October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How Linux Restartable Sequences Improve User-Space Core Libraries

Linux rseq can reduce synchronization costs for short per-CPU updates. Here’s how abort-and-retry works, how it compares with atomics and locks, and what library maintainers must do for safe ABI sharing.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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

  1. Define a bounded operation that can be safely abandoned and retried; avoid blocking inside the critical section.
  2. Provide a descriptor with explicit start, abort, and post-commit locations. Keep the abort target outside the critical region.
  3. 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.
  4. Use the C-library-provided thread state when available; do not assume a private per-thread registration is available to every library.
  5. Before freeing or reusing descriptor storage, clear the thread’s rseq_cs field to NULL.
  6. In optimized V2 mode, do not modify kernel-maintained read-only fields.
  7. Provide a correct lock, atomic, or syscall-based fallback for unsupported kernels, older libc versions, unusual architectures, or workloads with excessive aborts.
  8. 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.