{
  "slug": "madv-free",
  "term": "MADV_FREE",
  "aliases": [
    "Linux MADV_FREE"
  ],
  "definition": "MADV_FREE is a Linux memory-advice operation that makes private anonymous pages eligible for discard while allowing their contents to remain until reclamation.",
  "note": "Deferred discard: old contents can remain readable after success, but the application cannot rely on their retention. After reclamation, access obtains zero-filled memory; a write after advice but before reclamation cancels the pending discard for that page. This does not evict a file-backed cache range. [madvise-api]\n\nReclamation path: Linux v6.14 distinguishes lazy-free anonymous folios from ordinary swap-backed reclaim. Eligible contents can be discarded instead of preserved in swap. This is a source-level explanation, not a measurement of reclaim latency, memory savings or device I/O. [linux-vmscan-v614]\n\nChoice of operation: MADV_DONTNEED discards private anonymous contents without waiting for this deferred-reclaim opportunity. Neither operation is a secure-erasure procedure. Use MADV_FREE only after relinquishing the old data; it is not a durability operation for a mapped file. [madvise-api] [hesela-advice-scope]\n\nFailure scope: an unmapped gap can produce ENOMEM even when mapped parts were processed. An error is not an unchanged-data guarantee. The v6.14 walker retains earlier effects if a later mapping fails. [linux-madvise-v614]",
  "status": "shipping",
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-11-09",
  "advantages": [
    {
      "text": "Allows disposable anonymous allocations to become reclaimable while retaining their virtual address range.",
      "citationIds": [
        "madvise-api"
      ]
    }
  ],
  "limitations": [
    {
      "text": "Only private anonymous mappings are eligible; success does not establish immediate reclamation.",
      "citationIds": [
        "madvise-api"
      ]
    }
  ],
  "related": [
    "madv-dontneed",
    "madv-remove",
    "memory-mapped-file",
    "page-cache"
  ],
  "citations": [
    {
      "id": "madvise-api",
      "title": "Linux man-pages: madvise(2), memory-advice contracts",
      "url": "https://man7.org/linux/man-pages/man2/madvise.2.html",
      "accessed": "2026-11-09"
    },
    {
      "id": "linux-vmscan-v614",
      "title": "Linux v6.14: lazy-free folio reclamation",
      "url": "https://github.com/torvalds/linux/blob/v6.14/mm/vmscan.c",
      "accessed": "2026-11-09"
    },
    {
      "id": "hesela-advice-scope",
      "title": "Hesela: lazy discard is not backing-file removal",
      "url": "https://hesela.com/analyses/mmap-visibility-size-durability/#lazy-discard-backing-store",
      "accessed": "2026-11-09"
    },
    {
      "id": "linux-madvise-v614",
      "title": "Linux v6.14: madvise range walking and partial effects",
      "url": "https://github.com/torvalds/linux/blob/v6.14/mm/madvise.c",
      "accessed": "2026-11-09"
    }
  ]
}
