mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gregory Price (Meta)" <gourry@gourry.net>
To: linux-kselftest@vger.kernel.org, linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com,
	akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org,
	liam@infradead.org, vbabka@kernel.org, rppt@kernel.org,
	surenb@google.com, mhocko@suse.com, shuah@kernel.org
Subject: [PATCH 0/8] selftests/mm: add MADV_COLD and MADV_PAGEOUT contract tests
Date: Wed, 14 Oct 2026 13:57:48 -0400	[thread overview]
Message-ID: <20261014175756.2035176-1-gourry@gourry.net> (raw)

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/20260922235830.2350770-2-gourry@gourry.net/

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


             reply	other threads:[~2026-10-14 17:58 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14 17:57 Gregory Price (Meta) [this message]
2026-10-14 17:57 ` [PATCH 1/8] " Gregory Price (Meta)
2026-10-19  4:59   ` Sarthak Sharma
2026-10-14 17:57 ` [PATCH 2/8] selftests/mm: check that MADV_PAGEOUT skips holes and swapped pages Gregory Price (Meta)
2026-10-19  5:00   ` Sarthak Sharma
2026-10-14 17:57 ` [PATCH 3/8] selftests/mm: check MADV_COLD and MADV_PAGEOUT range handling Gregory Price (Meta)
2026-10-14 21:31   ` [PATCH] fixup! " Gregory Price (Meta)
2026-10-16 12:17   ` [PATCH 3/8] " Sarthak Sharma
2026-10-16 13:22     ` Gregory Price
2026-10-16 14:07       ` Gregory Price
2026-10-19  4:48         ` Sarthak Sharma
2026-10-14 17:57 ` [PATCH 4/8] selftests/mm: check that MADV_COLD and MADV_PAGEOUT reject hugetlb Gregory Price (Meta)
2026-10-19  5:02   ` Sarthak Sharma
2026-10-14 17:57 ` [PATCH 5/8] selftests/mm: check that MADV_COLD and MADV_PAGEOUT preserve shared memory Gregory Price (Meta)
2026-10-19  5:13   ` Sarthak Sharma
2026-10-14 17:57 ` [PATCH 6/8] selftests/mm: check MADV_COLD and MADV_PAGEOUT on partly advised THPs Gregory Price (Meta)
2026-10-19  5:16   ` Sarthak Sharma
2026-10-14 17:57 ` [PATCH 7/8] selftests/mm: check MADV_PAGEOUT file permissions Gregory Price (Meta)
2026-10-16 12:18   ` Sarthak Sharma
2026-10-16 13:48     ` Gregory Price
2026-10-19  4:51       ` Sarthak Sharma
2026-10-14 17:57 ` [PATCH 8/8] selftests/mm: check that unauthorized MADV_PAGEOUT skips large file folios Gregory Price (Meta)
2026-10-14 21:26   ` Gregory Price
2026-10-19  5:19   ` Sarthak Sharma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261014175756.2035176-1-gourry@gourry.net \
    --to=gourry@gourry.net \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=rppt@kernel.org \
    --cc=shuah@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®