My program reads a file, interleaving it as below:

The file to be read is large. It is split into four parts that are then split into many blocks. My program first reads block 1 of part 1, then jumps to block 1 of part 2, and so on. Then back to the block 2 of part 1, …, as such.
The performance drops in tests. I believe the reason is that the page cache feature of kernel doesn’t work efficiently in such situations. But the file is too large to mmap(), and the file is located in NFS.
How do I speed up reading in such a situation? Any comments and suggestions are welcome.
You may want to use
posix_fadvise()to give the system hints on your usage, eg. usePOSIX_FADV_RANDOMto disable readahead, and possibly usePOSIX_FADV_WILLNEEDto have the system try to read the next block into the page cache before you need it (if you can predict this).You could also try to use
POSIX_FADV_DONTNEEDonce you are done reading a block to have the system free the underlying cache pages, although this might not be necessary