13 unstable releases (4 breaking)

new 0.4.0 Apr 17, 2024
0.3.1 Mar 12, 2024
0.2.5 Jul 20, 2022
0.2.2 Mar 30, 2022
0.0.0 Sep 27, 2021

#131 in Concurrency

Download history 403/week @ 2023-12-23 1339/week @ 2023-12-30 1985/week @ 2024-01-06 1858/week @ 2024-01-13 2628/week @ 2024-01-20 3605/week @ 2024-01-27 3935/week @ 2024-02-03 4094/week @ 2024-02-10 2845/week @ 2024-02-17 4347/week @ 2024-02-24 4827/week @ 2024-03-02 5357/week @ 2024-03-09 5065/week @ 2024-03-16 5944/week @ 2024-03-23 5206/week @ 2024-03-30 4393/week @ 2024-04-06

21,533 downloads per month
Used in 15 crates (4 directly)

MIT license

73KB
1K SLoC

Seize

Crate Github Docs

Fast, efficient, and robust memory reclamation for concurrent data structures.

See the quick-start guide to get started.

Background

Concurrent data structures are faced with the problem of deciding when it is safe to free memory. Although an object might have been logically removed, other threads that previously loaded it may still be accessing it, and thus it is not safe to free immediately. Over the years, many algorithms have been devised to solve this problem. However, most traditional memory reclamation schemes make the tradeoff between performance, efficiency, and robustness. For example, epoch based reclamation is fast and lightweight but lacks robustness in that a stalled thread can prevent the reclamation of all retired objects. Hazard pointers, another popular scheme, tracks individual pointers, making it efficient and robust but generally much slower.

Another problem that is often not considered is workload balancing. In most reclamation schemes, the thread that retires an object is the one that reclaims it. This leads to unbalanced reclamation in read-dominated workloads; parallelism is degraded when only a fraction of threads are writing. This is especially prevalent with the use of M:N threading models as provided by asynchronous runtimes like Tokio.

Implementation

Seize is based on the hyaline reclamation scheme, which uses reference counting to determine when it is safe to free memory. However, reference counters are only used for objects that have been retired, allowing it to avoid the high overhead incurred by traditional reference counting schemes where every memory access requires modifying shared memory. Performance is competitive with that of epoch based schemes, while memory efficiency is similar to hazard pointers. Reclamation is naturally balanced as the thread with the last reference to an object is the one that frees it. Epochs can also be optionally tracked to protect against stalled threads, making reclamation truly lock-free.

Seize is compatible with all modern hardware that supports single-word atomic operations such as FAA and CAS.

No runtime deps