[PATCH 08/16] selftests/mm: skip collapse_compound_extreme where the PMD is too large

From: Kiryl Shutsemau

Date: Sun Aug 02 2026 - 16:00:34 EST


From: "Kiryl Shutsemau (Meta)" <kas@xxxxxxxxxx>

Its fault-time THP construction (x hpage_pmd_nr) cannot hand out a
512M order-13 page on arm64/64K, bailing the whole binary. Skip when
hpage_pmd_size > 32M; MADV_COLLAPSE-driven cases still exercise PMD-order
collapse there. No effect on 4K (2M) or 16K (32M) PMDs.

Assisted-by: Claude-Code:claude-opus-5
Signed-off-by: Kiryl Shutsemau (Meta) <kas@xxxxxxxxxx>
---
tools/testing/selftests/mm/khugepaged.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c
index 81001e15765c..b43e060b4118 100644
--- a/tools/testing/selftests/mm/khugepaged.c
+++ b/tools/testing/selftests/mm/khugepaged.c
@@ -857,6 +857,21 @@ static void collapse_compound_extreme(struct collapse_context *c, struct mem_ops
void *p;
int i;

+ /*
+ * Builds a PMD's worth of distinct PTE-mapped compound pages by cycling
+ * hpage_pmd_nr fault-time THPs through mremap. Fault-time THP allocation
+ * is best-effort, and this needs hpage_pmd_nr PMD-order pages in a row:
+ * fine at a 2M (4K base) or 32M (16K base) PMD, but a 512M PMD (arm64/64K)
+ * is an order-13 allocation the allocator cannot reliably hand out even
+ * once, let alone 8192 times. Cap at a 32M PMD; MADV_COLLAPSE-driven cases
+ * still cover PMD-order collapse on the larger configs.
+ */
+ if (hpage_pmd_size > (32UL << 20)) {
+ ksft_test_result_skip("%s: PMD too large for fault-time THP construction\n",
+ __func__);
+ return;
+ }
+
p = ops->setup_area(1);
ksft_print_msg("Construct PTE page table full of different PTE-mapped compound pages\n");
for (i = 0; i < hpage_pmd_nr; i++) {
--
2.54.0