Notice: MinGW Build is broken and may not be fixed in a near future. See this PR in the upstream.
snmalloc-rs provides a wrapper for microsoft/snmalloc to make it usable as
a global allocator for rust. snmalloc is a research allocator. 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.
- The allocator uses large ranges of pages to reduce the amount of meta-data required.
Some old benchmark results are available in
the snmalloc paper. Some recent benchmark results
are listed at
bench_suite. There are three features defined in this crate:
debug: Enable theDebugmode insnmalloc.(removed since 0.3.0)1mib: Use the1mibchunk configuration. From0.2.17, this is set as a default feature(removed since 0.3.0)16mib: Use the16mibchunk configuration.(removed since 0.3.0)cache-friendly: Make the allocator more cache friendly (settingCACHE_FRIENDLY_OFFSETto64in building the library).native-cpu: Optimizesnmallocfor the native CPU of the host machine. (this is not a default behavior since0.2.14)qemu: Workaroundmadviseproblem of QEMU environment(removed since 0.3.0)stats: Enable statisticslocal_dynamic_tls: Workaround cannot allocate memory in static tls blockbuild_cc: Use of cc crate instead of cmake (cmake still default) as builder (more platform agnostic)(removed since 0.3.0)usecxx20: Enable C++20 standard if availableusecxx17: Use C++17 standardcheck: Enable extra checks to improve security, see upstream security docs. Note that thememcpyprotection is not enabled in Rust.win8compat: Improve compatibility for old Windows platforms (removing usages ofVirtualAlloc2and other new APIs)lto: Links with InterProceduralOptimization/LinkTimeOptimizationnotls: Enables to be loaded dynamically, thus disable tls.stats: Enables allocation statistics.libc-api: Enables libc API backed by snmalloc.
To get the crates compiled, you need to choose either 1mib or 16mib to determine the chunk configuration
To use snmalloc-rs add it as a dependency:
# Cargo.toml
[dependencies]
snmalloc-rs = "0.3.8"To set SnMalloc as the global allocator add this to your project:
#[global_allocator]
static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;mingw version is only tested on nightly branch with MSYS environment. We are using dynamic linking method. Hence,
please make sure the following libs are in your PATH:
winpthreadatomicstdc++gcc_s
Notice: since version 0.2.12, we no longer require you to provide additional environment variables for mingw
target.
ANDROID_NDKmust be provided as an environment variableANDROID_PLATFORMcan be passed as an optional environment variableANDROID_ABIused by CMake is detected automatically- feature
android-lldcan be used to set the linker ofsnmalloctolld feature(android-shared-stdcan be used to set the STL library ofsnmalloctoc++_shared(it usesc++_staticby default)libstdc++is no longer a dependency)
- Tracking upstream to match version 0.7.1
- Recommended to upgrade from 0.3.7 to get an important bug fix.
- Tracking upstream to match version 0.7
- Tracking upstream to version 0.6.2.
- Tracking upstream to fix Linux PAL typo.
- Tracking upstream to enable old Linux variants.
- Fixes
build_ccfeature (broken in 0.3.0 release). - Fixes
native-cpufeature (broken in 0.3.0 release).
- Release to support snmalloc 0.6.0.
- Beta release to support snmalloc
20.6.0