Re: [PATCH] mm/madvise: add cond_resched() in THP branch of madvise_cold_or_pageout_pte_range()
From: Lorenzo Stoakes (ARM)
Date: Mon Oct 12 2026 - 09:00:38 EST
On Sat, Oct 10, 2026 at 10:26:33AM -0400, Gregory Price wrote:
> On Sat, Oct 10, 2026 at 10:40:42AM +0800, albin_yang@xxxxxxx wrote:
> > From: Wei Yang <albinwyang@xxxxxxxxxxx>
> >
> > Crash log:
> > watchdog: BUG: soft lockup - CPU#63 stuck for 23s! [stress-ng-vm:1665914]
> > ...
> > Call trace:
> > pmdp_invalidate+0x48/0x68
> > madvise_cold_or_pageout_pte_range+0x84c/0xb00
> > walk_pmd_range.isra.0+0x1ac/0x3b0
> > walk_pud_range+0x120/0x190
> > walk_pgd_range+0x170/0x1b8
> > __walk_page_range+0x184/0x198
> > walk_page_range_vma+0x94/0x128
> > madvise_cold+0xd8/0x198
> > madvise_vma_behavior+0x234/0x638
> > madvise_walk_vmas.constprop.0+0xdc/0x210
> > madvise_do_behavior+0xa8/0x328
> > do_madvise+0xd8/0x140
> > __arm64_sys_madvise+0x2c/0xe0
> >
> > Signed-off-by: Wei Yang <albinwyang@xxxxxxxxxxx>
> > ---
> > mm/madvise.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/mm/madvise.c b/mm/madvise.c
> > index eeee82cf2b3f..0755e6d99757 100644
> > --- a/mm/madvise.c
> > +++ b/mm/madvise.c
> > @@ -450,6 +450,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
> > spin_unlock(ptl);
> > if (pageout)
> > reclaim_pages(&folio_list);
> > + cond_resched();
> > return 0;
> > }
> >
>
> This same improvement came naturally from refactoring the entire
> function into a proper pagewalk structure:
>
> https://lore.kernel.org/linux-mm/20260922235830.2350770-10-gourry@xxxxxxxxxx/
>
> this function is really nasty.
Nice!
And thank you for looking at this horror show of a function.
But yeah as Andrew said, need something for the backport, then your work can
help eliminate the source of such things! :)
>
> ~Gregory
--
Cheers, Lorenzo