MADV_COLD and MADV_PAGEOUT share a page-table walker in mm/madvise.c
that handles ordinary PTEs, PTE-mapped large folios and huge PMDs.
Existing selftests cover little of its range, folio and permission
handling.
The walker has needed several fixes recently, and it's clear we need
to refactor this walker to make it maintainable. Ahead of that, lets
add some selftests to at least cover contractual behaviors.
This series adds tools/testing/selftests/mm/madvise.c to test only
behaviors userspace can rely on, so that it stays valid across changes
to the walker's implementation.
Each patch adds one group of tests, simplest first:
1. MADV_COLD skips PTE holes and swapped pages.
both hints reject locked VMAs
2. the same hole and swap checks for MADV_PAGEOUT
3. zero-length, unaligned and partly unmapped ranges
4. hugetlb VMAs are rejected
5. shared file, shared anonymous and SHM_LOCK'd memory is preserved
6. whole and partly advised THPs, including that MADV_PAGEOUT never
reclaims pages outside the advised range
7. the file permission rule in can_do_file_pageout()
8. the same rule for large file folios mapped by a PMD or by PTEs
Tests that need root, swap, THPs or hugetlb pages skip when those are
unavailable, and tests that need a page to be reclaimed skip when reclaim
does not happen. Where a skip would hide the bug a test looks for, it first
checks with a control page that reclaim works at all.
All 24 tests pass over three consecutive runs, with no skips and no
warnings in dmesg, as root in a virtme-ng guest with 4 CPUs, two NUMA
nodes, a 2G swap disk, 16 hugetlb pages, THP set to always,
CONFIG_DEBUG_VM and CONFIG_PROVE_LOCKING.
Run unprivileged on a host with swap, 18 pass and 6 skip:
- 5 need root
- 1 needs reserved hugetlb pages
original set:
https://lore.kernel.org/linux-mm/[email protected]/
Gregory Price (Meta) (8):
selftests/mm: add MADV_COLD and MADV_PAGEOUT contract tests
selftests/mm: check that MADV_PAGEOUT skips holes and swapped pages
selftests/mm: check MADV_COLD and MADV_PAGEOUT range handling
selftests/mm: check that MADV_COLD and MADV_PAGEOUT reject hugetlb
selftests/mm: check that MADV_COLD and MADV_PAGEOUT preserve shared
memory
selftests/mm: check MADV_COLD and MADV_PAGEOUT on partly advised THPs
selftests/mm: check MADV_PAGEOUT file permissions
selftests/mm: check that unauthorized MADV_PAGEOUT skips large file
folios
tools/testing/selftests/mm/Makefile | 2 +
tools/testing/selftests/mm/ksft_madvise.sh | 4 +
tools/testing/selftests/mm/madvise.c | 846 +++++++++++++++++++++
tools/testing/selftests/mm/run_vmtests.sh | 5 +
tools/testing/selftests/mm/vm_util.h | 1 +
5 files changed, 858 insertions(+)
create mode 100755 tools/testing/selftests/mm/ksft_madvise.sh
create mode 100644 tools/testing/selftests/mm/madvise.c
--
2.56.0