__mem_cgroup..._charge_swap(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… __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 πŸ’…

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