mm: introduce MADV_PAGEOUT

When a process expects no accesses to a certain memory range for a long
time, it could hint kernel that the pages can be reclaimed instantly but
data should be preserved for future use.  This could reduce workingset
eviction so it ends up increasing performance.

This patch introduces the new MADV_PAGEOUT hint to madvise(2) syscall. 
MADV_PAGEOUT can be used by a process to mark a memory range as not
expected to be used for a long time so that kernel reclaims *any LRU*
pages instantly.  The hint can help kernel in deciding which pages to
evict proactively.

A note: It doesn't apply SWAP_CLUSTER_MAX LRU page isolation limit
intentionally because it's automatically bounded by PMD size.  If PMD
size(e.g., 256) makes some trouble, we could fix it later by limit it to

- man-page material

MADV_PAGEOUT (since Linux x.x)

Do not expect access in the near future so pages in the specified
regions could be reclaimed instantly regardless of memory pressure.
Thus, access in the range after successful operation could cause
major page fault but never lose the up-to-date contents unlike
MADV_DONTNEED. Pages belonging to a shared mapping are only processed
if a write access is allowed for the calling process.

MADV_PAGEOUT cannot be applied to locked pages, Huge TLB pages, or
VM_PFNMAP pages.


Signed-off-by: Minchan Kim <>
Reported-by: kbuild test robot <>
Acked-by: Michal Hocko <>
Cc: James E.J. Bottomley <>
Cc: Richard Henderson <>
Cc: Ralf Baechle <>
Cc: Chris Zankel <>
Cc: Daniel Colascione <>
Cc: Dave Hansen <>
Cc: Hillf Danton <>
Cc: Joel Fernandes (Google) <>
Cc: Johannes Weiner <>
Cc: Kirill A. Shutemov <>
Cc: Oleksandr Natalenko <>
Cc: Shakeel Butt <>
Cc: Sonny Rao <>
Cc: Suren Baghdasaryan <>
Cc: Tim Murray <>
Signed-off-by: Andrew Morton <>
8 files changed