Kernel synchronization and RCU
Quick answer
Concurrent kernel tasks can access shared data. Locks and read-copy-update (RCU) solve different synchronization and lifetime problems.
In an RCU lifetime example, unlinking an object and freeing its storage are separate actions. The updater waits for the relevant pre-existing readers before reclaiming the object; other synchronization may still be necessary for writers. Do not treat RCU as a universal lock replacement.
Prepare the practice environment
Run python3 lab-fixtures/kernel/setup.py from the extracted root as an ordinary user. Enter the printed fresh private path and check pwd. Use fresh fixtures, Bash with set -e -o pipefail, LC_ALL=C and umask 077. Run each snippet in a separate Bash process, not your interactive shell. Only private files are used; optional examples require an authorized snapshot VM. Do not write kernel attributes, load modules, or change boot settings. Supplied records are fictional; read only the selected non-sensitive live fields. Review the lab guide.
Prerequisites
Review: VFS and block I/O.
How it works
A mutex permits a contender to sleep in appropriate task context; a spinlock conventionally waits without sleeping, subject to kernel configuration such as PREEMPT_RT. Atomic operations are not a general substitute for synchronization of complex invariants. RCU separates removal from reclamation: publish a new version, stop exposing the old object to new readers, then wait for a grace period before freeing it. Pre-existing RCU readers may still hold the old object. Updaters still need appropriate coordination, publication primitives and lifetime rules; RCU does not make arbitrary concurrent writes safe. The model uses discrete events and no kernel primitives.
Try the examples
Two fictional writers read zero before writing; serialized operations preserve both increments.
Expected stdout:
uncoordinated=1 serialized=2The old object remains until the modeled pre-existing reader exits.
Expected stdout:
old reader active: retainold reader finished: reclaim eligibleThe synthetic state machine refuses to reclaim while a pre-existing reader remains.
Expected stdout:
premature reclamation rejectedCommon mistakes
RCU is not a mutex or a garbage collector for arbitrary references. Never infer real grace-period timing from this model.
Practice
Write an event timeline with two readers and one updater; identify the earliest safe reclamation event under the modeled rules.
Related references
Study: perf. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Kernel synchronization and RCU — Knowledge Check
Apply kernel concepts to read-only observations and synthetic models.
What must finish before reclaiming an RCU-retired object?
Does RCU alone serialize writers?
Why can two increments yield one?
Can a mutex waiter sleep in appropriate task context?