[PATCH v5 19/19] selftests/mm: zap whole PTE tables in the khugepaged race harness
From: Kiryl Shutsemau
Date: Tue Sep 08 2026 - 09:04:28 EST
From: "Kiryl Shutsemau (Meta)" <kas@xxxxxxxxxx>
The harness's MADV_DONTNEED thread zaps 1 to 32 pages at a time, never a
whole PMD-aligned area, and only a zap that covers a full table frees the
table itself (CONFIG_PT_RECLAIM).
Make the thread zap a whole PMD-aligned area about one iteration in 64,
and keep the fine-grained zaps as the common case. The new case frees
page tables, racing that against a collapse walking the same table.
Assisted-by: LLM
Tested-by: Muhammad Usama Anjum <usama.anjum@xxxxxxx>
Signed-off-by: Kiryl Shutsemau (Meta) <kas@xxxxxxxxxx>
---
tools/testing/selftests/mm/khugepaged_race.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/mm/khugepaged_race.c b/tools/testing/selftests/mm/khugepaged_race.c
index 1f4aa23834db..c3478b5123e2 100644
--- a/tools/testing/selftests/mm/khugepaged_race.c
+++ b/tools/testing/selftests/mm/khugepaged_race.c
@@ -118,8 +118,21 @@ static void *dontneed_fn(void *arg)
unsigned long page_idx = rand_page(&seed);
unsigned long nr = 1UL << (rand_r(&seed) % 6); /* 1..32 pages */
- madvise(region + page_idx * page_size,
- room_from(page_idx, nr) * page_size, MADV_DONTNEED);
+ /*
+ * Now and then zap a whole PMD-aligned area: only a zap that
+ * covers the full table frees the table itself (CONFIG_PT_RECLAIM).
+ */
+ if (!(rand_r(&seed) % 64)) {
+ unsigned long area = page_idx /
+ (hpage_pmd_size / page_size);
+
+ madvise(region + area * hpage_pmd_size,
+ hpage_pmd_size, MADV_DONTNEED);
+ } else {
+ madvise(region + page_idx * page_size,
+ room_from(page_idx, nr) * page_size,
+ MADV_DONTNEED);
+ }
usleep(rand_r(&seed) % 500);
}
return NULL;
--
2.54.0