Introduction to Read-Copy-Update (RCU)
Readers-writer locks seem like the obvious solution for read-heavy workloads: Multiple readers can proceed simultaneously while writers get exclusive access. However, there is a hidden cost. Recently, I benchmarked a read-heavy workload on an M4 MacBook and found that Read-Copy-Update (RCU) outperformed traditional locks by 110%.
What is Read-Copy-Update (RCU)?
RCU eliminates lock overhead from the read path by removing locks entirely. This isn’t a niche kernel optimization; production systems like Kubernetes etcd, PostgreSQL MVCC, and Envoy proxy rely on RCU principles to achieve scale.
How RCU Works
The name ‘read-copy-update’ describes exactly what happens in this pattern. Readers access shared data without acquiring any locks. When writers need to modify data, they create a copy of the existing data and modify that copy. Once the copy is ready, the writer atomically swaps a pointer to point to the new version.
For example, consider a configuration file that multiple threads access simultaneously. Readers can access the file without any locks, while writers create a copy of the file, modify it, and then atomically swap the pointer to the new version.
Benefits of RCU
RCU delivers ten to thirty times the read performance over traditional locks by completely eliminating lock overhead from the read path. However, it trades strong consistency for scalability, making it ideal for read-heavy workloads where eventual consistency is acceptable.
When to Apply RCU
Apply RCU when read-to-write ratios exceed a ten-to-one ratio and a brief inconsistency is tolerable. Additionally, consider using RCU in systems where readers vastly outnumber writers, such as Kubernetes API serving, PostgreSQL MVCC, Envoy configuration updates, and DNS servers.








