__mem_cgroup..._charge_swap(9)
π
__mem_cgroup..._charge_swap(9) β like, the Kernel API Manual page, bestie
okay so. this is a page out of the Kernel API Manual, and the function it's hyping up is __mem_cgroup_try_charge_swap. yes the page title is the truncated one with the ... in it, that's just how the kernel do. anyway it's short, it's sweet, and it's lowkey doing a very specific job. let's get into it π«Ά
β¨ NAME β¨
__mem_cgroup_try_charge_swap β literally "try charging swap space for a folio". that's the whole vibe. it tries. if it works, slay. if not, it tells you. πΈ
πΈ SYNOPSIS πΈ
int __mem_cgroup_try_charge_swap (struct folio *folio );
one argument, one int coming back at you. no cap, that's it. β¨
π ARGUMENTS π
folioβ the folio that's being added to swap. this is the main character of the whole call, the thing getting charged. π
π DESCRIPTION π
so here's the tea β β this function tries to charge the folio's memcg (that's the memory cgroup it belongs to, iykyk) for the swap space sitting at folio->swap.
"tries" is doing a lot of heavy lifting in that sentence and honestly? iconic. because it can fail.
returns 0 on success β everything went great, no notes, perfect. π
returns -ENOMEM on failure β as in, no memory to go around, the charge did not go through, and you gotta deal with it. π
that's genuinely the entire behaviour. short king of a function. π
π¦ SEE ALSO π¦
this page lives in the kernel file ./mm/memcontrol.c, and it's rolling with a whole friend group of related pages. genuinely a group chat. here's every single one, no skips, no "etc." β periodt π
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_wb_stats(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_uncharge_swap(9)obj_cgroup_may_zswap(9)obj_cgroup_charge_zswap(9)obj_cgroup_uncharge_zswap(9)
like, go read some of those too. they're right there. π§
real talk though bestie: this one only tries to charge. if you get -ENOMEM back, that's not a "huh weird" moment, that's the whole point β handle it. π
π cute sign-off π
and that's the page!! π it ships out of ./mm and it's dated October 2026 β so yeah, mark your calendars, time-travelling kernel manpage era. go charge some swap, bestie. π
π¦ 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