@@ -23,6 +23,14 @@ over a rather long period of time, but improvements are always welcome!
2323 Yet another exception is where the low real-time latency of RCU's
2424 read-side primitives is critically important.
2525
26+ One final exception is where RCU readers are used to prevent
27+ the ABA problem (https://en.wikipedia.org/wiki/ABA_problem)
28+ for lockless updates. This does result in the mildly
29+ counter-intuitive situation where rcu_read_lock() and
30+ rcu_read_unlock() are used to protect updates, however, this
31+ approach provides the same potential simplifications that garbage
32+ collectors do.
33+
26341. Does the update code have proper mutual exclusion?
2735
2836 RCU does allow -readers- to run (almost) naked, but -writers- must
@@ -40,7 +48,9 @@ over a rather long period of time, but improvements are always welcome!
4048 explain how this single task does not become a major bottleneck on
4149 big multiprocessor machines (for example, if the task is updating
4250 information relating to itself that other tasks can read, there
43- by definition can be no bottleneck).
51+ by definition can be no bottleneck). Note that the definition
52+ of "large" has changed significantly: Eight CPUs was "large"
53+ in the year 2000, but a hundred CPUs was unremarkable in 2017.
4454
45552. Do the RCU read-side critical sections make proper use of
4656 rcu_read_lock() and friends? These primitives are needed
@@ -55,6 +65,12 @@ over a rather long period of time, but improvements are always welcome!
5565 Disabling of preemption can serve as rcu_read_lock_sched(), but
5666 is less readable.
5767
68+ Letting RCU-protected pointers "leak" out of an RCU read-side
69+ critical section is every bid as bad as letting them leak out
70+ from under a lock. Unless, of course, you have arranged some
71+ other means of protection, such as a lock or a reference count
72+ -before- letting them out of the RCU read-side critical section.
73+
58743. Does the update code tolerate concurrent accesses?
5975
6076 The whole point of RCU is to permit readers to run without
@@ -78,10 +94,10 @@ over a rather long period of time, but improvements are always welcome!
7894
7995 This works quite well, also.
8096
81- c. Make updates appear atomic to readers. For example,
97+ c. Make updates appear atomic to readers. For example,
8298 pointer updates to properly aligned fields will
8399 appear atomic, as will individual atomic primitives.
84- Sequences of perations performed under a lock will -not-
100+ Sequences of operations performed under a lock will -not-
85101 appear to be atomic to RCU readers, nor will sequences
86102 of multiple atomic primitives.
87103
@@ -168,8 +184,8 @@ over a rather long period of time, but improvements are always welcome!
168184
1691855. If call_rcu(), or a related primitive such as call_rcu_bh(),
170186 call_rcu_sched(), or call_srcu() is used, the callback function
171- must be written to be called from softirq context. In particular,
172- it cannot block.
187+ will be called from softirq context. In particular, it cannot
188+ block.
173189
1741906. Since synchronize_rcu() can block, it cannot be called from
175191 any sort of irq context. The same rule applies for
@@ -178,11 +194,14 @@ over a rather long period of time, but improvements are always welcome!
178194 synchronize_sched_expedite(), and synchronize_srcu_expedited().
179195
180196 The expedited forms of these primitives have the same semantics
181- as the non-expedited forms, but expediting is both expensive
182- and unfriendly to real-time workloads. Use of the expedited
183- primitives should be restricted to rare configuration-change
184- operations that would not normally be undertaken while a real-time
185- workload is running.
197+ as the non-expedited forms, but expediting is both expensive and
198+ (with the exception of synchronize_srcu_expedited()) unfriendly
199+ to real-time workloads. Use of the expedited primitives should
200+ be restricted to rare configuration-change operations that would
201+ not normally be undertaken while a real-time workload is running.
202+ However, real-time workloads can use rcupdate.rcu_normal kernel
203+ boot parameter to completely disable expedited grace periods,
204+ though this might have performance implications.
186205
187206 In particular, if you find yourself invoking one of the expedited
188207 primitives repeatedly in a loop, please do everyone a favor:
@@ -193,11 +212,6 @@ over a rather long period of time, but improvements are always welcome!
193212 of the system, especially to real-time workloads running on
194213 the rest of the system.
195214
196- In addition, it is illegal to call the expedited forms from
197- a CPU-hotplug notifier, or while holding a lock that is acquired
198- by a CPU-hotplug notifier. Failing to observe this restriction
199- will result in deadlock.
200-
2012157. If the updater uses call_rcu() or synchronize_rcu(), then the
202216 corresponding readers must use rcu_read_lock() and
203217 rcu_read_unlock(). If the updater uses call_rcu_bh() or
@@ -321,7 +335,7 @@ over a rather long period of time, but improvements are always welcome!
321335 Similarly, disabling preemption is not an acceptable substitute
322336 for rcu_read_lock(). Code that attempts to use preemption
323337 disabling where it should be using rcu_read_lock() will break
324- in real-time kernel builds.
338+ in CONFIG_PREEMPT=y kernel builds.
325339
326340 If you want to wait for interrupt handlers, NMI handlers, and
327341 code under the influence of preempt_disable(), you instead
@@ -356,23 +370,22 @@ over a rather long period of time, but improvements are always welcome!
356370 not the case, a self-spawning RCU callback would prevent the
357371 victim CPU from ever going offline.)
358372
359- 14. SRCU (srcu_read_lock(), srcu_read_unlock(), srcu_dereference(),
360- synchronize_srcu(), synchronize_srcu_expedited(), and call_srcu())
361- may only be invoked from process context. Unlike other forms of
362- RCU, it -is- permissible to block in an SRCU read-side critical
363- section (demarked by srcu_read_lock() and srcu_read_unlock()),
364- hence the "SRCU": "sleepable RCU". Please note that if you
365- don't need to sleep in read-side critical sections, you should be
366- using RCU rather than SRCU, because RCU is almost always faster
367- and easier to use than is SRCU.
368-
369- Also unlike other forms of RCU, explicit initialization
370- and cleanup is required via init_srcu_struct() and
371- cleanup_srcu_struct(). These are passed a "struct srcu_struct"
372- that defines the scope of a given SRCU domain. Once initialized,
373- the srcu_struct is passed to srcu_read_lock(), srcu_read_unlock()
374- synchronize_srcu(), synchronize_srcu_expedited(), and call_srcu().
375- A given synchronize_srcu() waits only for SRCU read-side critical
373+ 14. Unlike other forms of RCU, it -is- permissible to block in an
374+ SRCU read-side critical section (demarked by srcu_read_lock()
375+ and srcu_read_unlock()), hence the "SRCU": "sleepable RCU".
376+ Please note that if you don't need to sleep in read-side critical
377+ sections, you should be using RCU rather than SRCU, because RCU
378+ is almost always faster and easier to use than is SRCU.
379+
380+ Also unlike other forms of RCU, explicit initialization and
381+ cleanup is required either at build time via DEFINE_SRCU()
382+ or DEFINE_STATIC_SRCU() or at runtime via init_srcu_struct()
383+ and cleanup_srcu_struct(). These last two are passed a
384+ "struct srcu_struct" that defines the scope of a given
385+ SRCU domain. Once initialized, the srcu_struct is passed
386+ to srcu_read_lock(), srcu_read_unlock() synchronize_srcu(),
387+ synchronize_srcu_expedited(), and call_srcu(). A given
388+ synchronize_srcu() waits only for SRCU read-side critical
376389 sections governed by srcu_read_lock() and srcu_read_unlock()
377390 calls that have been passed the same srcu_struct. This property
378391 is what makes sleeping read-side critical sections tolerable --
@@ -390,10 +403,16 @@ over a rather long period of time, but improvements are always welcome!
390403 Therefore, SRCU should be used in preference to rw_semaphore
391404 only in extremely read-intensive situations, or in situations
392405 requiring SRCU's read-side deadlock immunity or low read-side
393- realtime latency.
406+ realtime latency. You should also consider percpu_rw_semaphore
407+ when you need lightweight readers.
394408
395- Note that, rcu_assign_pointer() relates to SRCU just as it does
396- to other forms of RCU.
409+ SRCU's expedited primitive (synchronize_srcu_expedited())
410+ never sends IPIs to other CPUs, so it is easier on
411+ real-time workloads than is synchronize_rcu_expedited(),
412+ synchronize_rcu_bh_expedited() or synchronize_sched_expedited().
413+
414+ Note that rcu_dereference() and rcu_assign_pointer() relate to
415+ SRCU just as they do to other forms of RCU.
397416
39841715. The whole point of call_rcu(), synchronize_rcu(), and friends
399418 is to wait until all pre-existing readers have finished before
@@ -435,3 +454,33 @@ over a rather long period of time, but improvements are always welcome!
435454
436455 These debugging aids can help you find problems that are
437456 otherwise extremely difficult to spot.
457+
458+ 18. If you register a callback using call_rcu(), call_rcu_bh(),
459+ call_rcu_sched(), or call_srcu(), and pass in a function defined
460+ within a loadable module, then it in necessary to wait for
461+ all pending callbacks to be invoked after the last invocation
462+ and before unloading that module. Note that it is absolutely
463+ -not- sufficient to wait for a grace period! The current (say)
464+ synchronize_rcu() implementation waits only for all previous
465+ callbacks registered on the CPU that synchronize_rcu() is running
466+ on, but it is -not- guaranteed to wait for callbacks registered
467+ on other CPUs.
468+
469+ You instead need to use one of the barrier functions:
470+
471+ o call_rcu() -> rcu_barrier()
472+ o call_rcu_bh() -> rcu_barrier_bh()
473+ o call_rcu_sched() -> rcu_barrier_sched()
474+ o call_srcu() -> srcu_barrier()
475+
476+ However, these barrier functions are absolutely -not- guaranteed
477+ to wait for a grace period. In fact, if there are no call_rcu()
478+ callbacks waiting anywhere in the system, rcu_barrier() is within
479+ its rights to return immediately.
480+
481+ So if you need to wait for both an RCU grace period and for
482+ all pre-existing call_rcu() callbacks, you will need to execute
483+ both rcu_barrier() and synchronize_rcu(), if necessary, using
484+ something like workqueues to to execute them concurrently.
485+
486+ See rcubarrier.txt for more information.
0 commit comments