fcntl(2) F_READAHEAD set to zero doesn't work [patch]
Ian Lepore
ian at FreeBSD.org
Fri Feb 8 23:58:23 UTC 2013
I discovered today that fcntl(fd, F_READAHEAD, 0) doesn't work as
advertised. It's supposed to disable readahead, but instead it restores
the default readahead behavior (if it had previously been changed), and
there is no way to disable readahead.[1] I think the attached patch
fixes it, but it's not immediately clear from the patch why; here's the
deal...
The amount of readahead is calculated by sequential_heuristic() in
vfs_vnops.c. If the FRDAHEAD flag is set on the file it uses the value
stored in the file's f_seqcount, otherwise it calculates a value (and
updates f_seqcount, which doesn't ever happen when FRDAHEAD is set).
So the patch causes the FRDAHEAD flag to be set even in the case of the
readahead amount being zero. Because it seems like a useful concept, it
still allows the readahead to be restored to default behavior, now by
passing a negative value.
Does this look right to those of you who understand this part of the
system better than I do?
-- Ian
[1] No way using F_READAHEAD; I know about POSIX_FADV_RANDOM.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fcntl_readahead.diff
Type: text/x-patch
Size: 1003 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20130208/baf64ea8/attachment.bin>
More information about the freebsd-hackers
mailing list