Re: [PATCH v2] mm/mglru: Fix young counter undercount for large folios

Barry Song <[email protected]>
Newsgroups org.kvack.linux-mm,org.kernel.vger.linux-kernel
Message-ID <CAGsJ_4z3gfk9n35cPf3HhjKRrqJ52EHtZHb5eGzOVrxcHcOWKw@mail.gmail.com>
On Thu, Aug 13, 2026 at 2:10 PM Hui Zhu <[email protected]> wrote:
>
> From: Hui Zhu <[email protected]>
>
> lru_gen_look_around() feeds its local 'young' counter into
> suitable_to_scan(), which decides whether the current PMD is added to
> the bloom filter and checked again on the next aging round.
>
> The folio triggering the look-around is processed at function entry:
> test_and_clear_young_ptes_notify() clears the accessed bits of the nr
> PTEs it maps, and the function bails out if none of them is young.  The
> loop that follows therefore never recounts this folio, since its
> accessed bits are already cleared.  Every other young folio the loop
> finds is accounted as a batch (young += nr), where nr is the number of
> consecutive PTEs it maps.  The triggering folio, however, still
> contributes a fixed young = 1 regardless of its size -- a leftover from
> before PTE batching.  A large triggering folio is thus accounted
> inconsistently with the rest of the window.
>
> Initialize young to nr so the triggering folio is accounted the same way
> as any other young folio batch in the loop.
>
> Note this is a deliberate overestimate, not a measured value.  The
> test-and-clear helper only reports whether any of the nr PTEs is young,
> not how many were accessed, so the true number of accessed PTEs in a
> large folio is unknown and can be smaller than nr.  Counting the full
> batch is intentional: the mm core tracks accessed/dirty state per folio,
> not per page, so a per-page count is neither obtainable nor meaningful.
> The only consumer is suitable_to_scan(), and the bloom filter it feeds
> tolerates error.  Overestimating is also the safe direction: at worst a
> PMD that saw little access is rescanned, whereas underestimating could
> skip rescanning a PMD whose folios are still hot and reclaim them
> incorrectly.  (nr here is the PTE batch size, not necessarily
> folio_nr_pages().)
>
> Fixes: 56e5b60b2114 ("mm: support batched checking of the young flag for MGLRU")
> Signed-off-by: Hui Zhu <[email protected]>
> Reviewed-by: Baolin Wang <[email protected]>

LGTM, thanks!

Reviewed-by: Barry Song <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.