posix-madv-dontneed · shipping · also POSIX memory discard advice

POSIX_MADV_DONTNEED

POSIX_MADV_DONTNEED is a posix_madvise advice value expressing that a mapped memory range is not expected to be accessed soon, without changing the semantics of access to that memory.

Advice contract: the implementation may ignore POSIX memory-access advice, but the call must not change access semantics. The range is a virtual-memory address and length, not a file descriptor and offset. [1]

Glibc behavior: the Linux implementation has treated this value as a no-op since glibc 2.6 because native MADV_DONTNEED can discard contents. The pinned glibc 2.39 source returns zero for this advice rather than forwarding it to madvise. [3] [2]

Measured comparison: Hesela's six-case probe retained P throughout private file and private anonymous pages after the POSIX call. Native discard restored file bytes in the first mapping type and produced zeros in the second. All advice calls returned zero, so success alone did not identify their data effects. [4]

Error handling: posix_madvise returns zero on success and a positive error number on failure; do not inspect errno as though it were madvise. A successful no-op does not establish cache eviction, page residency, persistence or secure erasure. [3]

Relations

related
MADV_DONTNEED, Memory-mapped file, POSIX_FADV_DONTNEED, Page cache

Advantages

  • Communicates expected mapped-memory use without a destructive discard contract.

Limitations

  • The implementation may ignore the advice; glibc's no-op does not promise memory reclamation.

Citations

  1. POSIX.1-2017: posix_madvise(), advice preserves memory-access semantics (accessed 2026-10-20)
  2. glibc 2.39: Linux posix_madvise implementation (accessed 2026-10-20)
  3. Linux man-pages: posix_madvise(3), glibc behavior and error convention (accessed 2026-10-20)
  4. Hesela: When don't need discards private edits (accessed 2026-10-20)

JSON: /data/terms/posix-madv-dontneed.json

Published by Hesela team · Updated

Report a correction · Editorial standards · Reuse guidance

Cite this page
Hesela team. POSIX_MADV_DONTNEED. Hesela. 2026-10-20. https://hesela.dev/terms/posix-madv-dontneed/