Linux performs readaheads (specified in /sys/block//queue/read_ahead_kb) when a file is read sequentially.

Interested OS : Red Hat Linux Interested File System : xfs, ext4

What is the criteria for deciding a sequential read is done ? Consider multiple concurrent reads done on same file using pread (https://man7.org/linux/man-pages/man2/pwrite.2.html) with same or different FDs.


Same FD. reads at positions 10-20-30-78-89(out of seq reads) -40-50-60-70 - 23-34 (out of seq reads)- 80-90-100...

Could above subtle out-of-sequence reads avoid readaheads in this case ?

If so, would using two different FDs solve this issue (i.e. a separate FD used for reads at 78-89-23-34) ? (i.e. readaheads will happen as usual for 10-20-30-40-50 read)

1 Answer 1


Can above subtle out of sequence reads could avoid readaheads in this case?

Yes, out-of-sequence reads from the same file descriptor can affect readaheads, but the kernel tries to take this into account — at least for small “random” reads in parallel with sequential reads. See the description of the on-demand readahead design, in particular:

In interleaved sequential reads, concurrent streams on the same fd can be invalidating each other's readahead state. So we flag the new readahead page at (start+size-async_size) with PG_readahead, and use it as readahead indicator. The flag won't be set on already cached pages, to avoid the readahead-for-nothing fuss, saving pointless page cache lookups.

You can see where this fits in by looking at ondemand_readahead, in particular its call to try_context_readahead and the surrounding comments.

As always when trying to remove performance bottlenecks, you shouldn’t take potential bottlenecks into account except as hints: you should devise your own benchmarks and analyse the performance characteristics of your specific scenarios. It could be the case, for example, that your out-of-sequence reads only hit pages which are already in the page cache as a result of readahead on your sequential reads.

  • thx for the information, will using a different FD solve this issue ?
    – aKumara
    Commented May 31, 2021 at 16:18
  • 2
    First you need to determine whether you actually have an issue; have you done so already? Commented May 31, 2021 at 17:11
  • kindly pls note that this question was asked during design stage. With a theoretical background (+ any experience shared by other devs who dealt with similar cases) I can design my software to work optimally (i.e. in this case best read rate).
    – aKumara
    Commented Jun 1, 2021 at 5:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .