set_active_memcg(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ set_active_memcg ✨

okay so this is a page from the Kernel API Manual (section 9, kernel land, very serious business πŸ’…) and it's about set_active_memcg β€” the little function that says "hey, everything allocated from here until I say stop? charge it to this memcg." bestie, it's giving scope-manager energy and we're obsessed 🫢


🌸 NAME 🌸

set_active_memcg β€” kicks off the remote memcg charging scope. that's it, that's the whole job πŸ’–


πŸŽ€ SYNOPSIS πŸŽ€

struct mem_cgroup * set_active_memcg (struct mem_cgroup *memcg );

(yes the spacing is exactly like that, don't come for me, that's how it's written ✨)


πŸ¦‹ ARGUMENTS πŸ¦‹

  • memcg β€” the memcg you wanna charge. the one catching all the allocation allegations. 🧚

πŸ‘‘ DESCRIPTION πŸ‘‘

so here's the vibe: this function marks the beginning of the remote memcg charging scope. 🌈

translation? every single __GFP_ACCOUNT allocation from this moment until the end of the scope gets charged to the given memcg. all of them. no cap. πŸ’€

⚠️ okay this part is important so listen up: please, make sure that caller has a reference to the passed memcg structure, so its lifetime is guaranteed to exceed the scope between two set_active_memcg calls. no dangling references on my watch, bestie 😭 keep that thing alive.

πŸ’… NOTE πŸ’…

this function can nest. πŸͺ† which means β€” users must save the return value and reset the previous value after their own charging scope is over. don't just leave it hanging, that's not the move. save it, restore it, slay. ✨


⭐ SEE ALSO ⭐

the kernel file ./include/linux/sched/mm.h β€” aka where this all lives β€” plus the whole friend group:

go read those too, iykyk πŸ“š


and that's the whole page, bestie! this one came straight outta ./include/linux/sched, stamped October 2026 β€” so yeah, mark your calendars and remember: save your return value, restore your scope, and always keep a reference. mwah πŸ’‹πŸŽ€πŸ’œ

πŸ“¦ where this page comes from