Re: [PATCH v2 27/28] tools/cgroup: make slabinfo.py compatible with new slab controller

From: Roman Gushchin
Date: Fri Jan 31 2020 - 17:25:48 EST


On Thu, Jan 30, 2020 at 07:47:29AM +0530, Bharata B Rao wrote:
> On Mon, Jan 27, 2020 at 09:34:52AM -0800, Roman Gushchin wrote:
> > Make slabinfo.py compatible with the new slab controller.
>
> Tried using slabinfo.py, but run into some errors. (I am using your
> new_slab.2 branch)
>
> ./tools/cgroup/slabinfo.py /sys/fs/cgroup/memory/1
> Traceback (most recent call last):
> File "/usr/local/bin/drgn", line 11, in <module>
> sys.exit(main())
> File "/usr/local/lib/python3.6/dist-packages/drgn/internal/cli.py", line 127, in main
> runpy.run_path(args.script[0], init_globals=init_globals, run_name="__main__")
> File "/usr/lib/python3.6/runpy.py", line 263, in run_path
> pkg_name=pkg_name, script_name=fname)
> File "/usr/lib/python3.6/runpy.py", line 96, in _run_module_code
> mod_name, mod_spec, pkg_name, script_name)
> File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
> exec(code, run_globals)
> File "./tools/cgroup/slabinfo.py", line 220, in <module>
> main()
> File "./tools/cgroup/slabinfo.py", line 165, in main
> find_memcg_ids()
> File "./tools/cgroup/slabinfo.py", line 43, in find_memcg_ids
> MEMCGS[css.cgroup.kn.id.ino.value_()] = memcg
> AttributeError: '_drgn.Object' object has no attribute 'ino'
>
> I did make this change...
>
> # git diff
> diff --git a/tools/cgroup/slabinfo.py b/tools/cgroup/slabinfo.py
> index b779a4863beb..571fd95224d6 100755
> --- a/tools/cgroup/slabinfo.py
> +++ b/tools/cgroup/slabinfo.py
> @@ -40,7 +40,7 @@ def find_memcg_ids(css=prog['root_mem_cgroup'].css, prefix=''):
> 'sibling'):
> name = prefix + '/' + css.cgroup.kn.name.string_().decode('utf-8')
> memcg = container_of(css, 'struct mem_cgroup', 'css')
> - MEMCGS[css.cgroup.kn.id.ino.value_()] = memcg
> + MEMCGS[css.cgroup.kn.id.value_()] = memcg
> find_memcg_ids(css, name)
>
>
> but now get empty output.

Btw, I've checked that the change like you've done above fixes the problem.
The script works for me both on current upstream and new_slab.2 branch.

Are you sure that in your case there is some kernel memory charged to that
cgroup? Please note, that in the current implementation kmem_caches are created
on demand, so the accounting is effectively enabled with some delay.

Thank you!

Below is an updated version of the patch to use:
--------------------------------------------------------------------------------