mem_cgroup_wb_stats(9)

๐Ÿ“ฆ version 7.3.1, in nixpkgs unstable

๐Ÿ’… mem_cgroup_wb_stats(9) โ€” the Kernel API Manual, bestie edition ๐ŸŽ€

okay so this whole vibe comes straight out of the Kernel API Manual, and the star of the show is mem_cgroup_wb_stats(9). buckle up ๐Ÿฆ‹


โœจ NAME โœจ

mem_cgroup_wb_stats โ€” retrieve writeback related stats from its memcg. that's literally it. it goes and grabs the numbers for you ๐Ÿ’–


๐ŸŒธ SYNOPSIS ๐ŸŒธ

void mem_cgroup_wb_stats (struct bdi_writeback *wb , unsigned long *pfilepages , unsigned long *pheadroom , unsigned long *pdirty , unsigned long *pwriteback );

likeโ€ฆ it returns void (no takesies-backsies, no return value, she's just here to fill your pointers) and it wants five things from you. five. count 'em. ๐Ÿซถ


๐ŸŽ€ ARGUMENTS ๐ŸŽ€

  • wb โ€” the bdi_writeback in question. yes, that one. the one we're talking about ๐Ÿ’…
  • pfilepages โ€” out parameter for number of file pages โœจ
  • pheadroom โ€” out parameter for number of allocatable pages according to memcg. the little bit of breathing room, basically ๐ŸŒฌ๏ธ
  • pdirty โ€” out parameter for number of dirty pages ๐Ÿซง
  • pwriteback โ€” out parameter for number of pages under writeback. they're out there, doing their thing ๐Ÿ’€
ngl the "out parameter" thing is doing a lot of work in this list โ€” you pass the addresses, she writes the numbers in. no cap ๐Ÿ“

๐Ÿ”ฅ DESCRIPTION ๐Ÿ”ฅ

so the whole job is: determine the numbers of file, headroom, dirty, and writeback pages in wb's memcg. that's the assignment, and she ate ๐Ÿ‘‘

File, dirty and writeback are self-explanatory. like, you get it. i get it. we all get it. ๐Ÿ’–

Headroom though? headroom is a bit more involved. headroom is the lowkey complicated one of the group ๐Ÿ™ˆ

A memcg's headroom is "min(max, high) - used". write that down. it's giving math but make it cgroup ๐Ÿงฎ

In the hierarchy, the headroom is calculated as the lowest headroom of itself and the ancestors. so like, your headroom is only as good as your most constrained ancestor, bestie. it's giving generational trauma but for memory cgroups ๐Ÿ˜ญ

โš ๏ธ important vibe check: note that this doesn't consider the actual amount of available memory in the system. she's not looking at the real hardware situation, okay?? so the caller should further cap *pheadroom accordingly. cap it yourself. do not come for her about it ๐Ÿ’€

๐ŸŒˆ SEE ALSO ๐ŸŒˆ

the whole friend group, fr fr. Kernel file ./mm/memcontrol.c plus:


and that's the whole page, bestie ๐Ÿ’œ mwah ๐Ÿ’‹

signed, sealed, delivered from the ./mm directory, dated October 2026, and it's still called mem_cgroup_wb_stats(9) โ€” iykyk โœจ๐ŸŽ€

๐Ÿ“ฆ where this page comes from