[PATCH v4 03/19] selftests/mm: scale khugepaged's collapse wait with the PMD size

From: Kiryl Shutsemau

Date: Fri Aug 14 2026 - 22:01:53 EST


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

wait_for_scan() gives every case the same three seconds, whatever the huge
page costs to build. collapse_full() asks for four of them: 8M at a 2M
PMD, but 2G at a 512M PMD -- arm64 with 64K base pages.

Three seconds is thin at that size rather than generous. Across 80 runs of
collapse_full() on arm64 with 64K pages the wait was half a second in 73 of
them, with a tail to two seconds. The case has also timed out in a full
matrix run, reporting a failure for a collapse that was still going.

Keep three seconds as the floor and add a second per 128M collapsed. A 2M
PMD is unchanged. A 512M PMD gets 19 seconds.

arm64/64K: khugepaged all:anon 21 pass/1 fail -> 22 pass/0 fail. x86-64 is
unchanged.

Assisted-by: Claude-Code:claude-opus-5
Reviewed-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
Tested-by: Muhammad Usama Anjum <usama.anjum@xxxxxxx>
Signed-off-by: Kiryl Shutsemau (Meta) <kas@xxxxxxxxxx>
---
tools/testing/selftests/mm/khugepaged.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c
index dd924edd8557..c499804a0ec4 100644
--- a/tools/testing/selftests/mm/khugepaged.c
+++ b/tools/testing/selftests/mm/khugepaged.c
@@ -561,8 +561,10 @@ static bool wait_for_scan(const char *msg, char *p, size_t len,
int nr_hpages, int collap_order, struct mem_ops *ops)
{
unsigned long hpage_size = page_size << collap_order;
+ /* Three seconds as a floor, plus a second per 128M to collapse */
+ const unsigned long bytes = (unsigned long)nr_hpages * hpage_size;
+ int timeout = 6 + 2 * (bytes / (128UL << 20));
int full_scans;
- int timeout = 6; /* 3 seconds */

/* Sanity check */
if (!ops->check_huge(p, len, 0, hpage_size))
--
2.54.0