memalloc_noreclaim_save(9)
β¨ memalloc_noreclaim_save β¨
okay so this is a page from the Kernel API Manual, and bestie, we're about to get into it π
πΈ NAME πΈ
memalloc_noreclaim_save β marks the implicit __GFP_MEMALLOC scope. periodt.
π SYNOPSIS π
unsigned int memalloc_noreclaim_save (void );
π¦ ARGUMENTS π¦
voidβ no arguments, literally none, it's giving "I need nothing from you" energy π
π DESCRIPTION π
So this function marks the beginning of the __GFP_MEMALLOC allocation scope. Like, it's the "we're doing this now" moment β¨
Once you're in this scope, all further allocations will implicitly add the __GFP_MEMALLOC flag, which (a) prevents entering reclaim, and (b) allows access to all memory reserves. Iconic, but also kind of a big deal π
only use this when the caller guarantees the allocation will allow more memory to be freed very shortly π₯ like, the situation is: it needs to allocate some memory in the process of freeing memory, and it cannot reclaim due to potential recursion. iykyk.
Users of this scope have to be extremely careful to not deplete the reserves completely, and should implement a throttling mechanism that controls the consumption of the reserve based on the amount of freed memory. no cap, that part is serious π
Using a pre-allocated pool (e.g. mempool) should always be considered before using this scope. like, always. π«Ά
Individual allocations under the scope can opt out using __GFP_NOMEMALLOC β cute little escape hatch, we love to see it β
π CONTEXT π
This function should not be used in an interrupt context, because that one does not give PF_MEMALLOC access to reserves. see __gfp_pfmemalloc_flags. π§
π RETURN π
the saved flags, which you pass to memalloc_noreclaim_restore. don't lose 'em π
π SEE ALSO π
kernel file ./include/linux/sched/mm.h, 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_restore(9)memalloc_pin_save(9)memalloc_pin_restore(9)set_active_memcg(9)
and that's the whole page, bestie π sign-off time: this one came out of ./include/linux/sched, dated October 2026, in the Kernel API Manual. slay, go save some flags π
β¨
π¦ 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