RCU_INIT_POINTER(9)
π RCU_INIT_POINTER(9) β the kernel API manual, bestie edition π
Okay so this is a page from the Kernel API Manual and it's about RCU_INIT_POINTER, which initializes an RCU protected pointer. Sounds chill, is actually lowkey a loaded gun, but we'll get there β¨
πΈ NAME πΈ
RCU_INIT_POINTER β initialize an RCU protected pointer π«Ά
β SYNOPSIS β
RCU_INIT_POINTER (p , v );
That's the whole vibe. Two args, one function, zero ordering guarantees (we'll circle back to that, iykyk π).
π¦ ARGUMENTS π¦
pβ the pointer that's getting initialized. the main character of this whole operation πvβ the value you're initializing that pointer to. the supporting actress, but make it iconic π
π₯ DESCRIPTION π₯
So here's the tea: you use RCU_INIT_POINTER to initialize an RCU-protected pointer in those special cases where readers genuinely do not need ordering constraints β not on the CPU, not on the compiler. None. Nada. π§
And the special cases are, like, extremely specific. Here's the list, no cap:
- This use of
RCU_INIT_POINTERis NULLing out the pointer or - The caller has taken whatever steps are required to prevent RCU readers from concurrently accessing this pointer or
- The referenced data structure has already been exposed to readers either at compile time or via
rcu_assign_pointerand- a. You have not made any reader-visible changes to this structure since then or
- b. It is OK for readers accessing this structure from its new location to see the old state of the structure. (For example, the changes were to statistical counters or to other state where exact synchronization is not required.)
That's it. That's the whole checklist. You either tick one of those three boxes, or you don't get to use this function. Periodt. π―
β οΈ Okay so listen, and I mean really listen: failure to follow these rules governing use ofRCU_INIT_POINTERwill result in impossible-to-diagnose memory corruption. Likeβ¦ literally impossible. As in the structures will look OK in crash dumps, but any concurrent RCU readers might see pre-initialized values of the referenced data structure. π So please be very careful how you useRCU_INIT_POINTER!!! This is not a drill, bestie π
Now for the cute little extra scenario π β if you are creating an RCU-protected linked structure that is accessed by a single external-to-structure RCU-protected pointer, then you may use RCU_INIT_POINTER to initialize the internal RCU-protected pointers. But! You must use rcu_assign_pointer to initialize the external-to-structure pointer after you have completely initialized the reader-accessible portions of the linked structure. Order matters, bestie. Read the room. Then read the order. π
And finally, the note that everyone skips and shouldn't: note that unlike rcu_assign_pointer, RCU_INIT_POINTER provides no ordering guarantees for either the CPU or the compiler. Like, none. Zero. It is not giving ordering. It is giving "you're on your own, queen" πβ¨
π SEE ALSO π
Kernel file ./include/linux/rcupdate.h, plus a whole friend group of related pages β 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_assign_pointer(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_POINTER_INITIALIZER(9), kfree_rcu(9), kfree_rcu_mightsleep(9), kfree_rcu_nolock(9), rcu_head_init(9), rcu_head_after_call_rcu(9) β go read them, they're all slay π
and that's the whole page, bestie π«Ά it lives in ./include/linux and this version is dated October 2026, brought to you by the fine folks maintaining the kernel API manual. mwah π go forth and initialize 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