rcu_assign_pointer(9)
π rcu_assign_pointer(9) β the kernel API manual, bestie edition
okay so you opened the rcu_assign_pointer page from the Kernel API Manual and you want the tea. say less, i got you π«Ά
β¨ NAME β¨
rcu_assign_pointer β assign to RCU-protected pointer. that's the whole vibe. it's giving "publishing pointers safely" and honestly? iconic.
πΈ SYNOPSIS πΈ
rcu_assign_pointer (p , v );
yes bestie, the spacing is weird, that's just how the manpage renders it, we do not touch it π
π ARGUMENTS π
pβ pointer to assign to. like, the destination. the address that's about to get a whole new personality.vβ value to assign (publish). this is the thing you're making visible to the world. publish it, queen π
π¦ DESCRIPTION π¦
so what does it actually do. it assigns the specified value to the specified RCU-protected pointer, and it does it in a way that ensures any concurrent RCU readers will see any prior initialization. no cap, that's the whole point β nobody sees a half-built struct, everyone sees the finished glow-up β¨
it inserts memory barriers on architectures that require them (which is most of them, fr fr), and it also prevents the compiler from reordering the code that initializes the structure after the pointer assignment. compiler said "i'll just move this around a little" and this macro said "absolutely not, sit down π ".
but more importantly β and this is the part that's lowkey the whole reason it exists β this call documents which pointers will be dereferenced by RCU read-side code. it's like a lil name tag for your pointer. iykyk.
π¨ okay now the serious part, bestie. in some special cases, you may useRCU_INIT_POINTERinstead ofrcu_assign_pointer.RCU_INIT_POINTERis a bit faster due to the fact that it does not constrain either the CPU or the compiler. sounds cute right? it is NOT cute if you use it wrong.
that said, using RCU_INIT_POINTER when you should have used rcu_assign_pointer is a very bad thing that results in impossible-to-diagnose memory corruption. like, memory corruption that will find you at 3am and you will have zero clues. so please be careful π see the RCU_INIT_POINTER comment header for details.
also β and this is the sneaky lil detail that ate β note that rcu_assign_pointer evaluates each of its arguments only once, appearances notwithstanding. one of the "extra" evaluations is in typeof and the other visible only to sparse (__CHECKER__), neither of which actually execute the argument. so the extra ones are basically set dressing, they don't do anything π₯
as with most cpp macros, this execute-arguments-only-once property is important, so please be careful when making changes to rcu_assign_pointer and the other macros that it invokes. like, don't be out here breaking the once-only guarantee, that's main character behavior in the worst way π
π SEE ALSO π
kernel file ./include/linux/rcupdate.h β and then the whole extended friend group, in order, bestie:
same_state_synchronize_rcu(9)cond_resched_tasks_rcu_qs(9)rcu_softirq_qs_periodic(9)RCU_LOCKDEP_WARN(9)lockdep_assert_in_rcu_read_lock(9)lockdep_assert_in_rcu_read_lock_bh(9)lockdep_assert_in_rcu_read_lock_sched(9)lockdep_assert_in_rcu_reader(9)unrcu_pointer(9)RCU_INITIALIZER(9)rcu_replace_pointer(9)rcu_access_pointer(9)rcu_dereference_check(9)rcu_dereference_bh_check(9)rcu_dereference_sched_check(9)rcu_dereference_all_check(9)rcu_dereference_protected(9)rcu_dereference(9)rcu_dereference_bh(9)rcu_dereference_sched(9)rcu_dereference_all(9)rcu_pointer_handoff(9)rcu_read_lock(9)rcu_read_unlock(9)rcu_read_lock_bh(9)rcu_read_unlock_bh(9)rcu_read_lock_sched(9)rcu_read_unlock_sched(9)RCU_INIT_POINTER(9)RCU_POINTER_INITIALIZER(9)kfree_rcu(9)kfree_rcu_mightsleep(9)kfree_rcu_nolock(9)rcu_head_init(9)rcu_head_after_call_rcu(9)
and that's the page, bestie π this lil masterpiece lives in ./include/linux, dated October 2026, and it's filed under rcu_assign_pointer(9). go publish a pointer responsibly, ily, mwah ππ§
π¦ 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