{
  "slug": "madv-dontneed",
  "term": "MADV_DONTNEED",
  "aliases": [
    "Linux MADV_DONTNEED"
  ],
  "definition": "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.",
  "note": "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. [madvise-api]\n\nFile-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. [hesela-advice]\n\nSimilar 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. [posix-advice] [glibc-advice]\n\nCache 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. [madvise-api] [posix-advice-api]",
  "status": "shipping",
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-10-20",
  "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."
  ],
  "related": [
    "memory-mapped-file",
    "copy-on-write",
    "page-cache",
    "msync",
    "posix-madv-dontneed",
    "posix-fadv-dontneed"
  ],
  "citations": [
    {
      "id": "madvise-api",
      "title": "Linux man-pages: madvise(2), MADV_DONTNEED semantics",
      "url": "https://man7.org/linux/man-pages/man2/madvise.2.html",
      "accessed": "2026-10-20"
    },
    {
      "id": "posix-advice",
      "title": "POSIX.1-2017: posix_madvise(), advice preserves memory-access semantics",
      "url": "https://man7.org/linux/man-pages/man3/posix_madvise.3p.html",
      "accessed": "2026-10-20"
    },
    {
      "id": "glibc-advice",
      "title": "glibc 2.39: Linux posix_madvise implementation",
      "url": "https://github.com/bminor/glibc/blob/glibc-2.39/sysdeps/unix/sysv/linux/posix_madvise.c",
      "accessed": "2026-10-20"
    },
    {
      "id": "posix-advice-api",
      "title": "Linux man-pages: posix_madvise(3), glibc behavior and error convention",
      "url": "https://man7.org/linux/man-pages/man3/posix_madvise.3.html",
      "accessed": "2026-10-20"
    },
    {
      "id": "hesela-advice",
      "title": "Hesela: When don't need discards private edits",
      "url": "https://hesela.com/analyses/mmap-visibility-size-durability/#discard-advice",
      "accessed": "2026-10-20"
    }
  ]
}
