2019-06-27 04:07:01 +08:00
|
|
|
.. _rcu_doc:
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-06-27 04:07:01 +08:00
|
|
|
RCU Concepts
|
|
|
|
============
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
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
|
2022-03-30 22:41:00 +08:00
|
|
|
a grace period to elapse, then free the element. See listRCU.rst for more
|
|
|
|
information on using RCU with linked lists.
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
Frequently Asked Questions
|
2019-06-27 04:07:01 +08:00
|
|
|
--------------------------
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-06-27 04:07:01 +08:00
|
|
|
- Why would anyone want to use RCU?
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-06-27 04:07:01 +08:00
|
|
|
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.
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-06-27 04:07:01 +08:00
|
|
|
- How can the updater tell when a grace period has completed
|
|
|
|
if the RCU readers give no indication when they are done?
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-06-27 04:07:01 +08:00
|
|
|
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.
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-06-27 04:07:01 +08:00
|
|
|
Preemptible variants of RCU (CONFIG_PREEMPT_RCU) get the
|
|
|
|
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 variants of RCU detect grace periods
|
|
|
|
by sampling these counters.
|
2008-01-26 04:08:25 +08:00
|
|
|
|
2019-06-27 04:07:01 +08:00
|
|
|
- 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?
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2022-03-30 22:41:00 +08:00
|
|
|
See UP.rst for more information.
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-06-27 04:07:01 +08:00
|
|
|
- How can I see where RCU is currently used in the Linux kernel?
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-06-27 04:07:01 +08:00
|
|
|
Search for "rcu_read_lock", "rcu_read_unlock", "call_rcu",
|
|
|
|
"rcu_read_lock_bh", "rcu_read_unlock_bh", "srcu_read_lock",
|
|
|
|
"srcu_read_unlock", "synchronize_rcu", "synchronize_net",
|
|
|
|
"synchronize_srcu", and the other RCU primitives. Or grab one
|
|
|
|
of the cscope databases from:
|
2008-01-26 04:08:25 +08:00
|
|
|
|
2019-06-27 04:07:01 +08:00
|
|
|
(http://www.rdrop.com/users/paulmck/RCU/linuxusage/rculocktab.html).
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-06-27 04:07:01 +08:00
|
|
|
- What guidelines should I follow when writing code that uses RCU?
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2022-03-30 22:41:00 +08:00
|
|
|
See checklist.rst.
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-06-27 04:07:01 +08:00
|
|
|
- Why the name "RCU"?
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-01-07 04:07:59 +08:00
|
|
|
"RCU" stands for "read-copy update".
|
2022-03-30 22:41:00 +08:00
|
|
|
listRCU.rst has more information on where this name came from, search
|
|
|
|
for "read-copy update" to find it.
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-06-27 04:07:01 +08:00
|
|
|
- I hear that RCU is patented? What is with that?
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-06-27 04:07:01 +08:00
|
|
|
Yes, it is. There are several known patents related to RCU,
|
2020-01-07 04:08:00 +08:00
|
|
|
search for the string "Patent" in Documentation/RCU/RTFP.txt to find them.
|
2019-06-27 04:07:01 +08:00
|
|
|
Of these, one was allowed to lapse by the assignee, and the
|
|
|
|
others have been contributed to the Linux kernel under GPL.
|
2022-11-05 05:16:48 +08:00
|
|
|
Many (but not all) have long since expired.
|
2019-06-27 04:07:01 +08:00
|
|
|
There are now also LGPL implementations of user-level RCU
|
2020-01-07 04:08:01 +08:00
|
|
|
available (https://liburcu.org/).
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-06-27 04:07:01 +08:00
|
|
|
- I hear that RCU needs work in order to support realtime kernels?
|
2005-09-10 15:26:24 +08:00
|
|
|
|
2022-11-05 05:16:48 +08:00
|
|
|
Realtime-friendly RCU are enabled via the CONFIG_PREEMPTION
|
2019-06-27 04:07:01 +08:00
|
|
|
kernel configuration parameter.
|
2005-09-10 15:26:24 +08:00
|
|
|
|
2019-06-27 04:07:01 +08:00
|
|
|
- Where can I find more information on RCU?
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-01-07 04:08:00 +08:00
|
|
|
See the Documentation/RCU/RTFP.txt file.
|
2022-11-05 07:55:03 +08:00
|
|
|
Or point your browser at (https://docs.google.com/document/d/1X0lThx8OK0ZgLMqVoXiR4ZrGURHrXK6NyLRbeXe3Xac/edit)
|
|
|
|
or (https://docs.google.com/document/d/1GCdQC8SDbb54W1shjEXqGZ0Rq8a6kIeYutdSIajfpLA/edit?usp=sharing).
|