Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

19.1 Introduction to RCU

Read-Copy-Update (RCU) is a highly efficient synchronization mechanism built into the Linux kernel, optimized for scenarios characterized by frequent read operations and infrequent write updates. The RCU infrastructure empowers reader contexts to execute concurrent lookups against shared data elements without acquiring any locks, which significantly elevates read performance and system scalability.

The core algorithmic design principle of RCU is to decouple an update transaction into two discrete, sequential execution phases: removal and reclamation. When traversing an RCU-protected data structure, a reader navigates memory references natively via pointers without acquiring locks of any kind. These read operations utilize the macro helpers rcu_read_lock() and rcu_read_unlock() to explicitly delineate the entry and exit boundaries of an RCU read-side critical section. Upon entering the critical section, rcu_read_lock() signals the commencement of a read operation, and the underlying memory cannot be recycled or reclaimed until the transaction is concluded. Once the lookup pass terminates, rcu_read_unlock() flags the conclusion of the read operation, indicating that the kernel is authorized to safely reclaim the legacy memory block if a reclamation sweep is pending. This precise critical section tracking guarantees that concurrent readers will seamlessly resolve either the fully intact legacy dataset or the fully intact new version, perfectly isolating the read path from encountering partially updated, inconsistent data states.

Compared to the lockless read paths, the write update sequence is significantly more complex. Prior to modifying an active data structure, a writer must first acquire an exclusive mutex lock to guarantee that exactly one update transaction can mutate the data block at any given time. Consequently, concurrent update threads typically rely on standard spinlocks or alternative synchronization primitives to serialize the write operations and maintain absolute data consistency.

When executing an update, the writer generates a localized copy (duplicate) of the target data structure and applies its modifications exclusively to this duplicated instance. This methodology guarantees that the structural integrity of the original reference remaining in memory is fully uncompromised. Upon concluding the mutations within the clone canvas, the writer updates the global tracking pointer to point directly to the newly instantiated data version via atomic pointer-assignment macros like rcu_assign_pointer(), enabling all subsequent inbound reader contexts to seamlessly resolve the new payload data. Prior to freeing up the discarded legacy records, however, the updater triggers the core routine synchronize_rcu(), which blocks the execution path to wait for every pre-existing RCU read-side critical section—defined as any read operation that was active at the precise moment the global pointer assignment was executed—to reach its conclusion. This mandatory temporal window spent waiting for active readers to drain out is designated as the Grace Period.

The formal conclusion of a grace period mathematically guarantees that every concurrent reader context capable of holding an active reference to the legacy data has cleanly exited its critical section. At this juncture, the write thread can safely free (kfree()) the memory space consumed by the legacy records.

The RCU framework achieves peak high-performance concurrent control by executing an explicitly designed space-for-time engineering trade-off, which consumes supplemental memory capacity to simultaneously manage both the new and old versions of a data asset. Under this layout, the lookup path is completely lockless, completely non-blocking, and demands no costly atomic instructions or microarchitectural memory barriers. This layout delivers exceptionally minimal operational overhead, making it uniquely suited for systems where lookup frequencies dwarf update passes. Furthermore, because reader contexts are prohibited from holding locks, RCU environments are immune to catastrophic deadlocks or priority inversion bottlenecks. Lookup passes are never blocked by concurrent write synchronization threads, which minimizes the latency footprint imposed on hard real-time systems.

Despite these advantages, RCU introduces conspicuous operational trade-offs. First, the computational and temporal overhead imposed on write transactions is exceptionally high; because an updater must duplicate structural records (increasing memory bloat) and subsequently stall to wait for all participating CPU cores to cross a grace period checkpoint (increasing processing latency), its complexity is substantially higher than standard locking patterns. Second, engineering a clean RCU implementation is far more complex and error-prone than applying traditional lock structures, demanding meticulous tracking of pointer life cycles and memory boundaries. Finally, the RCU mechanism permits read contexts to view stale, legacy versions of a data block over transient windows, rendering it unviable for application profiles that mandate immediate, strict state consistency.

Copyright © 2026 Guangzhou eSmart Information Technology Co., Ltd. All Rights Reserved.
All content in this book is copyrighted by the author. For personal learning and exchange only. Commercial use without authorization is strictly prohibited. Email:

✉ 3348194517@qq.com | hai616878@gmail.com