memalloc_noreclaim_save(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ 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:


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