From: Hao Ge <hao.ge@linux.dev>
To: Hongfu Li <lihongfu@kylinos.cn>,
roman.gushchin@linux.dev, vbabka@kernel.org, willy@infradead.org,
harry@kernel.org, pasha.tatashin@soleen.com, surenb@google.com,
akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tools/cgroup/slabinfo: Fix use of slab.memcg_data
Date: Mon, 20 Apr 2026 15:52:44 +0800 [thread overview]
Message-ID: <5e7c23e5-3099-4130-bf51-4a402279d04f@linux.dev> (raw)
In-Reply-To: <20260417020729.952897-1-lihongfu@kylinos.cn>
Hi Hongfu
On 2026/4/17 10:07, 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@kylinos.cn>
Good catch!
> ---
> tools/cgroup/memcg_slabinfo.py | 20 ++++++++++++++------
> 1 file changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/tools/cgroup/memcg_slabinfo.py b/tools/cgroup/memcg_slabinfo.py
> index 6bf4bde77903..e67dcfae1263 100644
> --- a/tools/cgroup/memcg_slabinfo.py
> +++ b/tools/cgroup/memcg_slabinfo.py
> @@ -33,6 +33,13 @@ def err(s):
> sys.exit(1)
>
>
> +def objexts_flags_mask():
> + try:
> + return int(prog.constant('__NR_OBJEXTS_FLAGS')) - 1
> + except:
> + return 0x7
> +
> +
> def find_memcg_ids(css=prog['root_mem_cgroup'].css, prefix=''):
> if not list_empty(css.children.address_of_()):
> for css in list_for_each_entry('struct cgroup_subsys_state',
> @@ -192,23 +199,24 @@ def main():
> # look over all slab folios and look for objects belonging
> # to the given memory cgroup
> for slab in for_each_slab(prog):
> - objcg_vec_raw = slab.memcg_data.value_()
> - if objcg_vec_raw == 0:
> + objext_vec_raw = slab.obj_exts.value_()
Here, we should also check whether it equals OBJEXTS_ALLOC_FAIL,
which indicates that the allocation of obj_exts has failed, Or have I
missed something here?
Thanks
BR
Hao
> + if objext_vec_raw == 0:
> continue
> cache = slab.slab_cache
> if not cache:
> continue
> addr = cache.value_()
> caches[addr] = cache
> - # clear the lowest bit to get the true obj_cgroups
> - objcg_vec = Object(prog, 'struct obj_cgroup **',
> - value=objcg_vec_raw & ~1)
>
> if addr not in stats:
> stats[addr] = 0
>
> + # clear OBJEXTS_FLAGS_MASK bits to get the true slabobj_ext
> + mask = objexts_flags_mask()
> + objext_vec = Object(prog, 'struct slabobj_ext *',
> + value=objext_vec_raw & ~mask)
> for i in range(oo_objects(cache)):
> - if objcg_vec[i].value_() in obj_cgroups:
> + if objext_vec[i].objcg.value_() in obj_cgroups:
> stats[addr] += 1
>
> for addr in caches:
next prev parent reply other threads:[~2026-04-20 7:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-17 2:07 [PATCH] tools/cgroup/slabinfo: Fix use of slab.memcg_data Hongfu Li
2026-04-20 3:19 ` Hongfu Li
2026-04-20 7:52 ` Hao Ge [this message]
2026-04-20 9:00 ` Hongfu Li
2026-04-20 9:32 ` Harry Yoo (Oracle)
2026-04-20 11:13 ` Hongfu Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5e7c23e5-3099-4130-bf51-4a402279d04f@linux.dev \
--to=hao.ge@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=harry@kernel.org \
--cc=lihongfu@kylinos.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=pasha.tatashin@soleen.com \
--cc=roman.gushchin@linux.dev \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox