bpf_mem_cgroup_usage(9)
π bpf_mem_cgroup_usage(9) β like, the memory cgroup usage reader, bestie π
okay so this one lives in the Kernel API Manual and it's genuinely so useful β it's bpf_mem_cgroup_usage, section 9. grab a snack, we're reading a cgroup's usage together πβ¨
πΈ NAME πΈ
bpf_mem_cgroup_usage β read memory cgroup's usage π
π¦ SYNOPSIS π¦
__bpf_kfunc unsigned long bpf_mem_cgroup_usage (struct mem_cgroup *memcg
);
so it's a __bpf_kfunc, it hands you back an unsigned long, and it takes exactly one arg. iconic signature tbh π
π ARGUMENTS π
memcgβ memory cgroup. that's it, that's the whole input, she's low maintenance π«Ά
β¨ DESCRIPTION β¨
okay bestie, listen, this part matters so read it twice:
the root memory cgroup is special and is exempt from the memory accounting. no cap, don't @ me, that's just how it is π
the value you get back is the sum of sub-cgroup's usages β and it is not reflecting the size of the root memory cgroup itself. so if you were expecting the root's own size to be folded in thereβ¦ it's not. vibe check: failed, respectfully π
and if you need to get an approximation, you can use root level statistics: e.g. NR_FILE_PAGES + NR_ANON_MAPPED. yup, that's the move π§
β RETURN β
the current memory cgroup size, in bytes π (bytes!! not pages!! we love a unit that says what it is)
π SEE ALSO π
kernel file ./mm/bpf_memcontrol.c, plus the whole squad β go read these too, they're all besties:
bpf_get_root_mem_cgroup(9)bpf_get_mem_cgroup(9)bpf_put_mem_cgroup(9)bpf_mem_cgroup_vm_events(9)bpf_mem_cgroup_memory_events(9)bpf_mem_cgroup_page_state(9)bpf_mem_cgroup_flush_stats(9)
okay that's the whole page, you ate that ππ
sign-off szn: this one comes out of ./mm, dated October 2026 β and yeah, the title up top said bpf_mem_cgroup_usage(9) like three times, which is giving main character energy fr fr. mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms