TL;DR
Restartable sequences (rseq) are a Linux feature allowing thread-safe, lockless data structures that scale efficiently on many-core processors. Currently used in some libraries, rseq promises to revolutionize system programming as support expands across operating systems.
Restartable sequences (rseq), a Linux feature introduced around 2018, enable lockless, thread-safe data structures that scale efficiently on many-core processors. This technology is currently limited to Linux with handwritten assembly but is poised to influence system programming broadly as support expands.
The concept of restartable sequences allows threads to execute small, restartable sections of code atomically, even during preemption or migration across CPUs. When a thread is scheduled on a different core, the kernel can force it to restart the critical section based on a specified assembly sequence, reducing the need for locks or atomic operations.
Currently, only a handful of libraries such as tcmalloc, jemalloc, glibc, and cosmopolitan utilize rseq. Its application has shown significant performance gains; for example, on a Raspberry Pi 5 with four cores, rseq improved malloc() performance threefold. On high-end systems, like a 128-core System76 Thelio Astra, rseq yielded a 34-fold speedup in malloc(), and on a 96-core AMD Threadripper, a 43-fold increase was observed.
Implementing rseq involves issuing an rseq() system call to allocate thread-local storage (TLS) and setting up assembly sequences that the kernel can invoke during thread preemption. This allows for lockless data structure modifications, such as push and pop operations on concurrent lists, with minimal overhead.
Why It Matters
This development is significant because it addresses the bottleneck of lock contention in multi-core systems, enabling scalable, high-performance data structures. As microprocessors with dozens or hundreds of cores become commonplace, rseq offers a way to harness their full potential, especially for system-level and high-performance computing tasks.
Adoption of rseq could lead to widespread performance improvements in operating system kernels, runtime libraries, and application software, fundamentally changing how concurrent programming is approached in the era of many-core processors.
Linux lockless data structure libraries
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Background
Since its introduction in Linux 4.18, rseq has remained a niche feature primarily used in specialized libraries. The growing prevalence of multi-core CPUs, especially with 128 or more cores, has increased interest in such lockless techniques. The concept builds on earlier ideas of optimistic concurrency and lock-free algorithms, but with kernel-assisted restartability for preempted threads.
Historically, synchronization in multi-core systems relied heavily on mutexes and atomic operations, which can cause contention and degrade performance. Rseq offers an alternative by allowing small, atomic, restartable code sections, promising better scalability as core counts increase.
“Restartable sequences are a game-changer for high-core-count systems, enabling performance gains that were previously impossible with traditional locking.”
— Justine, system programmer
“On my 128-core system, rseq made malloc 34 times faster, which is a breakthrough for scalable memory management.”
— Developer using rseq libraries
high-performance malloc for multi-core systems
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
What Remains Unclear
While initial results are promising, widespread OS support and language integration are still in development. It remains unclear how quickly mainstream Linux distributions and other operating systems will adopt rseq support, and how easily developers can incorporate it into existing codebases. Additionally, the full range of use cases and potential limitations are still being explored.
thread-safe memory management tools
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
What’s Next
Next steps include broader adoption in Linux kernels, integration into system programming languages, and the development of comprehensive libraries that leverage rseq. Developers are encouraged to experiment with rseq in their projects to prepare for future support and to contribute to standardization efforts.
restartable sequences programming kit
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Key Questions
What is restartable sequences (rseq)?
Rseq is a Linux feature that allows small sections of code to execute atomically, even during thread preemption, enabling lockless data structures that scale well on many-core processors.
Why is rseq important for modern computing?
As CPUs with dozens or hundreds of cores become common, traditional locking mechanisms cause bottlenecks. Rseq provides a way to perform concurrent operations efficiently without locks, improving performance significantly.
Is rseq supported outside Linux?
Currently, rseq support is limited to Linux with handwritten assembly. Broader support across operating systems and languages is expected in the future as the concept gains traction.
How can developers start using rseq?
Developers can experiment with rseq by writing assembly sequences and integrating them into their code, but widespread use will likely require support from libraries and compilers in the coming years.
Source: Hacker News