rcu_dereference_check(9)
π rcu_dereference_check(9) π
ok so this is from the Kernel API Manual bestie, and we're about to get very cozy with RCU. buckle up π
β¨ NAME β¨
rcu_dereference_check β it's literally rcu_dereference but with debug checking, no cap π
πΈ SYNOPSIS πΈ
rcu_dereference_check (p , c );
π¦ ARGUMENTS π¦
pβ the pointer you're reading, before you dereference it. read it first, deref second, that's the whole vibe π«Άcβ the conditions under which the dereference is gonna take place. like, when is it legal to do this thing energy
π₯ DESCRIPTION π₯
okay so picture this: you do an rcu_dereference, but you also check that the conditions under which the dereference will take place are correct. that's it, that's the function. β¨
typically these conditions indicate the various locking conditions that should be held at that point. and the check should return true if the conditions are satisfied. also β and this is the cute part β an implicit check for being in an RCU read-side critical section (rcu_read_lock) is included. so you don't even have to ask, it's already there π
for example:
bar = rcu_dereference_check(foo->bar, lockdep_is_held(foo->lock));
this could be used to indicate to lockdep that foo->bar may only be dereferenced if either rcu_read_lock is held, or that the lock required to replace the bar struct at foo->bar is held. two valid paths, one iconic function π
note that the list of conditions may also include indications of when a lock need not be held β for example during initialisation or destruction of the target struct. yes bestie, exceptions exist and they're valid π
like so:
bar = rcu_dereference_check(foo->bar, lockdep_is_held(foo->lock) ||
atomic_read(foo->usage) == 0);
and now the main character behaviour: it inserts memory barriers on architectures that require them (currently only the Alpha β yes, currently only the Alpha, that's a direct quote, don't come for me π«Ά), prevents the compiler from refetching (and from merging fetches), and β more importantly β documents exactly which pointers are protected by RCU and checks that the pointer is annotated as __rcu. it's giving documentation and enforcement. we love a multitasker π
π SEE ALSO π
- Kernel file
./include/linux/rcupdate.hβ and then the whole friend group showed up: 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_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 whole page bestie, go forth and dereference responsibly π
signing off from ./include/linux, dated October 2026, still repping rcu_dereference_check(9) like the icon it is β
π¦ 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