Noureddine RAMDI / Kovan: wait-free memory reclamation for Rust concurrency with 128-bit atomics

Created Mon, 04 May 2026 10:23:02 +0000 Modified Sat, 23 May 2026 20:41:27 +0000

vertexclique/kovan

Kovan tackles a core challenge in concurrent programming: knowing when it’s safe to free memory without stalling other threads. It implements a wait-free memory reclamation scheme tailored for Rust, leveraging cutting-edge atomic primitives to minimize overhead and avoid unbounded memory growth common in traditional epoch-based reclamation.

What kovan does and how it works under the hood

Kovan is a Rust library designed for wait-free memory reclamation in lock-free concurrent data structures. Its primary problem domain is safe memory management when multiple threads access and modify shared data without locks. Specifically, it answers the question: when can a thread safely free memory previously used by another thread without risking use-after-free bugs?

The library uses an epoch-based reclamation strategy with a twist: it requires 128-bit atomic operations to provide true wait-free guarantees on architectures that support them (x86_64 with cmpxchg16b, aarch64, s390, riscv64gc). These atomics allow Kovan to efficiently coordinate memory reclamation without global locks or unbounded delay.

The core API revolves around three operations: pin, load, and retire. Threads “pin” themselves to an epoch to indicate active access, “load” references safely under this protection, and “retire” nodes when they are logically removed but must be deferred before actual reclamation.

Kovan offers a high-level Atom API that automatically handles these semantics for users and lower-level primitives for fine-grained control. This design enables adoption in a range of concurrent data structures, from stacks and queues to maps and transactional memory.

The library is implemented in safe Rust where possible, with minimal unsafe code tightly scoped to atomic operations. Its architecture relies on the underlying hardware support for 128-bit atomics to achieve a low pin overhead of 2.79 nanoseconds, which benchmarks show is significantly better than other popular libraries like crossbeam-epoch (13.66 ns), seize (9.70 ns), and haphazard (18.09 ns).

Why kovan stands out: performance and wait-free guarantees

What distinguishes Kovan is its use of 128-bit atomics to implement wait-free epoch-based reclamation with bounded memory usage. Most epoch-based schemes suffer from unbounded memory retention or blocking behavior under contention or thread preemption. Kovan’s approach sidesteps this by splitting a 128-bit word into parts that track epochs and deferred nodes, enabling progress guarantees without delays.

This “WORD-split” technique under the hood is clever: it encodes both the active epoch and a pointer to retired nodes compactly, allowing threads to quickly determine when it’s safe to reclaim memory. This reduces synchronization overhead and contention hotspots.

Benchmarks included in the repository show concrete performance benefits. For example, in a Treiber stack benchmark with one thread, Kovan achieves 541 microseconds for 18.5 million operations, scaling reasonably to 8 threads. In read-heavy workloads, it outperforms crossbeam-epoch and others significantly in throughput and latency.

The codebase is surprisingly clean for such a low-level concurrency library. The authors clearly separate safe and unsafe abstractions, document the tricky memory ordering constraints, and provide modular components for reuse. This makes it easier to audit and reason about correctness—a crucial factor in concurrency primitives.

The tradeoff is that Kovan requires hardware support for 128-bit atomics, which limits portability to specific architectures. If your target platform doesn’t support this, you lose the wait-free guarantees and might need to fall back to alternatives. Also, this library targets advanced users building custom concurrent data structures rather than everyday application developers.

Quick start with kovan

Adding Kovan to your Rust project is straightforward. The library is available on crates.io, and you can add it as a dependency in your Cargo.toml:

[dependencies]
kovan = "0.1"

This minimal setup gives you access to the core reclamation primitives. From there, you can explore the high-level Atom API or dig into the lower-level primitives for more control.

The documentation and examples in the repository provide guidance on how to use pin, load, and retire safely. Given the complexity of concurrent memory reclamation, expect a learning curve if you haven’t worked with epoch-based or hazard-pointer schemes before.

Verdict: who should consider kovan?

Kovan is a solid choice if you are implementing high-performance lock-free data structures in Rust and require wait-free memory reclamation with minimal overhead. Its use of 128-bit atomics delivers measurable latency improvements over established libraries like crossbeam-epoch.

However, the hardware requirements and API complexity make it more suitable for systems programmers and library authors than typical application developers. If your project targets diverse architectures or you want a more battle-tested, widely used solution, you might prefer more portable reclamation crates.

For those who need every nanosecond of concurrency overhead squeezed out and run on supported hardware, Kovan is worth a close look. Its code quality and clear documentation also make it a valuable resource to understand modern epoch-based reclamation techniques in Rust.

Overall, Kovan exemplifies a focused systems library that solves a fundamental concurrency problem with precision and performance, trading off portability for speed and wait-free guarantees.


→ GitHub Repo: vertexclique/kovan ⭐ 111 · Rust