rcu.txt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. "srcu_read_lock", "srcu_read_unlock", "synchronize_rcu",
  37. "synchronize_net", and "synchronize_srcu".
  38. o What guidelines should I follow when writing code that uses RCU?
  39. See the checklist.txt file in this directory.
  40. o Why the name "RCU"?
  41. "RCU" stands for "read-copy update". The file listRCU.txt has
  42. more information on where this name came from, search for
  43. "read-copy update" to find it.
  44. o I hear that RCU is patented? What is with that?
  45. Yes, it is. There are several known patents related to RCU,
  46. search for the string "Patent" in RTFP.txt to find them.
  47. Of these, one was allowed to lapse by the assignee, and the
  48. others have been contributed to the Linux kernel under GPL.
  49. o I hear that RCU needs work in order to support realtime kernels?
  50. Yes, work in progress.
  51. o Where can I find more information on RCU?
  52. See the RTFP.txt file in this directory.
  53. Or point your browser at http://www.rdrop.com/users/paulmck/RCU/.
  54. o What are all these files in this directory?
  55. NMI-RCU.txt
  56. Describes how to use RCU to implement dynamic
  57. NMI handlers, which can be revectored on the fly,
  58. without rebooting.
  59. RTFP.txt
  60. List of RCU-related publications and web sites.
  61. UP.txt
  62. Discussion of RCU usage in UP kernels.
  63. arrayRCU.txt
  64. Describes how to use RCU to protect arrays, with
  65. resizeable arrays whose elements reference other
  66. data structures being of the most interest.
  67. checklist.txt
  68. Lists things to check for when inspecting code that
  69. uses RCU.
  70. listRCU.txt
  71. Describes how to use RCU to protect linked lists.
  72. This is the simplest and most common use of RCU
  73. in the Linux kernel.
  74. rcu.txt
  75. You are reading it!
  76. rcuref.txt
  77. Describes how to combine use of reference counts
  78. with RCU.
  79. whatisRCU.txt
  80. Overview of how the RCU implementation works. Along
  81. the way, presents a conceptual view of RCU.