POSIX_FADV_WILLNEED
POSIX_FADV_WILLNEED is file-access advice announcing that an application expects to read a specified range soon.
The advice covers a region that starts at offset and extends for size bytes. A size of 0 means through the end of the file, although before Linux 2.6.6 it was taken literally as zero bytes. Linux uses this hint to initiate a nonblocking page-cache read, and memory pressure can reduce the amount fetched. The advice is nonbinding; a zero result is not a count of resident bytes. posix_fadvise returns an error number directly on failure. [1]
In Linux v6.17, generic_fadvise rounds the range out to include the first and last partial pages and passes that page count to force_page_cache_readahead. It accepts and ignores advice for DAX or a noop backing device, and returns ESPIPE for a FIFO. Filesystems may override the generic implementation. [2]
In Linux v6.14 the downstream force_page_cache_ra helper bounds explicit prefetch by max(io_pages, ra_pages); requesting through EOF does not promise that all those pages will be loaded. [4]
Relations
- related
- posix_fadvise, readahead (Linux syscall), RWF_NOWAIT, Page cache, Buffered I/O, POSIX_FADV_DONTNEED, Direct Access, Prefetch wastage, Prefetch trigger distance
Advantages
- The hint lets applications overlap useful work with data prefetch; successful submission is not a completion barrier. [1]
- Kernel support dates from Linux 2.5.60 and the glibc wrapper from glibc 2.2, so the interface is long established. [1]
Limitations
- Prefetch advice does not pin the requested data in memory or promise a faster subsequent read. [1]
- Since Linux 3.18 the underlying fadvise64 system call is optional, depending on CONFIG_ADVISE_SYSCALLS. [1]
Citations
- Linux man-pages 6.19: posix_fadvise(2), advice and return conventions
- Linux v6.17: generic_fadvise and filesystem-specific dispatch
- Linux v6.14 mm/readahead.c: file_ra_state_init, force_page_cache_ra and ractl_max_pages
Further reading
Sources & caveats
- fadvise-api is the Linux man-pages 6.19 posix_fadvise(2) page, re-read for the region semantics, the 2.6.6 zero-length fix, WILLNEED behavior and the version history.
- fadvise-617 is mm/fadvise.c at v6.17, re-read on git.kernel.org at the same tag for page rounding, the DAX and noop-device branch and the FIFO check.
- hesela-probe is a three-call invalid-descriptor probe of posix_fadvise, readahead and preadv2 error channels. It is not a prefetch or filesystem-support benchmark.
- The posix-fadv-dontneed entry links here because it is the opposite advice on the same interface.
- 2026-11-08: reviewed the downstream v6.14 prefetch bound; softened an unconditional nonblocking/fetched-range advantage. No measured speedup.