mem_cgroup_wb_stats(9)
๐ 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โ thebdi_writebackin 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:
get_mem_cgroup_css_from_folio(9)page_cgroup_ino(9)lruvec_page_state_monotonic(9)mod_memcg_state(9)mod_lruvec_state(9)count_memcg_events(9)get_mem_cgroup_from_mm(9)get_mem_cgroup_from_current(9)get_mem_cgroup_from_folio(9)mem_cgroup_iter(9)mem_cgroup_iter_break(9)mem_cgroup_scan_tasks(9)folio_lruvec_lock(9)folio_lruvec_lock_irq(9)folio_lruvec_lock_irqsave(9)mem_cgroup_update_lru_size(9)mem_cgroup_margin(9)mem_cgroup_print_oom_context(9)mem_cgroup_print_oom_meminfo(9)mem_cgroup_get_oom_group(9)consume_stock(9)__memcg_kmem_charge_page(9)__memcg_kmem_uncharge_page(9)mem_cgroup_from_private_id(9)mem_cgroup_css_reset(9)mem_cgroup_calculate_protection(9)mem_cgroup_charge_hugetlb(9)mem_cgroup_swapin_charge_folio(9)mem_cgroup_replace_folio(9)mem_cgroup_migrate(9)mem_cgroup_sk_charge(9)mem_cgroup_sk_uncharge(9)__mem_cgroup_try_charge_swap(9)__mem_cgroup_uncharge_swap(9)obj_cgroup_may_zswap(9)obj_cgroup_charge_zswap(9)obj_cgroup_uncharge_zswap(9)
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
- 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