refcount_add_not_zero(9)
π 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, therefcount_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 π
falseif the passed refcount is0πtrueotherwise β¨
she said "zero? not today" and honestly? valid.
π₯ SEE ALSO π₯
Kernel file ./include/linux/refcount.h β and the whole friend group:
refcount_set(9)refcount_set_release(9)refcount_read(9)refcount_add_not_zero_acquire(9)refcount_add(9)refcount_inc_not_zero(9)refcount_inc_not_zero_acquire(9)refcount_inc(9)refcount_sub_and_test(9)refcount_dec_and_test(9)refcount_dec(9)
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
- 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