RCU Quiescent State and Tree RCU¶
Overview¶
Previous RCU learning focused on:
- Object publication
- Grace period
- Deferred reclamation
- RCU APIs
A simplified educational implementation often uses a global reader counter:
and determines grace period completion using:
Although easy to understand, this approach does not scale well on large multi-core systems.
Linux RCU uses a different design based on quiescent state tracking and per-CPU progress monitoring.
The Limitation of Reader Counting¶
A simple implementation maintains:
Every reader performs:
Grace period completion becomes:
Problem¶
All CPUs modify the same shared variable:
This creates:
- Shared cacheline contention
- Atomic operation overhead
- Poor scalability
As CPU count increases, the cost of maintaining a global reader counter becomes significant.
Linux RCU Philosophy¶
Linux RCU does not ask:
Instead it asks:
This is a fundamentally different way of thinking.
Quiescent State¶
Definition¶
A quiescent state (QS) is a point where a CPU can no longer hold a reader that existed before the current grace period.
Conceptually:
Common Misconceptions¶
A quiescent state does not mean:
A CPU may remain busy while still passing through a quiescent state.
Practical Interpretation¶
A quiescent state means:
Once a CPU reaches this point, it becomes safe for the current grace period.
Reader Counting vs Progress Tracking¶
Reader Counting¶
Educational Mini RCU:
Progress Tracking¶
Linux RCU:
This removes the need for a globally shared reader counter.
Per-CPU State¶
Instead of maintaining:
Linux maintains per-CPU information.
Conceptually:
Each CPU tracks its own progress.
This avoids constant modification of a shared global variable.
Grace Period Detection¶
When a grace period begins:
Linux records which CPUs must be observed.
Conceptually:
As CPUs report quiescent states:
The grace period completes.
Why Snapshot Matters¶
Linux only waits for CPUs that existed at the beginning of the grace period.
Conceptually:
New CPUs appearing later are not part of the current grace period.
This prevents grace periods from growing indefinitely.
Tree RCU Motivation¶
A small system may contain:
Tracking each CPU individually is simple.
Modern systems may contain:
Scanning every CPU becomes increasingly expensive.
Tree Aggregation¶
Linux organizes CPU state hierarchically.
Conceptually:
Aggregated Reporting¶
Instead of reporting every CPU to the root:
Each group reports:
The root only tracks group status.
Benefits¶
Tree aggregation provides:
- Better scalability
- Reduced tracking overhead
- Efficient grace period detection
- Support for very large CPU counts
Relationship to RCU APIs¶
The internal implementation is largely hidden from users.
Typical driver code still uses:
rcu_read_lock();
...
rcu_read_unlock();
obj = rcu_dereference(ptr);
rcu_assign_pointer(ptr, new_obj);
synchronize_rcu();
call_rcu(...);
Most kernel developers use the RCU APIs without needing to understand the full Tree RCU implementation.
Summary¶
Educational Mini RCU:
Linux RCU:
The most important conceptual transition is:
This design allows Linux RCU to scale efficiently on systems with large numbers of CPUs.