snmalloc is a high-performance allocator.
snmalloc can be used directly in a project as a header-only C++ library,
it can be LD_PRELOAD
ed on Elf platforms (e.g. Linux, BSD),
and there is a crate to use it from Rust.
Its key design features are:
- Memory that is freed by the same thread that allocated it does not require any
synchronising operations. - Freeing memory in a different thread to initially allocated it, does not take
any locks and instead uses a novel message passing scheme to return the
memory to the original allocator, where it is recycled. This enables 1000s of remote
deallocations to be performed with only a single atomic operation enabling great
scaling with core count. - The allocator uses large ranges of pages to reduce the amount of meta-data
required. - The fast paths are highly optimised with just two branches on the fast path
for malloc (On Linux compiled with Clang). - The platform dependencies are abstracted away to enable porting to other platforms.
snmalloc’s design is particular well suited to the following two difficult
scenarios that can be problematic for other allocators:
- Allocations on one thread are freed by a differen