Linux restartable sequences (rseq) let a thread make certain short, per-CPU updates without putting a heavyweight atomic operation, lock, or syscall on the fast path. If preemption, migration, or signal delivery interrupts the critical sequence, the kernel redirects execution to an abort handler so the operation can safely retry. That makes rseq useful for carefully bounded operations in allocators, counters, queues, and other core-library data structures—not a general replacement for synchronization.
How rseq works
Rseq gives each participating thread a userspace area shared with the kernel. It can expose the thread’s current CPU and NUMA-node identifiers, support restartable sequences, and—in optimized V2 mode—enable an optional scheduler time-slice extension.
A restartable sequence is a short instruction sequence that operates on per-CPU data. Its descriptor identifies the critical section’s start, abort, and post-commit locations. Code checks that it is still on the CPU whose data it intends to update, then performs the bounded update. If an event makes continuing unsafe, the kernel redirects control to the abort handler rather than letting the interrupted path proceed as though the operation had completed.
This is a limited form of atomicity with respect to scheduler preemption and signal delivery. It does not make arbitrary code transactional, protect unrelated shared data, or allow a critical section to block. The operation and its recovery path must be designed together.
#1 Best Overall
Where core libraries can benefit
The strongest use case is reducing synchronization overhead for short operations on per-CPU state. A library can use the thread’s CPU identifier to select that CPU’s own data and update it without making every thread contend on a shared cache line.
- Allocators: Maintain per-CPU freelists or caches, provided an interrupted operation can be abandoned and retried safely.
- Counters: Increment per-CPU counters and aggregate them later, instead of making each thread update one globally contended counter.
- Queues and similar structures: Handle bounded, nonblocking per-CPU operations when the data structure has a correct abort-and-retry design.
The benefit depends on the workload. Rseq can reduce fast-path synchronization costs, but frequent aborts, expensive retries, thread churn, or contention elsewhere may erase the gain. There is no universal speedup figure: the kernel documentation’s 5-microsecond time-slice extension default is a configuration detail, not a performance benchmark.
Rank #2
Rseq versus locks, atomics, futexes, and syscalls
These mechanisms solve overlapping but different problems. Choose according to the operation’s shape, progress requirements, and acceptable recovery behavior.
| Approach | Fast-path behavior | Interruption and contention | Fit and trade-off |
|---|---|---|---|
| Rseq | A short sequence can update the current CPU’s data without a heavyweight atomic operation on the normal path. | Unsafe interruption redirects to an abort path; retries can add cost and affect tail latency. | Best suited to bounded, restartable per-CPU operations. Requires ABI-aware integration and a fallback. |
| C11 atomics | Performs an atomic operation, whose cost depends on the operation and hardware. | Can create cache-line contention when many threads update the same location; does not use rseq’s abort-and-retry model. | Useful when the shared operation is naturally atomic or needs to work without rseq registration. |
| Locks | Requires lock acquisition and release, even when uncontended. | Coordinates access to shared state; contending threads may wait, and the protected region must follow the lock’s rules. | Appropriate for broader critical sections or code that cannot safely retry, but can serialize access. |
| Futexes | Typically support a userspace fast path with kernel involvement when threads must wait or be woken. | Designed for blocking and wake-up coordination rather than restarting an interrupted per-CPU update. | Useful when waiting is part of the required behavior; not a substitute for a short rseq critical section. |
| Syscall-based design | Enters the kernel for the operation or coordination. | Does not rely on a userspace sequence being safely restartable, but incurs a kernel transition. | Can be suitable where kernel-mediated behavior is necessary or a userspace fallback cannot safely implement the operation. |
Rseq is not automatically better than an atomic or lock. If the state is genuinely shared, the sequence is long, or correctness depends on completing an operation without retry, use a synchronization design that directly provides those semantics.
What happens if a thread is preempted, migrated, or interrupted by a signal?
Preemption can leave a thread off the CPU associated with the per-CPU data it selected. Migration creates the same concern: continuing the original sequence on a different CPU could update the wrong CPU’s state. Signal delivery can also interrupt execution within the sequence. Rseq is designed to handle these events by redirecting the thread to the descriptor’s abort location when the critical section cannot safely continue.
The abort path must restore a valid state and retry or otherwise recover without exposing a partial update. Read and validate CPU identity before accessing per-CPU data, and make the update restart-safe. A design that cannot tolerate an abandoned attempt is not a suitable rseq operation.
Rank #4
How libraries should share rseq safely
There can be only one rseq ABI registration per thread, so independent libraries must not assume they can each register their own area. The rseq(2) proposal says glibc has handled allocation and registration since glibc 2.35. A library should use the C library’s provided state when available, detect when registration is unsupported, and retain a correct alternative path for environments where rseq cannot be used.
Descriptor lifetime matters as well. The GNU C Library manual recommends that a library that may free or reuse memory used for a critical-section descriptor set the thread’s rseq_cs field to NULL before returning from the library function that used rseq. Otherwise, the kernel could later observe a stale pointer to storage that is no longer valid.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteBest Value
Legacy registration and optimized V2
Current kernel documentation distinguishes legacy behavior from optimized V2. The modes differ in how identifiers and critical sections are handled, and V2 adds protections that library code must respect.
| Mode | Kernel behavior | What library maintainers should account for |
|---|---|---|
| Legacy | Unconditionally updates identifiers and checks critical sections to preserve behavior expected by older binaries registering the original 32-byte area. | Do not assume optimized V2 behavior when supporting older registrations or environments. |
| Optimized V2 | Updates identifiers only when they change, checks critical sections conditionally, enforces read-only fields, and enables scheduler time-slice extensions. | Treat kernel-maintained read-only fields as immutable. Modifying protected fields in compliant V2 use can terminate the process. |
Optimized V2 also supports an optional scheduler time-slice extension. A thread with an optimized-V2 registration can request it, if the kernel feature is available, with:
prctl(PR_RSEQ_SLICE_EXTENSION, PR_RSEQ_SLICE_EXTENSION_SET, PR_RSEQ_SLICE_EXT_ENABLE, 0, 0)
The kernel documentation gives a default extension of 5 microseconds and notes that increasing it can affect minimum scheduling latency. This is a kernel configuration detail, not a universal scheduling guarantee or a reason by itself to enable the feature.
Implementation checklist
- Define a bounded operation that can be safely abandoned and retried; avoid blocking inside the critical section.
- Provide a descriptor with explicit start, abort, and post-commit locations. Keep the abort target outside the critical region.
- Read and validate the CPU identity before touching that CPU’s data. Ensure migration or interruption leads to retry rather than an update to the wrong per-CPU structure.
- Use the C-library-provided thread state when available; do not assume a private per-thread registration is available to every library.
- Before freeing or reusing descriptor storage, clear the thread’s
rseq_csfield toNULL. - In optimized V2 mode, do not modify kernel-maintained read-only fields.
- Provide a correct lock, atomic, or syscall-based fallback for unsupported kernels, older libc versions, unusual architectures, or workloads with excessive aborts.
- Benchmark the actual workload, including abort frequency, tail latency, thread churn, and behavior across supported architectures. Do not infer a win from the fast path alone.
When to choose rseq
Choose rseq when an operation is short, per-CPU, nonblocking, and safe to retry, and when avoiding shared-state contention matters in the target workload. Prefer atomics for naturally atomic shared updates, locks for critical sections that cannot be restarted safely, and futexes or syscall-based coordination when threads need to wait or kernel-mediated behavior is essential. Keep a fallback: rseq’s ABI, libc integration, architecture support, and abort rate are all part of the engineering decision.
Free tools Windows power users keep installed
One-click scans. No signup required.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




