percpu_ref_init(9)
π 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β thepercpu_refyou're initializing. this is the main character right here πreleaseβ the function that gets called when the refcount hits0. like, the cleanup crew that shows up when the party's over πβπflagsβ yourPERCPU_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:
percpu_ref_exit(9)percpu_ref_switch_to_atomic(9)percpu_ref_switch_to_atomic_sync(9)percpu_ref_switch_to_percpu(9)percpu_ref_kill_and_confirm(9)percpu_ref_is_zero(9)percpu_ref_reinit(9)percpu_ref_resurrect(9)
β and that's the page!! brought to you by ./lib, dated October 2026, in the Kernel API Manual β periodt π
ππ¦
π¦ 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