Re: [PATCH v3] tools/cgroup/slabinfo: Fix use of slab.memcg_data

From: Hongfu Li

Date: Sun Apr 26 2026 - 21:28:57 EST


> > > +def kmem_cache_get_node(s, nid):
> > > + try:
> > > + return s.per_node[nid].node
> > > + except AttributeError:
> > > + return s.node[nid]
> > > +
> >
> > This gives me another idea.
> >
> > So actually, we don't need to forcibly convert memcg_data to obj_exts,
> > right?
> >
> > like this:
> >
> > try:
> > raw = slab.memcg_data.value_()
> > new_layout = False
> > except AttributeError:
> > raw = slab.obj_exts.value_()
> > new_layout = True
> >
> > and then take the new path based on new_layout.
> >
> > But I'm not sure if we need to do this, as it would indeed make the
> > helper handle more and more cases.
>
> Thanks for sharing this idea!
>
> It provides a clean way to support both layouts without forced conversion
> of memcg_data to obj_exts. I'm happy to implement this approach in the next
> version of the patch.

When adding compatibility for slab.memcg_data, I found that to run this
script correctly on kernels with slab.memcg_data, we need to handle PG_slab
(the script has already been modified to use PGTY_slab). Adding this
compatibility would introduce extra complexity to the script.

Do we still need to add this compatibility?

In commit 7f770e94d793("memcg_slabinfo: Fix use of PG_slab"), PG_slab was
modified, but slab.memcg_data was left unchanged. Did this patch miss
updating slab.memcg_data?

Best Regards,
Hongfu