Re: [PATCH v4 30/31] mm: memcontrol: eliminate the problem of dying memory cgroup for LRU folios
From: Shakeel Butt
Date: Mon Feb 09 2026 - 12:57:14 EST
On Mon, Feb 09, 2026 at 11:49:43AM +0800, Qi Zheng wrote:
>
>
> On 2/8/26 6:25 AM, Shakeel Butt wrote:
> > On Thu, Feb 05, 2026 at 05:01:49PM +0800, Qi Zheng wrote:
> > > From: Muchun Song <songmuchun@xxxxxxxxxxxxx>
> > >
> > > Now that everything is set up, switch folio->memcg_data pointers to
> > > objcgs, update the accessors, and execute reparenting on cgroup death.
> > >
> > > Finally, folio->memcg_data of LRU folios and kmem folios will always
> > > point to an object cgroup pointer. The folio->memcg_data of slab
> > > folios will point to an vector of object cgroups.
> > >
> > > Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>
> > > Signed-off-by: Qi Zheng <zhengqi.arch@xxxxxxxxxxxxx>
> > > /*
> > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > > index e7d4e4ff411b6..0e0efaa511d3d 100644
> > > --- a/mm/memcontrol.c
> > > +++ b/mm/memcontrol.c
> > > @@ -247,11 +247,25 @@ static inline void reparent_state_local(struct mem_cgroup *memcg, struct mem_cgr
> > > static inline void reparent_locks(struct mem_cgroup *memcg, struct mem_cgroup *parent)
> > > {
> > > + int nid, nest = 0;
> > > +
> > > spin_lock_irq(&objcg_lock);
> > > + for_each_node(nid) {
> > > + spin_lock_nested(&mem_cgroup_lruvec(memcg,
> > > + NODE_DATA(nid))->lru_lock, nest++);
> > > + spin_lock_nested(&mem_cgroup_lruvec(parent,
> > > + NODE_DATA(nid))->lru_lock, nest++);
> >
> > Is there a reason to acquire locks for all the node together? Why not do
> > the for_each_node(nid) in memcg_reparent_objcgs() and then reparent the
> > LRUs for each node one by one and taking and releasing lock
> > individually. Though the lock for the offlining memcg might not be
>
> To do this, we first need to convert objcg from per-memcg to per-memcg
> per-node. In this way, we can hold the lru lock and objcg lock for
> each node to reparent the folio and the corresponding objcg together.
Oh we want reparenting of both objcg and folio atomic. Let's add a
comment here with the explanation.