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

From: Bharata B Rao
Date: Wed Feb 12 2020 - 00:21:50 EST


On Fri, Jan 31, 2020 at 10:24:58PM +0000, Roman Gushchin wrote:
> 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:
>
> 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.

I do see kmem getting charged.

# cat /sys/fs/cgroup/memory/1/memory.kmem.usage_in_bytes /sys/fs/cgroup/memory/1/memory.usage_in_bytes
182910976
4515627008

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

I see the below failure with this updated version:

# ./tools/cgroup/slabinfo-new.py /sys/fs/cgroup/memory/1
# name <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab> : tunables <limit> <batchcount> <sharedfactor> : slabdata <active_slabs> <num_slabs> <sharedavail>
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-new.py", line 158, in <module>
main()
File "./tools/cgroup/slabinfo-new.py", line 153, in main
memcg.kmem_caches.address_of_(),
AttributeError: 'struct mem_cgroup' has no member 'kmem_caches'

> +
> +def main():
> + parser = argparse.ArgumentParser(description=DESC,
> + formatter_class=
> + argparse.RawTextHelpFormatter)
> + parser.add_argument('cgroup', metavar='CGROUP',
> + help='Target memory cgroup')
> + args = parser.parse_args()
> +
> + try:
> + cgroup_id = stat(args.cgroup).st_ino
> + find_memcg_ids()
> + memcg = MEMCGS[cgroup_id]
> + except KeyError:
> + err('Can\'t find the memory cgroup')
> +
> + cfg = detect_kernel_config()
> +
> + print('# name <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab>'
> + ' : tunables <limit> <batchcount> <sharedfactor>'
> + ' : slabdata <active_slabs> <num_slabs> <sharedavail>')
> +
> + for s in list_for_each_entry('struct kmem_cache',
> + memcg.kmem_caches.address_of_(),
> + 'memcg_params.kmem_caches_node'):

Are you sure this is the right version? In the previous version
you had the if-else loop that handled shared_slab_pages and old
scheme separately.

Regards,
Bharata.