RCU

Reading a few LWN articles on RCUs (1 2 3) really shed some light on their properties and use.

On read-intensive scenarios, it's more efficient to replace read/write locking with an RCU. This is possible because all Linux platforms have atomic pointer read/write operations.

Read critical section
  • dereferences pointers through a mechanism with platform specific memory ordering guarantees: rcu_dereference()
  • may not sleep
  • may not keep or pass dereferenced pointers outside the critical section
Write critical section
  • Protects agains concurrent writes using regular spinlock mutex
  • Makes a copy of the original structure, making updates in the copy
  • Swaps in the new version, while still keeping the old version (atomic)
  • Invokes synchronize_rcu() to wait for all readers to exit their current rcu read critical sections.
  • ( A non-pre-emptible kernel can simpy wait for all CPUs to switch contexts. )
  • Free the old version
Properly used RCUs are immune to deadlocks, but synchronous writes may be very slow due to need to wait for the context switches.

Comments

Popular posts from this blog

iMovie event library on a network drive, NAS

Proxmox PCIe passthrough on HP gen8 - failed to set iommu for container

Backup and restore observium