{
  "slug": "posix-madv-dontneed",
  "term": "POSIX_MADV_DONTNEED",
  "aliases": [
    "POSIX memory discard advice"
  ],
  "definition": "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.",
  "note": "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. [posix-advice]\n\nGlibc 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. [posix-advice-api] [glibc-advice]\n\nMeasured 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. [hesela-advice]\n\nError 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. [posix-advice-api]",
  "status": "shipping",
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-10-20",
  "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."
  ],
  "related": [
    "madv-dontneed",
    "memory-mapped-file",
    "posix-fadv-dontneed",
    "page-cache"
  ],
  "citations": [
    {
      "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"
    }
  ]
}
