rcu.txt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. RCU Concepts
  2. The basic idea behind RCU (read-copy update) is to split destructive
  3. operations into two parts, one that prevents anyone from seeing the data
  4. item being destroyed, and one that actually carries out the destruction.
  5. A "grace period" must elapse between the two parts, and this grace period
  6. must be long enough that any readers accessing the item being deleted have
  7. since dropped their references. For example, an RCU-protected deletion
  8. from a linked list would first remove the item from the list, wait for
  9. a grace period to elapse, then free the element. See the listRCU.txt
  10. file for more information on using RCU with linked lists.
  11. Frequently Asked Questions
  12. o Why would anyone want to use RCU?
  13. The advantage of RCU's two-part approach is that RCU readers need
  14. not acquire any locks, perform any atomic instructions, write to
  15. shared memory, or (on CPUs other than Alpha) execute any memory
  16. barriers. The fact that these operations are quite expensive
  17. on modern CPUs is what gives RCU its performance advantages
  18. in read-mostly situations. The fact that RCU readers need not
  19. acquire locks can also greatly simplify deadlock-avoidance code.
  20. o How can the updater tell when a grace period has completed
  21. if the RCU readers give no indication when they are done?
  22. Just as with spinlocks, RCU readers are not permitted to
  23. block, switch to user-mode execution, or enter the idle loop.
  24. Therefore, as soon as a CPU is seen passing through any of these
  25. three states, we know that that CPU has exited any previous RCU
  26. read-side critical sections. So, if we remove an item from a
  27. linked list, and then wait until all CPUs have switched context,
  28. executed in user mode, or executed in the idle loop, we can
  29. safely free up that item.
  30. o If I am running on a uniprocessor kernel, which can only do one
  31. thing at a time, why should I wait for a grace period?
  32. See the UP.txt file in this directory.
  33. o How can I see where RCU is currently used in the Linux kernel?
  34. Search for "rcu_read_lock", "rcu_read_unlock", "call_rcu",
  35. "rcu_read_lock_bh", "rcu_read_unlock_bh", "call_rcu_bh",
  36. "synchronize_rcu", and "synchronize_net".
  37. o What guidelines should I follow when writing code that uses RCU?
  38. See the checklist.txt file in this directory.
  39. o Why the name "RCU"?
  40. "RCU" stands for "read-copy update". The file listRCU.txt has
  41. more information on where this name came from, search for
  42. "read-copy update" to find it.
  43. o I hear that RCU is patented? What is with that?
  44. Yes, it is. There are several known patents related to RCU,
  45. search for the string "Patent" in RTFP.txt to find them.
  46. Of these, one was allowed to lapse by the assignee, and the
  47. others have been contributed to the Linux kernel under GPL.
  48. o I hear that RCU needs work in order to support realtime kernels?
  49. Yes, work in progress.
  50. o Where can I find more information on RCU?
  51. See the RTFP.txt file in this directory.
  52. Or point your browser at http://www.rdrop.com/users/paulmck/RCU/.
  53. o What are all these files in this directory?
  54. NMI-RCU.txt
  55. Describes how to use RCU to implement dynamic
  56. NMI handlers, which can be revectored on the fly,
  57. without rebooting.
  58. RTFP.txt
  59. List of RCU-related publications and web sites.
  60. UP.txt
  61. Discussion of RCU usage in UP kernels.
  62. arrayRCU.txt
  63. Describes how to use RCU to protect arrays, with
  64. resizeable arrays whose elements reference other
  65. data structures being of the most interest.
  66. checklist.txt
  67. Lists things to check for when inspecting code that
  68. uses RCU.
  69. listRCU.txt
  70. Describes how to use RCU to protect linked lists.
  71. This is the simplest and most common use of RCU
  72. in the Linux kernel.
  73. rcu.txt
  74. You are reading it!
  75. rcuref.txt
  76. Describes how to combine use of reference counts
  77. with RCU.
  78. whatisRCU.txt
  79. Overview of how the RCU implementation works. Along
  80. the way, presents a conceptual view of RCU.