Re: [PATCH v5 1/4] mm: list_lru: index per-memcg lists by memory CSS ID
From: Muchun Song
Date: Mon Nov 23 2026 - 07:23:01 EST
> On Nov 23, 2026, at 18:53, Qinyun Tan <qinyuntan@xxxxxxxxxxxxxxxxx> wrote:
>
> list_lru uses kmemcg_id, a copy of the private memcg ID, to index its
> per-memcg lists. kmemcg_id is only set when kmem accounting is enabled.
> Non-slab shrinkers need an index that also works with cgroup.memory=nokmem.
>
> Use memcg->css.id for non-root lists. The ID stays allocated until the
> CSS is freed, so disabling and re-enabling the memory controller on the
> same cgroup gives the new CSS a distinct index while the old CSS is
> still referenced. Reserve index zero for the root, which uses the
> per-node list directly.
>
> In list_lru_walk_node(), hold the RCU read lock across both lookups so
> the CSS ID cannot be reused between them. css_from_id() can see a CSS
> before its online callback succeeds, so check that the CSS is online
> before taking a reference. Drop the RCU read lock for the walk and
> keep the reference across restarts to recheck the same owner.
>
> Remove kmemcg_id and reparent the lists before the objcgs on memcg
> offline, including when kmem accounting is disabled.
>
> Signed-off-by: Qinyun Tan <qinyuntan@xxxxxxxxxxxxxxxxx>
Nice cleanup.
Acked-by: Muchun Song (ByteDance) <muchun.song@xxxxxxxxx>
Thanks.