On 9/8/26 8:50 PM, Kiryl Shutsemau wrote:
From: "Kiryl Shutsemau (Meta)" <[email protected]>
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, and the case has reported a failure for a collapse that
was still going.
The timeout is a ceiling on a poll loop, not a sleep: the loop stops as
soon as ops->check_huge() sees the collapse, or as soon as full_scans has
advanced by two. Raising it costs a passing case nothing. 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.
Keep three seconds as the floor and add a second per 128M collapsed. A 2M
PMD is unchanged, so x86-64 is too; a 512M PMD gets 19 seconds.
On arm64 with 64K pages a passing ./khugepaged all:anon takes 49 seconds
under TCG before and after this change.
Assisted-by: LLM
Acked-by: Lorenzo Stoakes (ARM) <[email protected]>
Reviewed-by: Mike Rapoport (Microsoft) <[email protected]>
Tested-by: Muhammad Usama Anjum <[email protected]>
Signed-off-by: Kiryl Shutsemau (Meta) <[email protected]>
---
tools/testing/selftests/mm/khugepaged.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/mm/khugepaged.c
b/tools/testing/selftests/mm/khugepaged.c
index 1ca7c6978571..48e0040d53b4 100644
--- a/tools/testing/selftests/mm/khugepaged.c
+++ b/tools/testing/selftests/mm/khugepaged.c
@@ -556,8 +556,11 @@ 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;
- int full_scans;
- int timeout = 6; /* 3 seconds */
+ unsigned long bytes = (unsigned long)nr_hpages * hpage_size;
We already pass in the 'len' parameter, and its size is also 'nr_hpages
* hpage_size", so you can drop the 'bytes' variable. With that,
Reviewed-by: Baolin Wang <[email protected]>
+ int timeout, full_scans;
+
+ /* Half-second ticks: three seconds floor, plus a second per 128M */
+ timeout = 6 + 2 * (bytes / (128UL << 20));
/* Sanity check */
if (!ops->check_huge(p, len, 0, hpage_size))