percpu_ref_init(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… percpu_ref_init β€” the Kernel API Manual glow-up ✨

okay so before we even start: this page is from the Kernel API Manual, section 9, and it's literally about waking a percpu refcount up from its beauty sleep. bestie, let's get into it πŸŽ€


🌸 NAME 🌸

percpu_ref_init β€” initialize a percpu refcount. that's it. that's the whole vibe. she sets it up so it's ready to be counted on 🫢


✨ SYNOPSIS ✨

int percpu_ref_init (struct percpu_ref *ref , percpu_ref_func_t *release
, unsigned int flags , gfp_t gfp );

four args, one int coming back at you. no cap, that's the whole signature πŸ’…


πŸ¦‹ ARGUMENTS πŸ¦‹

  • ref β€” the percpu_ref you're initializing. this is the main character right here πŸ‘‘
  • release β€” the function that gets called when the refcount hits 0. like, the cleanup crew that shows up when the party's over πŸŽ‰β†’πŸ˜­
  • flags β€” your PERCPU_REF_INIT_* flags. yes, the star-asterisk, they all live in that family 🌈
  • gfp β€” the allocation mask to use. the memory-allocation mood board, basically 🧚

πŸ’– DESCRIPTION πŸ’–

so percpu_ref_init initializes ref. and like β€” plot twist β€” ref starts out in percpu mode with a refcount of 1 πŸ’€ yes, one. she comes out the box already at 1, unless flags contains PERCPU_REF_INIT_ATOMIC or PERCPU_REF_INIT_DEAD πŸ™ˆ

those two flags change the start state to atomic, and the latter one β€” PERCPU_REF_INIT_DEAD β€” also sets the initial refcount to 0. so like, born dead, iconic energy fr fr πŸ’€βœ¨

for the actual flag behaviors, go read the definitions of the PERCPU_REF_INIT_* flags. that's where the lore lives, iykyk πŸ“–

and listen β€” release must not sleep 😴🚫 this is highkey important, not me being dramatic. it may potentially be called from RCU callback context by percpu_ref_kill, so if your release tries to nap in there, that's a whole mess. don't do it bestie 🫢


πŸ”₯ SEE ALSO πŸ”₯

the whole friend group πŸ’œ the kernel file ./lib/percpu-refcount.c, plus:


⭐ and that's the page!! brought to you by ./lib, dated October 2026, in the Kernel API Manual β€” periodt πŸ’…πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from