rcu_dereference_check(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 🌈


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