[PATCH v2 00/17] selftests/mm: improve khugepaged coverage

Kiryl Shutsemau <[email protected]>
Newsgroups gmane.linux.kernel,gmane.linux.kernel.mm
Message-ID <[email protected]>
From: "Kiryl Shutsemau (Meta)" <[email protected]>

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.

This version sits on top of Baolin's anon mTHP collapse selftests [1], now
in mm-new. His mthp_khugepaged context and per-order detection are what the
new cases need, so they go in there rather than bringing their own.

Four 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.
   Ask again before calling it a failure.

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 and mremap
   against collapse, checked by content and by KASAN and lockdep.

Tested on mm-new (8086604be973), with KASAN, lockdep, DEBUG_VM and
page_table_check, in 16G guests:

  x86-64 4K     190 pass, 1 skip, 0 fail
  arm64 64K     228 pass, 5 skip, 0 fail

The skips are structural: mixed sources declines at the smallest order, and
at 64K collapse_compound_extreme and the shmem components skip as above.

Changes since v1:

 - Rebased onto [1] (Baolin Wang), which this overlapped and which is in
   mm-new now, so this applies on top of it. This series' own -o mode is
   gone in favour of his context.
 - A plain ./khugepaged and ./khugepaged_race now run everything they can:
   every supported order, and every mode, occupancy and pressure axis.  The
   options only narrow that down (Mike Rapoport).
 - The fixes to existing cases come first, then the infrastructure and the
   new tests, each next to what it validates (Mike Rapoport).
 - The completion barrier helper comes before the tests that use it, so no
   case carries a throwaway implementation of it (Mike Rapoport).
 - Changelogs and comments rewritten to be read rather than parsed
   (Mike Rapoport).
 - One new patch: retry the swapout, which is what made
   collapse_max_ptes_swap flaky at 64K.
 - Dropped the swap-skip patch, an equivalent has landed
   (Alexander Gordeev).
 - Review fixes: masked failures, system state left behind on bail-out
   paths, arguments taken on trust (Sashiko).

[1] https://lore.kernel.org/all/[email protected]

Kiryl Shutsemau (Meta) (17):
  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: retry the swapout the khugepaged swap cases rely on
  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: verify synchronous khugepaged driving is attributable
  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  |  72 ++-
 .../testing/selftests/mm/hugepage_settings.h  |   3 +
 tools/testing/selftests/mm/khugepaged.c       | 466 +++++++++++++-
 tools/testing/selftests/mm/khugepaged_race.c  | 571 ++++++++++++++++++
 .../selftests/mm/khugepaged_sync_check.c      | 217 +++++++
 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 +
 12 files changed, 1599 insertions(+), 96 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: 8086604be9733378461a5534c39cb72635226b23
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.