tools/cgroup/memcg_slabinfo.py
Source file repositories/reference/linux-study-clean/tools/cgroup/memcg_slabinfo.py
File Facts
- System
- Linux kernel
- Corpus path
tools/cgroup/memcg_slabinfo.py- Extension
.py- Size
- 6578 bytes
- Lines
- 226
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: tools
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
#!/usr/bin/env drgn
#
# Copyright (C) 2020 Roman Gushchin <guro@fb.com>
# Copyright (C) 2020 Facebook
from os import stat
import argparse
import sys
from drgn.helpers.linux import list_for_each_entry, list_empty
from drgn.helpers.linux import for_each_page
from drgn.helpers.linux.cpumask import for_each_online_cpu
from drgn.helpers.linux.percpu import per_cpu_ptr
from drgn import container_of, FaultError, Object, cast
DESC = """
This is a drgn script to provide slab statistics for memory cgroups.
It supports cgroup v2 and v1 and can emulate memory.kmem.slabinfo
interface of cgroup v1.
For drgn, visit https://github.com/osandov/drgn.
"""
MEMCGS = {}
OO_SHIFT = 16
OO_MASK = ((1 << OO_SHIFT) - 1)
def err(s):
print('slabinfo.py: error: %s' % s, file=sys.stderr, flush=True)
sys.exit(1)
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',
css.children.address_of_(),
'sibling'):
name = prefix + '/' + css.cgroup.kn.name.string_().decode('utf-8')
memcg = container_of(css, 'struct mem_cgroup', 'css')
MEMCGS[css.cgroup.kn.id.value_()] = memcg
find_memcg_ids(css, name)
def is_root_cache(s):
try:
return False if s.memcg_params.root_cache else True
except AttributeError:
return True
def cache_name(s):
if is_root_cache(s):
return s.name.string_().decode('utf-8')
else:
return s.memcg_params.root_cache.name.string_().decode('utf-8')
# SLUB
def oo_order(s):
return s.oo.x >> OO_SHIFT
def oo_objects(s):
return s.oo.x & OO_MASK
Annotation
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.