snmalloc-rs
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 theDebug
mode insnmalloc
.1mib
: Use the1mib
chunk configuration. From0.2.17
, this is set as a default feature16mib
: Use the16mib
chunk configuration.cache-friendly
: Make the allocator more cache friendly (settingCACHE_FRIENDLY_OFFSET
to64
in building the library).native-cpu
: Optimizesnmalloc
for the native CPU of the host machine. (this is not a default behavior since0.2.14
)qemu
: workaroundmadvise
problem of QEMU environmentstats
: enable statistics
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
[]
= "0.2"
To set SnMalloc
as the global allocator add this to your project:
static ALLOC: SnMalloc = SnMalloc;
For MinGW Users
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
:
winpthread
atomic
stdc++
gcc_s
Notice: since version 0.2.12
, we no longer require you to provide additional environment variables for mingw
target.
For Android Cross-Compilation
ANDROID_NDK
must be provided as an environment variableANDROID_PLATFORM
can be passed as an optional environment variableANDROID_ABI
used by CMake is detected automatically- feature
android-lld
can be used to set the linker ofsnmalloc
tolld
- feature
android-shared-std
can be used to set the STL library ofsnmalloc
toc++_shared
(it usesc++_static
by default)
Changelog
0.2.21
- upstream bug fix for using failing to initialise meta-data
0.2.20
- upstream pass through Haiku build fix.
- upstream fix typo in macro definition for 16MiB shared library shim.
- upstream DragonFly support (userland).
- upstream natural alignment for USE_MALLOC
- upstream fix bug in pagemap when index has many level
- upstream add constexpr annotation to align_up/down.
0.2.19
- upstream stats
- upstream PAL updates and concepts
- upstream ddd constexpr annotation to align_up/down
- change macOS CI to follow xcode 12
for older versions, see CHANGELOG