Re: [PATCH 2/3] mm/mglru: improve scan_folios() exhaustion detection
From: Barry Song
Date: Tue Aug 25 2026 - 17:45:47 EST
On Mon, Aug 24, 2026 at 2:48 PM Baolin Wang
<baolin.wang@xxxxxxxxxxxxxxxxx> wrote:
>
>
>
> On 8/20/26 12:56 PM, Barry Song (Xiaomi) wrote:
> > Commit 16b475d2ac3c ("mm/mglru: avoid reclaim type fall back when
> > isolation makes no progress") uses scanned == 0 to determine
> > whether scan_folios() has exhausted a reclaim type. However,
> > this is not always sufficient. It is possible for scanned > 0,
> > while the oldest reclaimable generation is exhausted after the
> > first scan_folios() call.
> >
> > We detect early_stop in scan_folios(). If we stop early for any reason,
> > it means the current reclaim type is not exhausted yet. If early_stop is
> > never reached, it means we have exhausted the current oldest generation
> > without hitting any scanning limit.
> >
> > Another issue is that if the lruvec has 4 generations, we might have
> > exhausted the oldest generation while the second oldest generation is
> > still reclaimable. In that case, this type is not exhausted yet.
> >
> > Add an exhausted output argument to scan_folios() so it can
> > explicitly report whether the reclaimable lists for the current
> > type have been exhausted.
> >
> > Signed-off-by: Barry Song (Xiaomi) <baohua@xxxxxxxxxx>
> > ---
>
> LGTM. One nit below.
> Reviewed-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>
>
Thanks for the review, Baolin.
[...]
> > + *exhausted = !early_stop &&
> > + lrugen->min_seq[type] + MIN_NR_GENS == lrugen->max_seq;
>
> Nit: using get_nr_gens() looks more readable to me:
>
> *exhausted = !early_stop && get_nr_gens(lruvec, type) == MIN_NR_GENS + 1;
Yes, it seems more readable.
Best Regards
Barry