refcount_add_not_zero(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… refcount_add_not_zero β€” the Kernel API Manual page, bestie edition

okay so real talk, this one lives in the Kernel API Manual and it's lowkey iconic for exactly one reason: it refuses to touch a refcount that's already at zero. like, boundary-setting queen behavior πŸ’…βœ¨


🌸 NAME 🌸

refcount_add_not_zero β€” add a value to a refcount unless it is 0, no cap, she will not do it πŸ™…β€β™€οΈ


✨ SYNOPSIS ✨

bool refcount_add_not_zero (int i , refcount_t *r );

literally that's the whole signature, she's compact and she knows it πŸŽ€


πŸ¦‹ ARGUMENTS πŸ¦‹

  • i β€” the value you're adding to the refcount. yes bestie, this is the number going in πŸ“
  • r β€” the refcount itself, the refcount_t * main character πŸ‘‘

πŸ’– DESCRIPTION πŸ’–

okay so the vibes here: this function will saturate at REFCOUNT_SATURATED and WARN πŸ”₯ so if you're out here overflowing, she's gonna clamp it and yell at you. no silent failures in this house.

Here's the tea on ordering: it provides no memory ordering, periodt. it is assumed the caller has guaranteed the object memory to be stable (RCU, etc.) β€” that's on you, bestie, not on her πŸ™ˆ. What she does provide is a control dependency, and thereby orders future stores. and the page says: see the comment on top. go read the comment, iykyk πŸ’€

Now the part where the manpage is basically doing a vibe check on your code: use of this function is not recommended for the normal reference counting use case β€” you know, the one where references are taken and released one at a time. in those cases, refcount_inc, or one of its variants, should instead be used to increment a reference count. so like, she's not mad, she's just disappointed 🌈

ngl this is the "wrong tool, right intentions" of kernel functions. for one-at-a-time refs, go to refcount_inc or its variants instead 🫢

πŸ‘‘ RETURN πŸ‘‘

  • false if the passed refcount is 0 πŸ’€
  • true otherwise ✨

she said "zero? not today" and honestly? valid.


πŸ”₯ SEE ALSO πŸ”₯

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


so yeah, that's the whole lore πŸ’œ she's from ./include/linux, she's dated October 2026, and her name is refcount_add_not_zero(9) β€” mwah, no notes, go forth and increment responsibly πŸ§šβ€β™€οΈπŸŽ€

πŸ“¦ where this page comes from