Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

From Linux kernel's doc the advice POSIX_FADV_RANDOM seems to disable readahead. But whent I disable Readhead using (sudo hdparm -A 0 /dev/sdb) I get huge degradation in performances; also noticed that read(2) seems to get split every 512k and acts as separate calls (Not sure about the reason, may be the max sector per request).

So which option really disables the read-ahead? Does POSIX_FADV_RANDOM also disable OS caching, or shall I add a POSIX_FADV_DONTNEED.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

POSIX_FADV_RANDOM disables read-ahead performed by the kernel's filesystem driver. It advises the filesystem layer not to read more than what was asked. The read-ahead is done at the file level: the filesystem layer may fetch extra data from the same file, but it won't do that (much) if you specify POSIX_FADV_RANDOM.

hdparm -A 0 disabled read-ahead performed by the disk itself. It advises the disk that when you read a sector, it shouldn't store the next few sectors in its internal cache.

Both disable read-ahead, but in a different layer of the system.

POSIX_FADV_RANDOM only disables prefetching. Set a region to POSIX_FADV_DONTNEED if you don't want it to be cached (or you want it to be removed from the cache).

share|improve this answer
Also, I am noticing that the system forgets an fadvise on the entire file (fd,0,0, POSIX_FADV_DONTNEED) that is done once after an open(2). It's seems that it has no effect when I have a loop of reads, each time I need to specify the data range I am reading and not want to cache. Is this true? –  Djellel Eddine Jul 18 '12 at 5:47
Thank you for the answer. So basically to completely disable the RA, one needs to do it on both levels (OS/Disk) –  Djellel Eddine Jul 18 '12 at 5:48
@DjellelEddine If you want to disable all readahead, you need to disable all readahead… That is supposed to hurt performance except in highly peculiar cases, so if you experience a slowdown, it means it's working. An fadvise with a length of 0 should happen to the whole file, yes. Note that it's only advice, I think the kernel will keep the data in cache anyway if it has nothing better to do with the memory. –  Gilles Jul 18 '12 at 7:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.