bpf_mem_cgroup_usage(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– 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:


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