rcu.rst 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. .. _rcu_doc:
  2. RCU Concepts
  3. ============
  4. The basic idea behind RCU (read-copy update) is to split destructive
  5. operations into two parts, one that prevents anyone from seeing the data
  6. item being destroyed, and one that actually carries out the destruction.
  7. A "grace period" must elapse between the two parts, and this grace period
  8. must be long enough that any readers accessing the item being deleted have
  9. since dropped their references. For example, an RCU-protected deletion
  10. from a linked list would first remove the item from the list, wait for
  11. a grace period to elapse, then free the element. See listRCU.rst for more
  12. information on using RCU with linked lists.
  13. Frequently Asked Questions
  14. --------------------------
  15. - Why would anyone want to use RCU?
  16. The advantage of RCU's two-part approach is that RCU readers need
  17. not acquire any locks, perform any atomic instructions, write to
  18. shared memory, or (on CPUs other than Alpha) execute any memory
  19. barriers. The fact that these operations are quite expensive
  20. on modern CPUs is what gives RCU its performance advantages
  21. in read-mostly situations. The fact that RCU readers need not
  22. acquire locks can also greatly simplify deadlock-avoidance code.
  23. - How can the updater tell when a grace period has completed
  24. if the RCU readers give no indication when they are done?
  25. Just as with spinlocks, RCU readers are not permitted to
  26. block, switch to user-mode execution, or enter the idle loop.
  27. Therefore, as soon as a CPU is seen passing through any of these
  28. three states, we know that that CPU has exited any previous RCU
  29. read-side critical sections. So, if we remove an item from a
  30. linked list, and then wait until all CPUs have switched context,
  31. executed in user mode, or executed in the idle loop, we can
  32. safely free up that item.
  33. Preemptible variants of RCU (CONFIG_PREEMPT_RCU) get the
  34. same effect, but require that the readers manipulate CPU-local
  35. counters. These counters allow limited types of blocking within
  36. RCU read-side critical sections. SRCU also uses CPU-local
  37. counters, and permits general blocking within RCU read-side
  38. critical sections. These variants of RCU detect grace periods
  39. by sampling these counters.
  40. - If I am running on a uniprocessor kernel, which can only do one
  41. thing at a time, why should I wait for a grace period?
  42. See UP.rst for more information.
  43. - How can I see where RCU is currently used in the Linux kernel?
  44. Search for "rcu_read_lock", "rcu_read_unlock", "call_rcu",
  45. "rcu_read_lock_bh", "rcu_read_unlock_bh", "srcu_read_lock",
  46. "srcu_read_unlock", "synchronize_rcu", "synchronize_net",
  47. "synchronize_srcu", and the other RCU primitives. Or grab one
  48. of the cscope databases from:
  49. (http://www.rdrop.com/users/paulmck/RCU/linuxusage/rculocktab.html).
  50. - What guidelines should I follow when writing code that uses RCU?
  51. See checklist.rst.
  52. - Why the name "RCU"?
  53. "RCU" stands for "read-copy update".
  54. listRCU.rst has more information on where this name came from, search
  55. for "read-copy update" to find it.
  56. - I hear that RCU is patented? What is with that?
  57. Yes, it is. There are several known patents related to RCU,
  58. search for the string "Patent" in Documentation/RCU/RTFP.txt to find them.
  59. Of these, one was allowed to lapse by the assignee, and the
  60. others have been contributed to the Linux kernel under GPL.
  61. There are now also LGPL implementations of user-level RCU
  62. available (https://liburcu.org/).
  63. - I hear that RCU needs work in order to support realtime kernels?
  64. Realtime-friendly RCU can be enabled via the CONFIG_PREEMPT_RCU
  65. kernel configuration parameter.
  66. - Where can I find more information on RCU?
  67. See the Documentation/RCU/RTFP.txt file.
  68. Or point your browser at (http://www.rdrop.com/users/paulmck/RCU/).