madv-dontneed · shipping · also Linux MADV_DONTNEED

MADV_DONTNEED

MADV_DONTNEED is a Linux memory-advice operation that discards a mapped range's current private contents so later accesses can repopulate it from its backing object or zero-filled anonymous pages.

Destructive advice: unlike ordinary access-pattern hints, native MADV_DONTNEED changes memory-access semantics. A private anonymous range reads as zero on subsequent access; do not use it while that range holds the only copy of needed data. The address must be page-aligned. [1]

File-backed control: Hesela's sequential Linux 6.8/glibc 2.39 probe filled a private file mapping with P, then observed the original A bytes after native discard. The entire backing file stayed unchanged. Private MS_SYNC and no-operation controls retained P. This is measured API behavior on one host, not a durability or performance result. [5]

Similar names: POSIX_MADV_DONTNEED must preserve access semantics and is a no-op in the pinned glibc implementation. It is not an interchangeable replacement for native discard. POSIX_FADV_DONTNEED instead takes a file descriptor and file-offset range. [2] [3]

Cache scope: discarding a mapping does not guarantee immediate release of every shared backing page, a globally cold cache or secure erasure. The native call reports errors through -1 and errno, unlike posix_madvise's direct error-number return. [1] [4]

Relations

related
Memory-mapped file, Copy-on-write (storage), Page cache, msync, POSIX_MADV_DONTNEED, POSIX_FADV_DONTNEED

Advantages

  • Lets an application relinquish disposable private mapped contents without unmapping its address range.

Limitations

  • Can destroy private edits that have not been preserved elsewhere.
  • Interface and mapping mode matter; do not generalize Linux behavior to other operating systems.

Citations

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

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

Published by Hesela team · Updated

Report a correction · Editorial standards · Reuse guidance

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