The Linux-specific MADV_POPULATE_READ is much more reliable than MADV_WILLNEED if you want to implement read-ahead for a memory-mapped file.
In my opinion, the POSIX advices specified for madvise are useless or even dangerous.
On Linux, for precise control of memory-mapped files one should use only these 4 Linux-specific advices: MADV_COLD, MADV_PAGEOUT, MADV_POPULATE_READ & MADV_POPULATE_WRITE.
These should be used within io_uring, so that they will be executed asynchronously.
These have a well-documented meaning and using them carefully should be sufficient to reach optimum performance with mmap.
The Linux-specific MADV_POPULATE_READ is much more reliable than MADV_WILLNEED if you want to implement read-ahead for a memory-mapped file.
In my opinion, the POSIX advices specified for madvise are useless or even dangerous.
On Linux, for precise control of memory-mapped files one should use only these 4 Linux-specific advices: MADV_COLD, MADV_PAGEOUT, MADV_POPULATE_READ & MADV_POPULATE_WRITE.
These should be used within io_uring, so that they will be executed asynchronously.
These have a well-documented meaning and using them carefully should be sufficient to reach optimum performance with mmap.
Though at that point you can just use FADV_WILLNEED.
I'm just steelmanning here ¯\_(ツ)_/¯