percpu_ref_tryget_live(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… percpu_ref_tryget_live(9) β€” from the Kernel API Manual, bestie

okay so real talk, this one is a tiny function but it has lore. Sit down, hydrate, and let's get into it 🫢


✨ NAME ✨

percpu_ref_tryget_live β€” the "try to increment a live percpu refcount" girlie. She's giving cautious optimism. She's giving "I'll bump your count but only if you're still alive" πŸ’€

✨ SYNOPSIS ✨

bool percpu_ref_tryget_live (struct percpu_ref *ref );

✨ ARGUMENTS ✨

  • ref β€” the percpu_ref you're trying to try-get 🌸 like that's literally the whole job. Just the percpu_ref to try-get, no cap.

✨ DESCRIPTION ✨

So here's the vibe: percpu_ref_tryget_live increments a percpu refcount unless it has already been killed. That's it, that's the whole personality.

It returns true on success and false on failure. Iconic. Binary. Periodt ✨

Now for the part you actually need to internalize, bestie, because this is where people get Gotβ„’:

Completion of percpu_ref_kill in itself doesn't guarantee that this function will fail. 😭

Yes I know. I know. Take a sec. The kill finishing does not automatically mean percpu_ref_tryget_live starts failing β€” those are two different things, okay?

For that guarantee, you want percpu_ref_kill_and_confirm. Once the confirm_kill callback is invoked, then it's guaranteed that no new reference will be given out by percpu_ref_tryget_live. That's the lock-in moment. That's when the door actually closes πŸ”₯

And one more safety note so nothing jumps you:

This function is safe to call as long as ref is between init and exit. Outside that window? Not our problem, not our era πŸ™ˆ

✨ SEE ALSO ✨

Kernel file ./include/linux/percpu-refcount.h β€” and the whole friend group:


and that's the page, bestie πŸŽ€ sourced fresh out of ./include/linux in the October 2026 edition of the Kernel API Manual β€” go forth and try-get responsibly, mwah πŸ’–πŸ‘‘

πŸ“¦ where this page comes from