Re: [PATCH] mm/madvise: add cond_resched() in THP branch of madvise_cold_or_pageout_pte_range()

From: Andrew Morton

Date: Sat Oct 10 2026 - 16:51:24 EST


On Sat, 10 Oct 2026 10:26:33 -0400 Gregory Price <gourry@xxxxxxxxxx> wrote:

> > 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/

I'm thinking

Fixes: 9c276cc65a58 ("mm: introduce MADV_COLD")

Sep 25 2019. So 5.x and 6.x kernels want this. Current kernels
actually don't need this because PREEMPT_NONE has virtually
disappeared. But 99%(?) of machines run 5.x and 6.x.

I'll go with Wei's simple one-liner for backportability & safety.
Let's look at broader changes in future -rc cycles.