0001 .. _rcu_doc:
0002
0003 RCU Concepts
0004 ============
0005
0006 The basic idea behind RCU (read-copy update) is to split destructive
0007 operations into two parts, one that prevents anyone from seeing the data
0008 item being destroyed, and one that actually carries out the destruction.
0009 A "grace period" must elapse between the two parts, and this grace period
0010 must be long enough that any readers accessing the item being deleted have
0011 since dropped their references. For example, an RCU-protected deletion
0012 from a linked list would first remove the item from the list, wait for
0013 a grace period to elapse, then free the element. See listRCU.rst for more
0014 information on using RCU with linked lists.
0015
0016 Frequently Asked Questions
0017 --------------------------
0018
0019 - Why would anyone want to use RCU?
0020
0021 The advantage of RCU's two-part approach is that RCU readers need
0022 not acquire any locks, perform any atomic instructions, write to
0023 shared memory, or (on CPUs other than Alpha) execute any memory
0024 barriers. The fact that these operations are quite expensive
0025 on modern CPUs is what gives RCU its performance advantages
0026 in read-mostly situations. The fact that RCU readers need not
0027 acquire locks can also greatly simplify deadlock-avoidance code.
0028
0029 - How can the updater tell when a grace period has completed
0030 if the RCU readers give no indication when they are done?
0031
0032 Just as with spinlocks, RCU readers are not permitted to
0033 block, switch to user-mode execution, or enter the idle loop.
0034 Therefore, as soon as a CPU is seen passing through any of these
0035 three states, we know that that CPU has exited any previous RCU
0036 read-side critical sections. So, if we remove an item from a
0037 linked list, and then wait until all CPUs have switched context,
0038 executed in user mode, or executed in the idle loop, we can
0039 safely free up that item.
0040
0041 Preemptible variants of RCU (CONFIG_PREEMPT_RCU) get the
0042 same effect, but require that the readers manipulate CPU-local
0043 counters. These counters allow limited types of blocking within
0044 RCU read-side critical sections. SRCU also uses CPU-local
0045 counters, and permits general blocking within RCU read-side
0046 critical sections. These variants of RCU detect grace periods
0047 by sampling these counters.
0048
0049 - If I am running on a uniprocessor kernel, which can only do one
0050 thing at a time, why should I wait for a grace period?
0051
0052 See UP.rst for more information.
0053
0054 - How can I see where RCU is currently used in the Linux kernel?
0055
0056 Search for "rcu_read_lock", "rcu_read_unlock", "call_rcu",
0057 "rcu_read_lock_bh", "rcu_read_unlock_bh", "srcu_read_lock",
0058 "srcu_read_unlock", "synchronize_rcu", "synchronize_net",
0059 "synchronize_srcu", and the other RCU primitives. Or grab one
0060 of the cscope databases from:
0061
0062 (http://www.rdrop.com/users/paulmck/RCU/linuxusage/rculocktab.html).
0063
0064 - What guidelines should I follow when writing code that uses RCU?
0065
0066 See checklist.rst.
0067
0068 - Why the name "RCU"?
0069
0070 "RCU" stands for "read-copy update".
0071 listRCU.rst has more information on where this name came from, search
0072 for "read-copy update" to find it.
0073
0074 - I hear that RCU is patented? What is with that?
0075
0076 Yes, it is. There are several known patents related to RCU,
0077 search for the string "Patent" in Documentation/RCU/RTFP.txt to find them.
0078 Of these, one was allowed to lapse by the assignee, and the
0079 others have been contributed to the Linux kernel under GPL.
0080 There are now also LGPL implementations of user-level RCU
0081 available (https://liburcu.org/).
0082
0083 - I hear that RCU needs work in order to support realtime kernels?
0084
0085 Realtime-friendly RCU can be enabled via the CONFIG_PREEMPT_RCU
0086 kernel configuration parameter.
0087
0088 - Where can I find more information on RCU?
0089
0090 See the Documentation/RCU/RTFP.txt file.
0091 Or point your browser at (http://www.rdrop.com/users/paulmck/RCU/).