rcu.txt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. Preemptible variants of RCU (CONFIG_PREEMPT_RCU) get the
  31. same effect, but require that the readers manipulate CPU-local
  32. counters. These counters allow limited types of blocking within
  33. RCU read-side critical sections. SRCU also uses CPU-local
  34. counters, and permits general blocking within RCU read-side
  35. critical sections. These variants of RCU detect grace periods
  36. by sampling these counters.
  37. o If I am running on a uniprocessor kernel, which can only do one
  38. thing at a time, why should I wait for a grace period?
  39. See the UP.txt file in this directory.
  40. o How can I see where RCU is currently used in the Linux kernel?
  41. Search for "rcu_read_lock", "rcu_read_unlock", "call_rcu",
  42. "rcu_read_lock_bh", "rcu_read_unlock_bh", "call_rcu_bh",
  43. "srcu_read_lock", "srcu_read_unlock", "synchronize_rcu",
  44. "synchronize_net", "synchronize_srcu", and the other RCU
  45. primitives. Or grab one of the cscope databases from:
  46. http://www.rdrop.com/users/paulmck/RCU/linuxusage/rculocktab.html
  47. o What guidelines should I follow when writing code that uses RCU?
  48. See the checklist.txt file in this directory.
  49. o Why the name "RCU"?
  50. "RCU" stands for "read-copy update". The file listRCU.txt has
  51. more information on where this name came from, search for
  52. "read-copy update" to find it.
  53. o I hear that RCU is patented? What is with that?
  54. Yes, it is. There are several known patents related to RCU,
  55. search for the string "Patent" in RTFP.txt to find them.
  56. Of these, one was allowed to lapse by the assignee, and the
  57. others have been contributed to the Linux kernel under GPL.
  58. There are now also LGPL implementations of user-level RCU
  59. available (http://lttng.org/?q=node/18).
  60. o I hear that RCU needs work in order to support realtime kernels?
  61. This work is largely completed. Realtime-friendly RCU can be
  62. enabled via the CONFIG_PREEMPT_RCU kernel configuration
  63. parameter. However, work is in progress for enabling priority
  64. boosting of preempted RCU read-side critical sections. This is
  65. needed if you have CPU-bound realtime threads.
  66. o Where can I find more information on RCU?
  67. See the RTFP.txt file in this directory.
  68. Or point your browser at http://www.rdrop.com/users/paulmck/RCU/.
  69. o What are all these files in this directory?
  70. See 00-INDEX for the list.