Re: [PATCH 00/16] selftests/mm: improve khugepaged coverage

From: Mike Rapoport

Date: Mon Aug 03 2026 - 07:07:30 EST


> From: "Kiryl Shutsemau (Meta)" <kas@xxxxxxxxxx>
>
> 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.

My overall feeling is that changelogs need more human touch to be
parseable.

> - vm_util grows folio-order helpers: is_backed_by_folio() moves out of
> split_huge_page_test.c, and a range-level form asks whether every
> order-aligned window of a range is backed by one folio of exactly that
> order, mapped head to tail.
>
> - folio_order_check validates those helpers against the kernel for every
> anon THP order it supports, before any collapse test trusts them.
>
> - khugepaged_full_pass() drives exactly one scan pass through the sysfs
> wake path, so a barrier completes on the daemon's own cadence instead of
> needing a short scan_sleep_millisecs.
>
> - khugepaged -o <order> runs order-parameterized anon collapse cases: a
> full table, only the populated window, default max_ptes_none and
> max_ptes_none=0, and collapse upward from smaller large folios. Any
> order up to the PMD order, where the same cases baseline the PMD path.
>
> - khugepaged_race races two faulters, MADV_DONTNEED, transient FOLL_PIN,
> fork and mremap against one of three collapse drivers: khugepaged a pass
> at a time, khugepaged free-running, or a MADV_COLLAPSE loop. Every
> racing page must read as its pattern or as zero. -z collapses
> hole-bearing windows; -p adds pageout and compaction, the only threads
> that elevate a source folio's refcount from the reclaim side. DEBUG_VM,
> page_table_check, KASAN and lockdep are the other half of the oracle.
>
> - A shared-source write race pins the CoW isolation contract: a co-sharer
> writing throughout a collapse must not see the collapsing side's pages.
>
> - Four tests fail on the environment rather than on the kernel: the
> collapse wait is a fixed three seconds whatever a huge page costs to
> build, collapse_compound_extreme wants a 512M page from the fault path,
> the shmem cases want a PMD-order page cache folio the page cache caps
> below, and the swap cases fail instead of skipping without swap. Scale
> the wait (a 2M PMD is unchanged) and skip the other three. This is why
> the suite now runs on arm64 with 64K pages.
>
> Tested on mm-new (1dbd7c34bb92):
>
> x86-64 4K 105 pass, 3 skip, 0 fail
> arm64 64K 87 pass, 7 skip, 0 fail
>
> The skips are structural: sub-PMD cases decline at the PMD order and the
> mixed-source case at the smallest order, and on 64K pages
> collapse_compound_extreme and the shmem cases skip for the reasons above.
>
> Kiryl Shutsemau (Meta) (16):
> selftests/mm: move is_backed_by_folio() into vm_util
> selftests/mm: add folio-order check for VA ranges
> selftests/mm: add folio-order detection self-check
> selftests/mm: add order-parameterized khugepaged collapse cases
> selftests/mm: add khugepaged completion barrier helper
> selftests/mm: add khugepaged race harness
> selftests/mm: cover a shared-source collapse write race
> selftests/mm: skip collapse_compound_extreme where the PMD is too
> large
> selftests/mm: skip khugepaged swap tests when no swap is configured
> selftests/mm: verify synchronous khugepaged driving is attributable
> selftests/mm: race-harness variant for permissive hole occupancy
> selftests/mm: add memory-pressure threads to the khugepaged race
> harness
> selftests/mm: parameterize the mixed-source collapse case by source
> order
> selftests/mm: zap whole PTE tables in the khugepaged race harness
> selftests/mm: scale khugepaged's collapse wait with the PMD size
> selftests/mm: skip khugepaged shmem cases without a PMD page cache
> folio

I'd put the commits that update the existing tests at the top of the
series and than add the new tests and infrastrucure.

--
Sincerely yours,
Mike.