set_active_memcg(9)
β¨ 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 passedmemcgstructure, so its lifetime is guaranteed to exceed the scope between twoset_active_memcgcalls. 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:
mmgrab(9)mmget(9)might_alloc(9)memalloc_flags_save(9)memalloc_noio_save(9)memalloc_noio_restore(9)memalloc_nofs_save(9)memalloc_nofs_restore(9)memalloc_noreclaim_save(9)memalloc_noreclaim_restore(9)memalloc_pin_save(9)memalloc_pin_restore(9)
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
- 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