mempool_alloc(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– 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 β€” the GFP_* flags. and listen: __GFP_ZERO is 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 ✨

  1. first, she calls into the alloc_fn that was supplied at pool initialization time πŸ”₯
  2. then, when alloc_fn fails 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:


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