How Linux Kernel Uses Read-Copy-Update (RCU)

The Read-Copy-Update (RCU) mechanism in the Linux kernel is a synchronization pattern optimized for read-heavy workloads, allowing concurrent reads to occur without locks while updates happen safely in the background. This article explores the core architecture of RCU, how the Linux kernel executes reads and updates simultaneously without data corruption, and the primary subsystems—such as networking and the Virtual File System—that rely on RCU to achieve massive scalability on multi-core systems.

Core Mechanics of RCU

RCU splits the synchronization problem into three distinct phases: read-side execution, update-side execution, and deferred reclamation.

  1. Read-Side Operations: Readers mark the entry and exit of their critical sections using rcu_read_lock() and rcu_read_unlock(). In non-preemptible kernels, these primitives have zero CPU overhead; in preemptible kernels, they merely track nesting levels without taking locks, disabling interrupts, or modifying shared cache lines. Reads proceed completely unobstructed.
  2. Update Operations (Read-Copy): When a writer needs to modify a data structure, it does not alter the shared data directly. Instead, it creates a new copy of the object, applies changes to the copy, and then atomically swaps the global pointer to point to the new structure using primitives like rcu_assign_pointer(). New readers immediately observe the new version, while concurrent existing readers continue accessing the old version undisturbed.
  3. Grace Period and Reclamation (Update): The old memory cannot be freed immediately because in-flight readers may still be traversing it. The kernel enforces a "grace period"—an interval during which every CPU passes through at least one quiescent state (such as a context switch, executing in user mode, or entering an idle state). Once the grace period completes, no readers hold references to the old data. The writer can then safely reclaim the old memory using kfree_rcu() or asynchronous callbacks scheduled via call_rcu().

Major Subsystems Utilizing RCU

The Linux kernel deploys RCU across several core components where read operations exponentially outnumber modifications:

RCU Flavors in the Kernel

To accommodate diverse hardware profiles and latency requirements, the Linux kernel provides specialized implementations of RCU: