mempool_alloc(9)
π mempool_alloc β from the Kernel API Manual, bestie π
okay so picture this: you're deep in the kernel, you need a chunk of memory, and you absolutely cannot afford to be let down. that's literally this function. welcome to the group chat π«Ά
β¨ NAME β¨
mempool_alloc β allocate an element from a memory pool. yes that's it, that's the whole vibe. pulling a lil something out of the box π¦
πΈ SYNOPSIS πΈ
void * mempool_alloc (struct mempool *pool , gfp_t gfp_mask );
like. look at her. two args, zero drama β¨
π ARGUMENTS π
poolβ pointer to the memory pool. this is your box, your stash, your main-character pool that you're grabbing from πgfp_maskβ theGFP_*flags. and listen:__GFP_ZEROis not supported. not "discouraged", not "deprecated", just straight up not supported, so don't come for her π
π¦ DESCRIPTION π¦
okay so the way this works: you're allocating an element from pool. and it's a two-step slay β¨
- first, she calls into the
alloc_fnthat was supplied at pool initialization time π₯ - then, when
alloc_fnfails to allocate an element, she dips into the reserved pool π
so like, there's a backup plan built in. it's giving prepared. it's giving "i have a snack in my bag just in case".
now the sleep situation, because this is important: this function only sleeps if the alloc_fn callback sleeps, or when it's waiting for elements to become available in the pool. that's it. those are the two times. no random napping π
β RETURN β
she returns a pointer to the allocated element π β or NULL when she fails to allocate an element π
and here's the tea: allocation failure can only happen when gfp_mask does not include __GFP_DIRECT_RECLAIM. no cap. that's the only failure path. so if you did pass that flag, sit back and relax bestie π
π SEE ALSO π
the kernel file ./mm/mempool.c, and honestly the whole friend group:
mempool_exit(9)mempool_destroy(9)mempool_init(9)mempool_create_node(9)mempool_resize(9)mempool_alloc_bulk(9)mempool_alloc_preallocated(9)mempool_free_bulk(9)mempool_free(9)
and that's the page!! mwah π this one came straight out of ./mm and it's dated October 2026 β so like, future girlie behavior honestly πΈβ¨ go allocate something iconic, ily, bye π§π
π¦ 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