MADV_FREE
MADV_FREE is a Linux memory-advice operation that makes private anonymous pages eligible for discard while allowing their contents to remain until reclamation.
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. [1]
Reclamation 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. [2]
Choice 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. [1] [3]
Failure 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. [4]
Relations
- related
- MADV_DONTNEED, MADV_REMOVE, Memory-mapped file, Page cache
Advantages
- Allows disposable anonymous allocations to become reclaimable while retaining their virtual address range. [1]
Limitations
- Only private anonymous mappings are eligible; success does not establish immediate reclamation. [1]