percpu_ref_switch_to_atomic(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ NAME ✨

percpu_ref_switch_to_atomic β€” switch a percpu_ref to atomic mode, bestie πŸ’…

Okay so this is from the Kernel API Manual, and it’s the little switch-up that flips a percpu_ref from percpu mode into atomic mode. Slay. ✨

πŸŽ€ SYNOPSIS πŸŽ€

void percpu_ref_switch_to_atomic (struct percpu_ref *ref ,
       percpu_ref_func_t *confirm_switch );

πŸ’– ARGUMENTS πŸ’–

  • ref β€” the percpu_ref you’re switching to atomic mode. Main character energy, no cap πŸ‘‘
  • confirm_switch β€” optional confirmation callback. It’s optional, but if you pass it, remember the rule: it may not block 🫢

🌸 DESCRIPTION 🌸

Okay so first things first, bestie: do not reach for this for your usual reference counting. There’s literally no reason to use this function for the usual reference counting. Use percpu_ref_kill or percpu_ref_kill_and_confirm instead. Periodt. πŸ’…

This function schedules switching ref to atomic mode. All its percpu counts will be collected to the main atomic counter. On completion, when all CPUs are guaranteed to be in atomic mode, confirm_switch is invoked β€” and note that confirm_switch may not block. Like, no blocking allowed, okay? 😭

This function may be invoked concurrently with all the get/put operations, and it can safely be mixed with kill and reinit operations. No cap. Also note: ref will stay in atomic mode across kill/reinit cycles until percpu_ref_switch_to_percpu is called. So it’s not doing a little temporary vibe β€” it stays atomic until you switch it back. πŸ¦‹

⚠️ Blocking tea: this function may block if ref is in the process of switching to atomic mode. If the caller ensures that ref is not in the process of switching to atomic mode, this function can be called from any context. 🫢

πŸ¦‹ SEE ALSO πŸ¦‹

Kernel file ./lib/percpu-refcount.c and these iconic little references:


Made with πŸ’– from ./lib, October 2026 β€” percpu_ref_switch_to_atomic(9) βœ¨πŸ‘‘

πŸ“¦ where this page comes from