On Wed, Sep 09, 2026 at 03:59:37PM +0800, Baolin Wang wrote: > > > 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,
They are the same for the PMD contexts, but not for mthp_khugepaged: mthp_khugepaged_collapse() passes len = hpage_pmd_size, the range scanned, while nr_hpages is the number of folios asked for. collapse_single_mthp() asks for one order-N folio in a whole PMD. That matters on arm64 with 64K pages, where the PMD is 512M: with len the single-mTHP case would wait up to 7 seconds for one folio, with nr_hpages * hpage_size it gets the 3 second floor. The budget should follow what gets built, not what gets scanned, so I would keep it. Does the Reviewed-by stand with that? -- Kiryl Shutsemau / Kirill A. Shutemov

