Re: [PATCH v4 06/17] mm/mglru: move add/del LRU size accounting out of lru_gen_update_size()
From: Barry Song
Date: Sun Nov 08 2026 - 15:52:38 EST
On Fri, Oct 16, 2026 at 2:15 AM Kairui Song via B4 Relay
<devnull+kasong.tencent.com@xxxxxxxxxx> wrote:
>
> From: Kairui Song <kasong@xxxxxxxxxxx>
>
> Pure code shuffle, no behavior change. lru_gen_update_size() now only
> updates the per-generation counters plus the promotion move; the
> addition and deletion active/inactive accounting move to
> lru_gen_add_folio() and lru_gen_del_folio(), which know the generation
> and can apply the active-window test directly.
>
> The unevictable case is untouched: unevictable folios never enter
> lru_gen_add_folio() and keep being accounted by lruvec_add_folio() as
> before.
>
> Tested-by: zhaozhengzhuo <zhaozhengzhuo@xxxxxxxxxxxxx>
> Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
> ---
The patch looks good to me.
Meanwhile, I've been struggling with the names of
__update_lru_size() and lru_gen_update_size() for a long
time.
Given that lru_gen_update_size() now only updates
nr_pages:
static inline void lru_gen_update_size(struct lruvec *lruvec, int type,
struct folio *folio, int old_gen, int new_gen)
{
...
if (old_gen >= 0)
atomic_long_sub(delta, &lrugen->nr_pages[old_gen][type][zone]);
if (new_gen >= 0)
atomic_long_add(delta, &lrugen->nr_pages[new_gen][type][zone]);
}
while __update_lru_size() only handles
active/inactive accounting, could we rename them to make
their roles clearer? For example:
lru_gen_update_nr_pages()
lru_gen_update_active_inactive_size()
The names are longer, but the lru_gen_ prefix helps
distinguish this accounting from the actual
active/inactive LRU lists.
> include/linux/mm_inline.h | 28 ++++++++++++++--------------
> 1 file changed, 14 insertions(+), 14 deletions(-)
>
> diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h
> index cfcbe4a9aa85..65415eeac802 100644
> --- a/include/linux/mm_inline.h
> +++ b/include/linux/mm_inline.h
> @@ -313,21 +313,9 @@ static inline void lru_gen_update_size(struct lruvec *lruvec, struct folio *foli
> if (new_gen >= 0)
> atomic_long_add(delta, &lrugen->nr_pages[new_gen][type][zone]);
>
> - /* addition */
> - if (old_gen < 0) {
> - if (lru_gen_is_active(lruvec, new_gen))
> - lru += LRU_ACTIVE;
> - __update_lru_size(lruvec, lru, zone, delta);
> + /* return now if not a promotion */
> + if (old_gen < 0 || new_gen < 0)
> return;
> - }
> -
> - /* deletion */
> - if (new_gen < 0) {
> - if (lru_gen_is_active(lruvec, old_gen))
> - lru += LRU_ACTIVE;
> - __update_lru_size(lruvec, lru, zone, -delta);
> - return;
> - }
>
> /* promotion */
> if (!lru_gen_is_active(lruvec, old_gen) && lru_gen_is_active(lruvec, new_gen)) {
> @@ -381,6 +369,8 @@ static inline bool lru_gen_add_folio(struct lruvec *lruvec, struct folio *folio,
> int gen = folio_lru_gen(folio);
> int type = folio_is_file_lru(folio);
> int zone = folio_zonenum(folio);
> + int delta = folio_nr_pages(folio);
> + enum lru_list lru = type * LRU_INACTIVE_FILE;
> struct lru_gen_folio *lrugen = &lruvec->lrugen;
>
> BUILD_BUG_ON(BIT(LRU_GEN_WIDTH - 1) != MAX_NR_GENS);
> @@ -396,6 +386,10 @@ static inline bool lru_gen_add_folio(struct lruvec *lruvec, struct folio *folio,
> set_mask_bits(folio_flags(folio, 0), LRU_GEN_MASK | BIT(PG_active), flags);
>
> lru_gen_update_size(lruvec, folio, -1, gen);
> + if (lru_gen_is_active(lruvec, gen))
> + lru += LRU_ACTIVE;
> + __update_lru_size(lruvec, lru, zone, delta);
> +
> /* for folio_rotate_reclaimable() */
> if (reclaiming)
> list_add_tail(&folio->lru, &lrugen->folios[gen][type][zone]);
> @@ -409,6 +403,9 @@ static inline bool lru_gen_del_folio(struct lruvec *lruvec, struct folio *folio,
> {
> unsigned long flags;
> int gen = folio_lru_gen(folio);
> + int zone = folio_zonenum(folio);
> + int delta = folio_nr_pages(folio);
> + enum lru_list lru = folio_is_file_lru(folio) * LRU_INACTIVE_FILE;
>
> if (gen < 0)
> return false;
> @@ -422,6 +419,9 @@ static inline bool lru_gen_del_folio(struct lruvec *lruvec, struct folio *folio,
> gen = ((flags & LRU_GEN_MASK) >> LRU_GEN_PGOFF) - 1;
>
> lru_gen_update_size(lruvec, folio, gen, -1);
> + if (lru_gen_is_active(lruvec, gen))
> + lru += LRU_ACTIVE;
> + __update_lru_size(lruvec, lru, zone, -delta);
> list_del(&folio->lru);
>
> return true;
>
> --
> 2.56.0
>
>
Thanks,
Barry