McKenney: So You Want to Rust the Linux Kernel?
McKenney: So You Want to Rust the Linux Kernel?
Posted Oct 8, 2021 17:11 UTC (Fri) by PaulMcKenney (✭ supporter ✭, #9624)In reply to: McKenney: So You Want to Rust the Linux Kernel? by neilbrown
Parent article: McKenney: So You Want to Rust the Linux Kernel?
Unfortunately, when I tell someone about "a way of waiting for already-started things to finish", it is a very rare someone who bridges the chasm between this semantic and their particular use case. In fact, the most common response is of the form "but what on Earth can I possibly do with that???", albeit typically considerably less polite.
So yes, the analogy with reader-writer locking is quite rough. For example, RCU readers are not blocked by updaters, only very specific portions of RCU updaters are blocked by readers, and in some cases there is nothing delimiting the extent of an RCU updater.
But the analogy between reference counts and RCU is also quite rough. RCU readers cannot acquire a reference to a specific object, but instead acquire a "bulk reference" to each and every RCU-protected object that is still reachable by readers. RCU updaters have no way to determine if a given object is referenced by readers. RCU readers have no way to determine that their reference is the last one. RCU readers unconditionally acquire their bulk reference, whereas in many reference-counting implementations, an attempt to acquire a reference to a specific object might in fact fail. Yes, the CONFIG_PREEMPT=y RCU implementation's current->rcu_read_lock_nesting can be thought of as a per-task reference counter, but the CONFIG_PREEMPT=n RCU implementation has no such counter.
So why do I usually lead with the reader-writer locking analogy when describing RCU?
Because (1) RCU is most frequently used as an alternative to reader-writer locking, (2) Almost everyone is familiar with reader-writer locking, and (3) As a rough rule of thumb, those who have both RCU and hazard pointers at their disposal should first try using RCU to replace reader-writer locking and hazard pointers to replace reference counts. (And yes, the analogy between hazard pointers and reference counting is also rather rough: Hazard pointers cannot easily determine whether anything holds a reference to a given object and also cannot reasonably check that their reference is the last one for a given object.)
Does that help?
