refcount_add(9)
π refcount_add β the Kernel API Manual page you actually want to read β¨
okay bestie, welcome to the Kernel API Manual entry for refcount_add(9) β she's a refcount girly and she has thoughts. π
πΈ NAME πΈ
refcount_add β literally just adds a value to a refcount. that's the whole job. no cap. π
β¨ SYNOPSIS β¨
void refcount_add (int i , refcount_t *r );
look at her. two arguments. zero drama (mostly). π¦
π«Ά ARGUMENTS π«Ά
iβ the value you're adding to the refcount, aka the amount, aka the vibe you're contributing π«rβ the refcount itself, the main character, the thing getting incremented π
π DESCRIPTION π
okay so. she's similar to atomic_add, but β and this is the tea β she will saturate at REFCOUNT_SATURATED and WARN. so if you try to push her past the limit she doesn't just wrap around like some chaotic unhinged function, she stops, saturates, and hollers at you. π£οΈπ₯
she provides no memory ordering. nope, zero, none. it is assumed that the caller has guaranteed the object memory to be stable (RCU, etc.). so like, that's on you, bestie, not her. π but she does provide a control dependency and thereby orders future stores. see the comment on top. iykyk. β
now for the part where i have to be a responsible friend: use of this function is not recommended for the normal reference counting use case in which 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. like she's iconic but she's not the one for that job, fr fr. π§
lowkey a warning but a cute one: saturating and WARNing is the behaviour, and no memory ordering is provided β don't come for her when you needed ordering, she never promised that π
π¦ SEE ALSO π¦
kernel file ./include/linux/refcount.h, plus the whole squad:
refcount_set(9)refcount_set_release(9)refcount_read(9)refcount_add_not_zero(9)refcount_add_not_zero_acquire(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)
the whole group chat, together again π«Άπ
and that's the page, bestie!! π she lives in ./include/linux and this lil drop is from October 2026 β mwah, slay, periodt, go forth and refcount 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