USEFUL GFP FLAG COMBINATIONS(9)
πΈ USEFUL GFP FLAG COMBINATIONS β gfp_t(9), Kernel API Manual πΈ
ok so bestie, this is section 9 of the Kernel API Manual, and the page is literally called Useful GFP flag combinations. it's the lil cheat-sheet of the GFP combos everyone actually uses, and i'm gonna walk you through every single one π
β¨ DESCRIPTION β¨
so here's the whole vibe: these are the useful GFP flag combinations that are commonly used β the greatest hits, the ones that ate π
and the rec is super clear: it is recommended that subsystems start with one of these combinations and then set/clear __GFP_FOO flags as necessary. that's it, that's the whole strategy β pick a base combo, then tweak β¨
π¦ the flags themselves
GFP_ATOMICβ users can not sleep and the allocation needs to succeed, no cap. a lower watermark is applied so you can get access to the "atomic reserves". β οΈ the current implementation doesn't support NMI, nor contexts that disable preemption underPREEMPT_RTβ and yes that includesraw_spin_lockand plainpreempt_disable. see "Memory allocation" inDocumentation/core-api/real-time/differences.rstfor more info. iykyk πGFP_KERNELβ the classic, the main character π it's typical for kernel-internal allocations. the caller requiresZONE_NORMALor a lower zone for direct access, but can direct reclaim.GFP_KERNEL_ACCOUNTβ literally the same asGFP_KERNEL, except the allocation is accounted to kmemcg. that's the whole diff fr fr.GFP_NOWAITβ for kernel allocations that should not stall for direct reclaim, start physical IO, or use any filesystem callback. and bestieβ¦ it is very likely to fail to allocate memory, even for very small allocations π the same restrictions on calling contexts apply as forGFP_ATOMIC.GFP_NOIOβ will use direct reclaim to discard clean pages or slab pages that do not require the starting of any physical IO. π«Ά please try to avoid using this flag directly β instead usememalloc_noio_{save,restore}to mark the whole scope which cannot perform any IO, with a short explanation why. all allocation requests will inheritGFP_NOIOimplicitly.GFP_NOFSβ will use direct reclaim but will not use any filesystem interfaces. same deal, please try to avoid using this flag directly β instead usememalloc_nofs_{save,restore}to mark the whole scope which cannot/shouldn't recurse into the FS layer, with a short explanation why. all allocation requests will inheritGFP_NOFSimplicitly.GFP_USERβ for userspace allocations that also need to be directly accessibly by the kernel or hardware. typically used by hardware for buffers that are mapped to userspace (e.g. graphics) that hardware still must DMA to. π₯ cpuset limits are enforced for these allocations.GFP_DMAβ exists for historical reasons and should be avoided where possible π the flag indicates that the caller requires that the lowest zone be used (ZONE_DMAor 16M on x86-64). ideally this would be removed, but it would require careful auditing, because some users really require it and others use the flag to avoid lowmem reserves inZONE_DMAand treat the lowest zone as a type of emergency reserve.GFP_DMA32β similar toGFP_DMA, except the caller requires a 32-bit address. π note thatkmalloc(..., GFP_DMA32)does not return DMA32 memory because the DMA32 kmalloc cache array is not implemented. (Reason: there is no such user in kernel.)GFP_HIGHUSERβ for userspace allocations that may be mapped to userspace, do not need to be directly accessible by the kernel, but that cannot move once in use. an example may be a hardware allocation that maps data directly into userspace but has no addressing limitations.GFP_HIGHUSER_MOVABLEβ for userspace allocations that the kernel does not need direct access to but can usekmapwhen access is required. they are expected to be movable via page reclaim or page migration π¦ typically, pages on the LRU would also be allocated withGFP_HIGHUSER_MOVABLE.GFP_TRANSHUGEandGFP_TRANSHUGE_LIGHTβ used for THP allocations. they are compound allocations that will generally fail quickly if memory is not available and will not wakekswapd/kcompactdon failure. the_LIGHTversion does not attempt reclaim/compaction at all and is by default used in page fault path, while the non-light is used bykhugepaged.
π friendly reminder thatGFP_ATOMICandGFP_NOWAITare the risky girls β no sleeping, andGFP_NOWAITis very likely to fail even on tiny allocations. don't say i didn't warn you π
π SEE ALSO π
- Kernel file
./tools/include/linux/gfp_types.h gfp_t(9)Page mobility and placement hints(9)Watermark modifiers(9)Reclaim modifiers(9)Action modifiers(9)
that's the whole page bestie, you're so ready for your allocator era πβ¨
signing off from ./tools/include/linux β October 2026 edition of Useful GFP fβ¦combinations(9) ππ
π¦ 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