rcu_access_pointer(9)
π rcu_access_pointer β the "look but don't touch" of RCU pointers β¨
hey bestie, welcome to the rcu_access_pointer(9) page from the Kernel API Manual π this one's short but she has opinions, okay? like, there are right ways and wrong ways to use her and the manpage is very much going to tell you about both π«Ά
β¨ SYNOPSIS β¨
rcu_access_pointer (p );
πΈ ARGUMENTS πΈ
pβ the pointer you wanna read, bestie. that's it. that's the argument π
π¦ DESCRIPTION π¦
okay so, what does she actually do? she returns the value of the specified RCU-protected pointer, but β and this is the iconique part β she omits the lockdep checks for being in an RCU read-side critical section π no cap, that's the whole vibe.
when is that useful? when you're accessing the value of the pointer but not dereferencing it β for example, when you're testing an RCU-protected pointer against NULL. that's her moment, that's her main character energy β
lowkey: if you're already inside an RCU read-side critical section, there's little reason to use rcu_access_pointer. like, just use the normal one, queen π
she can also be used in cases where update-side locks prevent the value of the pointer from changing β but ngl, you should use rcu_dereference_protected for that use case instead. she said what she said π
it's also permissible to use rcu_access_pointer within lockless updaters to obtain the old value for an atomic operation β for example, for cmpxchg. slay π₯
π the "accident waiting to happen" section (yes really) π
it is usually best to test the rcu_access_pointer return value directly, okay? the whole point is to avoid accidental dereferences being introduced by later inattentive changes. in other words:
assigning the rcu_access_pointer return value to a local variable results in an accident waiting to happen. πππ
like. don't do it. she's literally warning you. this is the "not me leaving a footgun in my own code" moment, fr fr π
π§ the grace-period use case π§
it is also permissible to use rcu_access_pointer when read-side access to the pointer was removed at least one grace period ago β as is the case in the context of the RCU callback that is freeing up the data, or after a synchronize_rcu returns β¨
this can be useful when tearing down multi-linked structures after a grace period has elapsed π«Ά
however (and she's very clear about this): rcu_dereference_protected is normally preferred for this use case too. it's giving "she'll let you, but she'd rather you didn't" π
π SEE ALSO π
the girlies she runs with β so many icons, honestly π kernel file ./include/linux/rcupdate.h, plus:
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_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)
okay that's the whole page bestie, you ate that π mwah π«Ά
this one comes to you from ./include/linux, dated October 2026, and it's literally titled rcu_access_pointer(9) β go forth and don't assign her return value to a local variable, i'm begging ππΈπ
π¦ 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