19 releases

new 0.4.8 Nov 27, 2024
0.4.5 Jul 18, 2024
0.3.1 Mar 12, 2024
0.2.5 Jul 20, 2022
0.0.0 Sep 27, 2021

#75 in Concurrency

Download history 7027/week @ 2024-08-07 7524/week @ 2024-08-14 6370/week @ 2024-08-21 6263/week @ 2024-08-28 7326/week @ 2024-09-04 6415/week @ 2024-09-11 6204/week @ 2024-09-18 7804/week @ 2024-09-25 8498/week @ 2024-10-02 7341/week @ 2024-10-09 8047/week @ 2024-10-16 9295/week @ 2024-10-23 11096/week @ 2024-10-30 12406/week @ 2024-11-06 12849/week @ 2024-11-13 11891/week @ 2024-11-20

49,876 downloads per month
Used in 41 crates (6 directly)

MIT license

110KB
1.5K SLoC

seize

crates.io github docs.rs

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 reduced when only a fraction of threads are writing, degrading memory efficiency.

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 already retired objects, allowing it to avoid the high overhead incurred by traditional reference counting schemes where every memory access requires modifying shared memory. Reclamation is naturally balanced as the thread with the last reference to an object is the one that frees it. This removes the need to check whether other threads have made progress, leading to predictable latency without sacrificing performance. Epochs can also be tracked to protect against stalled threads, making reclamation truly lock-free.

Seize provides performance competitive with that of epoch based schemes, while memory efficiency is similar to that of hazard pointers. Seize is compatible with all modern hardware that supports single-word atomic operations such as FAA and CAS.

Dependencies

~0–7.5MB
~57K SLoC