All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 00/19] selftests/mm: improve khugepaged coverage
@ 2026-08-15  1:58 Kiryl Shutsemau
  2026-08-15  1:58 ` [PATCH v4 01/19] selftests/mm: raise the khugepaged test-case cap Kiryl Shutsemau
                   ` (18 more replies)
  0 siblings, 19 replies; 32+ messages in thread
From: Kiryl Shutsemau @ 2026-08-15  1:58 UTC (permalink / raw)
  To: akpm, david, ljs, nico.pache
  Cc: baolin.wang, baohua, dev.jain, hughd, lance.yang, liam, mhocko,
	rppt, ryan.roberts, shuah, surenb, usama.arif, vbabka, ziy,
	usama.anjum, agordeev, linux-mm, linux-kselftest, linux-kernel,
	kas

From: "Kiryl Shutsemau (Meta)" <kas@kernel.org>

mTHP collapse went in for 7.2 with no functional selftest coverage. Every
khugepaged collapse case is PMD-shaped, down to the detection: it reads
smaps AnonHugePages, which cannot see anything below the PMD order.

I am also reworking khugepaged's collapse mechanism, and that wants a suite
worth trusting before the mechanism changes underneath it. Nothing here
depends on the rework: everything passes on an unmodified kernel and
documents what khugepaged already does.

The table of cases is raised to 256 entries first. It holds 64, and a full
invocation -- every context crossed with every memory type, which needs a
directory for the file and shmem ones -- already registers 63, so the next
case added anywhere aborts the whole suite before a single test runs.

Five existing cases fail on the environment rather than on the kernel:

 - The collapse wait is a fixed three seconds, whatever a huge page costs
   to build. Scale it with the PMD size.

 - collapse_compound_extreme() wants a 512M folio from the fault path. Skip
   it where the PMD is that large.

 - The page cache caps folio order below the PMD order where a PMD is 512M,
   so nothing can hold a PMD-sized page cache folio. Skip the shmem and
   file cases there.

 - The swap cases ask a best-effort MADV_PAGEOUT for an exact swap count,
   and khugepaged reads the pages back in while they ask. Retry, hold the
   range out of the daemon's reach while retrying, and skip if the pages
   still will not go.

 - The MADV_COLLAPSE cases leave khugepaged running beside them, so a case
   can pass on the daemon's work rather than on its own.

This is why the suite now runs on arm64 with 64K pages.

Then the new coverage:

 - Folio-order helpers in vm_util, and folio_order_check to validate them
   against the kernel before any collapse test trusts them.

 - Four order-parameterized anon collapse cases, plus mixed sources by
   source order, at every supported order by default.

 - A shared-source write race: a co-sharer writing throughout a collapse
   and the collapsing side must not see each other's pages.

 - khugepaged_full_pass(), which steps the daemon one scan at a time
   through the sysfs wake path, and khugepaged_sync_check to hold it to
   exactly one attributed collapse per step.

 - khugepaged_race, racing faults, MADV_DONTNEED, pins, fork, mremap,
   reclaim and compaction against collapse, at both ends of the occupancy
   scale and over whole-table zaps, checked by content and by KASAN and
   lockdep.

Changes since v3:

 - New patch 6 stops khugepaged during the MADV_COLLAPSE cases: the
   per-order controls have to be cleared too, not only the global ones.

 - The shared-source write race did not race. The two sides now hand off,
   and the co-sharer unshares one page at a time (Sashiko).

 - khugepaged_sync_check no longer counts a tracepoint only the collapse
   rework emits.

 - khugepaged_race loses -z and -p: both occupancy limits and both
   pressure states always run.

 - -c refused the PMD order it advertised.

 - Smaller: two unchecked madvise() calls, and thread mask bits that had
   to be renumbered by hand.

 - The changelogs are rewritten throughout (Mike Rapoport).

Tested on an unmodified mm-new (33f61b12d297), with KASAN, lockdep,
DEBUG_VM and page_table_check, in 16G guests:

  x86-64 4K     181 pass, 1 skip, 0 fail
  arm64 64K     215 pass, 5 skip, 0 fail

The skips are structural: mixed sources declines at the smallest order, and
at 64K collapse_compound_extreme() skips as above. arm64 runs fewer cases
than x86-64 rather than skipping them: with no PMD-order page cache folio
the file and shmem contexts are never registered there.

Kiryl Shutsemau (Meta) (19):
  selftests/mm: raise the khugepaged test-case cap
  selftests/mm: skip collapse_compound_extreme() where the PMD is too
    large
  selftests/mm: scale khugepaged's collapse wait with the PMD size
  selftests/mm: skip khugepaged page cache cases without a PMD folio
  selftests/mm: make the swap cases' swapout reliable
  selftests/mm: stop khugepaged during the MADV_COLLAPSE cases
  selftests/mm: move is_backed_by_folio() into vm_util
  selftests/mm: add folio-order check for address ranges
  selftests/mm: add folio-order detection self-check
  selftests/mm: add khugepaged completion barrier helper
  selftests/mm: add order-parameterized khugepaged collapse cases
  selftests/mm: parameterize the mixed-source collapse case by source
    order
  selftests/mm: cover a shared-source collapse write race
  selftests/mm: run every supported collapse order by default
  selftests/mm: check that one khugepaged pass collapses one window
  selftests/mm: add khugepaged race harness
  selftests/mm: race collapse of windows with holes
  selftests/mm: add memory-pressure threads to the khugepaged race
    harness
  selftests/mm: zap whole PTE tables in the khugepaged race harness

 tools/testing/selftests/mm/Makefile           |   3 +
 .../testing/selftests/mm/folio_order_check.c  | 137 ++++
 tools/testing/selftests/mm/hmm-tests.c        |   1 -
 .../testing/selftests/mm/hugepage_settings.c  |  74 ++-
 .../testing/selftests/mm/hugepage_settings.h  |   3 +
 tools/testing/selftests/mm/khugepaged.c       | 524 +++++++++++++++-
 tools/testing/selftests/mm/khugepaged_race.c  | 589 ++++++++++++++++++
 .../selftests/mm/khugepaged_sync_check.c      | 196 ++++++
 tools/testing/selftests/mm/migration.c        |   1 -
 tools/testing/selftests/mm/run_vmtests.sh     |   8 +-
 .../selftests/mm/split_huge_page_test.c       |  62 --
 tools/testing/selftests/mm/vm_util.c          | 145 +++++
 tools/testing/selftests/mm/vm_util.h          |  10 +
 13 files changed, 1651 insertions(+), 102 deletions(-)
 create mode 100644 tools/testing/selftests/mm/folio_order_check.c
 create mode 100644 tools/testing/selftests/mm/khugepaged_race.c
 create mode 100644 tools/testing/selftests/mm/khugepaged_sync_check.c


base-commit: 33f61b12d297562321533c048e034b1fb21c1cf3
-- 
2.54.0


^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2026-08-18 10:48 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-15  1:58 [PATCH v4 00/19] selftests/mm: improve khugepaged coverage Kiryl Shutsemau
2026-08-15  1:58 ` [PATCH v4 01/19] selftests/mm: raise the khugepaged test-case cap Kiryl Shutsemau
2026-08-18  9:11   ` Lorenzo Stoakes (ARM)
2026-08-15  1:58 ` [PATCH v4 02/19] selftests/mm: skip collapse_compound_extreme() where the PMD is too large Kiryl Shutsemau
2026-08-18  9:22   ` Lorenzo Stoakes (ARM)
2026-08-15  1:58 ` [PATCH v4 03/19] selftests/mm: scale khugepaged's collapse wait with the PMD size Kiryl Shutsemau
2026-08-18 10:04   ` Lorenzo Stoakes (ARM)
2026-08-15  1:58 ` [PATCH v4 04/19] selftests/mm: skip khugepaged page cache cases without a PMD folio Kiryl Shutsemau
2026-08-18 10:07   ` Lorenzo Stoakes (ARM)
2026-08-15  1:58 ` [PATCH v4 05/19] selftests/mm: make the swap cases' swapout reliable Kiryl Shutsemau
2026-08-18 10:11   ` Lorenzo Stoakes (ARM)
2026-08-15  1:58 ` [PATCH v4 06/19] selftests/mm: stop khugepaged during the MADV_COLLAPSE cases Kiryl Shutsemau
2026-08-18 10:12   ` Lorenzo Stoakes (ARM)
2026-08-15  1:58 ` [PATCH v4 07/19] selftests/mm: move is_backed_by_folio() into vm_util Kiryl Shutsemau
2026-08-18 10:14   ` Lorenzo Stoakes (ARM)
2026-08-15  1:58 ` [PATCH v4 08/19] selftests/mm: add folio-order check for address ranges Kiryl Shutsemau
2026-08-18 10:25   ` Lorenzo Stoakes (ARM)
2026-08-15  1:58 ` [PATCH v4 09/19] selftests/mm: add folio-order detection self-check Kiryl Shutsemau
2026-08-18 10:30   ` Lorenzo Stoakes (ARM)
2026-08-15  1:58 ` [PATCH v4 10/19] selftests/mm: add khugepaged completion barrier helper Kiryl Shutsemau
2026-08-18 10:34   ` Lorenzo Stoakes (ARM)
2026-08-15  1:58 ` [PATCH v4 11/19] selftests/mm: add order-parameterized khugepaged collapse cases Kiryl Shutsemau
2026-08-18 10:38   ` Lorenzo Stoakes (ARM)
2026-08-15  1:58 ` [PATCH v4 12/19] selftests/mm: parameterize the mixed-source collapse case by source order Kiryl Shutsemau
2026-08-18 10:47   ` Lorenzo Stoakes (ARM)
2026-08-15  1:58 ` [PATCH v4 13/19] selftests/mm: cover a shared-source collapse write race Kiryl Shutsemau
2026-08-15  1:58 ` [PATCH v4 14/19] selftests/mm: run every supported collapse order by default Kiryl Shutsemau
2026-08-15  1:58 ` [PATCH v4 15/19] selftests/mm: check that one khugepaged pass collapses one window Kiryl Shutsemau
2026-08-15  1:58 ` [PATCH v4 16/19] selftests/mm: add khugepaged race harness Kiryl Shutsemau
2026-08-15  1:58 ` [PATCH v4 17/19] selftests/mm: race collapse of windows with holes Kiryl Shutsemau
2026-08-15  1:59 ` [PATCH v4 18/19] selftests/mm: add memory-pressure threads to the khugepaged race harness Kiryl Shutsemau
2026-08-15  1:59 ` [PATCH v4 19/19] selftests/mm: zap whole PTE tables in " Kiryl Shutsemau

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.