2005-04-17 06:20:36 +08:00
|
|
|
RCU Concepts
|
|
|
|
|
|
|
|
|
|
|
|
The basic idea behind RCU (read-copy update) is to split destructive
|
|
|
|
operations into two parts, one that prevents anyone from seeing the data
|
|
|
|
item being destroyed, and one that actually carries out the destruction.
|
|
|
|
A "grace period" must elapse between the two parts, and this grace period
|
|
|
|
must be long enough that any readers accessing the item being deleted have
|
|
|
|
since dropped their references. For example, an RCU-protected deletion
|
|
|
|
from a linked list would first remove the item from the list, wait for
|
|
|
|
a grace period to elapse, then free the element. See the listRCU.txt
|
|
|
|
file for more information on using RCU with linked lists.
|
|
|
|
|
|
|
|
|
|
|
|
Frequently Asked Questions
|
|
|
|
|
|
|
|
o Why would anyone want to use RCU?
|
|
|
|
|
|
|
|
The advantage of RCU's two-part approach is that RCU readers need
|
|
|
|
not acquire any locks, perform any atomic instructions, write to
|
|
|
|
shared memory, or (on CPUs other than Alpha) execute any memory
|
|
|
|
barriers. The fact that these operations are quite expensive
|
|
|
|
on modern CPUs is what gives RCU its performance advantages
|
|
|
|
in read-mostly situations. The fact that RCU readers need not
|
|
|
|
acquire locks can also greatly simplify deadlock-avoidance code.
|
|
|
|
|
|
|
|
o How can the updater tell when a grace period has completed
|
|
|
|
if the RCU readers give no indication when they are done?
|
|
|
|
|
|
|
|
Just as with spinlocks, RCU readers are not permitted to
|
|
|
|
block, switch to user-mode execution, or enter the idle loop.
|
|
|
|
Therefore, as soon as a CPU is seen passing through any of these
|
|
|
|
three states, we know that that CPU has exited any previous RCU
|
|
|
|
read-side critical sections. So, if we remove an item from a
|
|
|
|
linked list, and then wait until all CPUs have switched context,
|
|
|
|
executed in user mode, or executed in the idle loop, we can
|
|
|
|
safely free up that item.
|
|
|
|
|
2009-08-23 04:56:53 +08:00
|
|
|
Preemptible variants of RCU (CONFIG_TREE_PREEMPT_RCU) get the
|
2008-01-26 04:08:25 +08:00
|
|
|
same effect, but require that the readers manipulate CPU-local
|
|
|
|
counters. These counters allow limited types of blocking
|
|
|
|
within RCU read-side critical sections. SRCU also uses
|
|
|
|
CPU-local counters, and permits general blocking within
|
|
|
|
RCU read-side critical sections. These two variants of
|
|
|
|
RCU detect grace periods by sampling these counters.
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
o If I am running on a uniprocessor kernel, which can only do one
|
|
|
|
thing at a time, why should I wait for a grace period?
|
|
|
|
|
|
|
|
See the UP.txt file in this directory.
|
|
|
|
|
|
|
|
o How can I see where RCU is currently used in the Linux kernel?
|
|
|
|
|
2005-05-01 23:59:05 +08:00
|
|
|
Search for "rcu_read_lock", "rcu_read_unlock", "call_rcu",
|
|
|
|
"rcu_read_lock_bh", "rcu_read_unlock_bh", "call_rcu_bh",
|
[PATCH] srcu-3: RCU variant permitting read-side blocking
Updated patch adding a variant of RCU that permits sleeping in read-side
critical sections. SRCU is as follows:
o Each use of SRCU creates its own srcu_struct, and each
srcu_struct has its own set of grace periods. This is
critical, as it prevents one subsystem with a blocking
reader from holding up SRCU grace periods for other
subsystems.
o The SRCU primitives (srcu_read_lock(), srcu_read_unlock(),
and synchronize_srcu()) all take a pointer to a srcu_struct.
o The SRCU primitives must be called from process context.
o srcu_read_lock() returns an int that must be passed to
the matching srcu_read_unlock(). Realtime RCU avoids the
need for this by storing the state in the task struct,
but SRCU needs to allow a given code path to pass through
multiple SRCU domains -- storing state in the task struct
would therefore require either arbitrary space in the
task struct or arbitrary limits on SRCU nesting. So I
kicked the state-storage problem up to the caller.
Of course, it is not permitted to call synchronize_srcu()
while in an SRCU read-side critical section.
o There is no call_srcu(). It would not be hard to implement
one, but it seems like too easy a way to OOM the system.
(Hey, we have enough trouble with call_rcu(), which does
-not- permit readers to sleep!!!) So, if you want it,
please tell me why...
[josht@us.ibm.com: sparse notation]
Signed-off-by: Paul E. McKenney <paulmck@us.ibm.com>
Signed-off-by: Josh Triplett <josh@freedesktop.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-10-04 17:17:02 +08:00
|
|
|
"srcu_read_lock", "srcu_read_unlock", "synchronize_rcu",
|
2008-01-26 04:08:25 +08:00
|
|
|
"synchronize_net", "synchronize_srcu", and the other RCU
|
|
|
|
primitives. Or grab one of the cscope databases from:
|
|
|
|
|
|
|
|
http://www.rdrop.com/users/paulmck/RCU/linuxusage/rculocktab.html
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
o What guidelines should I follow when writing code that uses RCU?
|
|
|
|
|
|
|
|
See the checklist.txt file in this directory.
|
|
|
|
|
|
|
|
o Why the name "RCU"?
|
|
|
|
|
|
|
|
"RCU" stands for "read-copy update". The file listRCU.txt has
|
|
|
|
more information on where this name came from, search for
|
|
|
|
"read-copy update" to find it.
|
|
|
|
|
|
|
|
o I hear that RCU is patented? What is with that?
|
|
|
|
|
|
|
|
Yes, it is. There are several known patents related to RCU,
|
|
|
|
search for the string "Patent" in RTFP.txt to find them.
|
|
|
|
Of these, one was allowed to lapse by the assignee, and the
|
|
|
|
others have been contributed to the Linux kernel under GPL.
|
|
|
|
|
2005-09-10 15:26:24 +08:00
|
|
|
o I hear that RCU needs work in order to support realtime kernels?
|
|
|
|
|
2008-01-26 04:08:25 +08:00
|
|
|
This work is largely completed. Realtime-friendly RCU can be
|
2009-08-23 04:56:53 +08:00
|
|
|
enabled via the CONFIG_TREE_PREEMPT_RCU kernel configuration
|
|
|
|
parameter. However, work is in progress for enabling priority
|
|
|
|
boosting of preempted RCU read-side critical sections. This is
|
|
|
|
needed if you have CPU-bound realtime threads.
|
2005-09-10 15:26:24 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
o Where can I find more information on RCU?
|
|
|
|
|
|
|
|
See the RTFP.txt file in this directory.
|
2005-09-10 15:26:24 +08:00
|
|
|
Or point your browser at http://www.rdrop.com/users/paulmck/RCU/.
|
|
|
|
|
|
|
|
o What are all these files in this directory?
|
|
|
|
|
|
|
|
|
|
|
|
NMI-RCU.txt
|
|
|
|
|
|
|
|
Describes how to use RCU to implement dynamic
|
|
|
|
NMI handlers, which can be revectored on the fly,
|
|
|
|
without rebooting.
|
|
|
|
|
|
|
|
RTFP.txt
|
|
|
|
|
|
|
|
List of RCU-related publications and web sites.
|
|
|
|
|
|
|
|
UP.txt
|
|
|
|
|
|
|
|
Discussion of RCU usage in UP kernels.
|
|
|
|
|
|
|
|
arrayRCU.txt
|
|
|
|
|
|
|
|
Describes how to use RCU to protect arrays, with
|
|
|
|
resizeable arrays whose elements reference other
|
|
|
|
data structures being of the most interest.
|
|
|
|
|
|
|
|
checklist.txt
|
|
|
|
|
|
|
|
Lists things to check for when inspecting code that
|
|
|
|
uses RCU.
|
|
|
|
|
|
|
|
listRCU.txt
|
|
|
|
|
|
|
|
Describes how to use RCU to protect linked lists.
|
|
|
|
This is the simplest and most common use of RCU
|
|
|
|
in the Linux kernel.
|
|
|
|
|
|
|
|
rcu.txt
|
|
|
|
|
|
|
|
You are reading it!
|
|
|
|
|
2006-02-01 19:06:42 +08:00
|
|
|
rcuref.txt
|
|
|
|
|
|
|
|
Describes how to combine use of reference counts
|
|
|
|
with RCU.
|
|
|
|
|
2005-09-10 15:26:24 +08:00
|
|
|
whatisRCU.txt
|
|
|
|
|
|
|
|
Overview of how the RCU implementation works. Along
|
|
|
|
the way, presents a conceptual view of RCU.
|