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

From: Harry Yoo (Oracle)

Date: Tue Apr 21 2026 - 06:43:15 EST


On Tue, Apr 21, 2026 at 01:58:29PM +0800, Hongfu Li wrote:
> After the introduce slabobj_ext to support slab object extensions, the
> memcg_slabinfo tool broke. An attempt to run it produces a trace like
> this:
> Traceback (most recent call last):
> File "/usr/local/bin/drgn", line 8, in <module>
> sys.exit(_main())
> ^^^^^^^
> File "/usr/local/lib64/python3.11/site-packages/drgn/cli.py", line 688, in _main
> runpy.run_path(
> File "<frozen runpy>", line 291, in run_path
> File "<frozen runpy>", line 98, in _run_module_code
> File "<frozen runpy>", line 88, in _run_code
> File "/root/memcg_slabinfo.py", line 225, in <module>
> main()
> File "/root/memcg_slabinfo.py", line 195, in main
> objcg_vec_raw = slab.memcg_data.value_()
> AttributeError: 'struct slab' has no member 'memcg_data'
>
> Fixes: 21c690a349ba ("mm: introduce slabobj_ext to support slab object extensions")
> Signed-off-by: Hongfu Li <lihongfu@xxxxxxxxxx>
>
> Changes in v2:

Changes between versions should not be part of the commit message.
to the changelog.

> - Skip slabs after masking when the base is zero (OBJEXTS_ALLOC_FAIL).
> - Walk slab->obj_exts using base + stride * i (same indexing as slab_obj_ext()).

These two changes looks good to me.

> - Link to v1: https://lore.kernel.org/all/20260417020729.952897-1-lihongfu@xxxxxxxxxx/
> ---

"Changes since ..." should be under this '---' line so that it won't be
included in the commit message.

Not sure what kernel version you're using, but due to recent changes
in slab (v7.1-rc1), we need this:

diff --git a/tools/cgroup/memcg_slabinfo.py b/tools/cgroup/memcg_slabinfo.py
old mode 100644
new mode 100755
index b5d4e51671cd..e54e2bb65fe2
--- a/tools/cgroup/memcg_slabinfo.py
+++ b/tools/cgroup/memcg_slabinfo.py
@@ -101,7 +101,7 @@ def slub_get_slabinfo(s, cfg):
nr_free = 0

for node in range(cfg['nr_nodes']):
- n = s.node[node]
+ n = s.per_node[node].node
nr_slabs += n.nr_slabs.counter.value_()
nr_objs += n.total_objects.counter.value_()
nr_free += count_partial(n, count_free)

Perhaps you could make it work for kernel w/ and w/o the recent slab
changes. (By checking if the field exists and falling back)

Please address this and adjust the commit message accordingly.

--
Cheers,
Harry / Hyeonggon