refcount_set_release(9)
π¦ refcount_set_release(9) π¦
okay so bestie, we're in the Kernel API Manual today and this one is a baddie. it's refcount_set_release, and it's giving "i set a refcount but make it β¨orderedβ¨". stay with me, it's actually so good.
πΈ NAME πΈ
refcount_set_release β set a refcount's value with release ordering π
β SYNOPSIS β
void refcount_set_release (refcount_t *r , int n );
like, that's it. that's the whole signature. iconic.
π ARGUMENTS π
rβ the refcount. your girl. the actualrefcount_twe're messing with π«Άnβ value to which the refcount will be set. yes, the refcount will be set ton. that's the vibe.
π DESCRIPTION π
okay so listen. highkey this one has a whole situation attached to it.
This function should be used when memory occupied by the object might be reused to store another object β consider SLAB_TYPESAFE_BY_RCU. like, the memory's getting recycled, bestie, and we need to be normal about it. π
It provides release memory ordering, which will order previous memory operations against this store. This ensures all updates to this object are visible once the refcount is set and stale values from the object previously occupying this memory are overwritten with new ones. no cap β the stale stuff gets yeeted, the new stuff is visible, periodt. π₯
This function should be called only after the new object is fully initialized. fr fr. do not skip this step, do not pass go, do not collect $200. π
After this call the object should be considered visible to other tasks even if it was not yet added into an object collection normally used to discover it. which is like, kind of unhinged but also correct β the way that other tasks might have discovered the object previously occupying the same memory, and after memory reuse they can succeed in taking refcount to the new object and start using it. so yeah. it's visible. main character energy, whether you added it to the collection or not. π
π§ SEE ALSO π§
Kernel file ./include/linux/refcount.h β aka the mothership β plus the whole refcount friend group, all linked up:
refcount_set(9)refcount_read(9)refcount_add_not_zero(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)
π and that's the whole page, bestie! this one ships out of ./include/linux, dated October 2026 β so like, future core, slay. mwah π go set some refcounts 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