Akilan 22d9b65b4b
Some checks failed
snmalloc Benchmarking CI / benchmark (push) Has been cancelled
snmalloc CI / Ubuntu - ubuntu-22.04 Debug (push) Has been cancelled
snmalloc CI / Ubuntu - ubuntu-24.04 Debug (push) Has been cancelled
snmalloc CI / Ubuntu - ubuntu-24.04-arm Debug (push) Has been cancelled
snmalloc CI / Ubuntu - ubuntu-22.04 Debug C++17 (push) Has been cancelled
snmalloc CI / Ubuntu - ubuntu-24.04 Debug with pthread destructors (push) Has been cancelled
snmalloc CI / Ubuntu - ubuntu-22.04 Release (push) Has been cancelled
snmalloc CI / Ubuntu - ubuntu-24.04 Release (push) Has been cancelled
snmalloc CI / Ubuntu - ubuntu-24.04-arm Release (push) Has been cancelled
snmalloc CI / Ubuntu - ubuntu-24.04 Release individual mitigations (push) Has been cancelled
snmalloc CI / Ubuntu - ubuntu-24.04 Release libstdc++ (Build only) (push) Has been cancelled
snmalloc CI / Ubuntu - ubuntu-22.04 Release clang + libstdc++ (Build only) (push) Has been cancelled
snmalloc CI / Ubuntu - ubuntu-22.04 Release Traced Build (push) Has been cancelled
snmalloc CI / Bazel - macos-13 Debug (push) Has been cancelled
snmalloc CI / Bazel - macos-14 Debug (push) Has been cancelled
snmalloc CI / Bazel - macos-15 Debug (push) Has been cancelled
snmalloc CI / Bazel - ubuntu-22.04 Debug (push) Has been cancelled
snmalloc CI / Bazel - ubuntu-24.04 Debug (push) Has been cancelled
snmalloc CI / Bazel - macos-13 Release (push) Has been cancelled
snmalloc CI / Bazel - macos-14 Release (push) Has been cancelled
snmalloc CI / Bazel - macos-15 Release (push) Has been cancelled
snmalloc CI / Bazel - ubuntu-22.04 Release (push) Has been cancelled
snmalloc CI / Bazel - ubuntu-24.04 Release (push) Has been cancelled
snmalloc CI / Mac OS macos-13 Debug (push) Has been cancelled
snmalloc CI / Mac OS macos-14 Debug (push) Has been cancelled
snmalloc CI / Mac OS macos-15 Debug (push) Has been cancelled
snmalloc CI / Mac OS macos-13 Debug -DSNMALLOC_USE_CXX17=ON (push) Has been cancelled
snmalloc CI / Mac OS macos-14 Debug -DSNMALLOC_USE_CXX17=ON (push) Has been cancelled
snmalloc CI / Mac OS macos-15 Debug -DSNMALLOC_USE_CXX17=ON (push) Has been cancelled
snmalloc CI / Mac OS macos-13 Release (push) Has been cancelled
snmalloc CI / Mac OS macos-14 Release (push) Has been cancelled
snmalloc CI / Mac OS macos-15 Release (push) Has been cancelled
snmalloc CI / Mac OS macos-13 Release -DSNMALLOC_USE_CXX17=ON (push) Has been cancelled
snmalloc CI / Mac OS macos-14 Release -DSNMALLOC_USE_CXX17=ON (push) Has been cancelled
snmalloc CI / Mac OS macos-15 Release -DSNMALLOC_USE_CXX17=ON (push) Has been cancelled
snmalloc CI / FreeBSD-13.2 Debug (push) Has been cancelled
snmalloc CI / FreeBSD-13.2 Release (push) Has been cancelled
snmalloc CI / NetBSD-9.2 Release (push) Has been cancelled
snmalloc CI / Sanitizer - ubuntu-22.04 Release libc++ (TSan + UBSan) (push) Has been cancelled
snmalloc CI / Sanitizer - ubuntu-24.04 Release libc++ (TSan + UBSan) (push) Has been cancelled
snmalloc CI / Crossbuild - Debug cross-build for riscv64-linux-gnu (push) Has been cancelled
snmalloc CI / Crossbuild - Release cross-build for riscv64-linux-gnu (push) Has been cancelled
snmalloc CI / Crossbuild - Debug cross-build for aarch64-linux-gnu (push) Has been cancelled
snmalloc CI / Crossbuild - Release cross-build for aarch64-linux-gnu (push) Has been cancelled
snmalloc CI / Crossbuild - Debug cross-build for arm-linux-gnueabihf (push) Has been cancelled
snmalloc CI / Crossbuild - Release cross-build for arm-linux-gnueabihf (push) Has been cancelled
snmalloc CI / Windows - windows-2022 ARM64 Debug (push) Has been cancelled
snmalloc CI / Windows - windows-2022 ARM64 Release (push) Has been cancelled
snmalloc CI / Windows - windows-2022 ARM64EC Debug (push) Has been cancelled
snmalloc CI / Windows - windows-2022 ARM64EC Release (push) Has been cancelled
snmalloc CI / Windows - windows-2022 Win32 Debug (push) Has been cancelled
snmalloc CI / Windows - windows-2022 Win32 Debug -T ClangCL (push) Has been cancelled
snmalloc CI / Windows - windows-2025 Win32 Debug (push) Has been cancelled
snmalloc CI / Windows - windows-2025 Win32 Debug -T ClangCL (push) Has been cancelled
snmalloc CI / Windows - windows-2022 Win32 Release (push) Has been cancelled
snmalloc CI / Windows - windows-2022 Win32 Release -T ClangCL (push) Has been cancelled
snmalloc CI / Windows - windows-2025 Win32 Release (push) Has been cancelled
snmalloc CI / Windows - windows-2025 Win32 Release -T ClangCL (push) Has been cancelled
snmalloc CI / Windows - windows-2022 x64 Debug (push) Has been cancelled
snmalloc CI / Windows - windows-2022 x64 Debug -T ClangCL (push) Has been cancelled
snmalloc CI / Windows - windows-2025 x64 Debug (push) Has been cancelled
snmalloc CI / Windows - windows-2025 x64 Debug -T ClangCL (push) Has been cancelled
snmalloc CI / Windows - windows-2022 x64 Release (push) Has been cancelled
snmalloc CI / Windows - windows-2022 x64 Release -T ClangCL (push) Has been cancelled
snmalloc CI / Windows - windows-2025 x64 Release (push) Has been cancelled
snmalloc CI / Windows - windows-2025 x64 Release -T ClangCL (push) Has been cancelled
snmalloc CI / Windows - windows-2022 x64 Release Windows 8 compatible (push) Has been cancelled
snmalloc CI / Format check (push) Has been cancelled
snmalloc CI / Fuzzing (push) Has been cancelled
snmalloc CI / Self Vendored STL - macos-latest clang++ (push) Has been cancelled
snmalloc CI / Self Vendored STL - ubuntu-24.04 clang++-18 (push) Has been cancelled
snmalloc CI / Self Vendored STL - windows-2022 clang-cl (push) Has been cancelled
snmalloc CI / Self Vendored STL - ubuntu-24.04 g++-14 (push) Has been cancelled
snmalloc CI / gwp-asan (ubuntu-24.04, Debug) (push) Has been cancelled
snmalloc CI / gwp-asan (ubuntu-24.04, RelWithDebInfo) (push) Has been cancelled
snmalloc CI / gwp-asan (ubuntu-24.04-arm, Debug) (push) Has been cancelled
snmalloc CI / gwp-asan (ubuntu-24.04-arm, RelWithDebInfo) (push) Has been cancelled
snmalloc CI for Morello / morello Debug Hybrid (push) Has been cancelled
snmalloc CI for Morello / morello Debug Purecap (push) Has been cancelled
snmalloc CI for Morello / morello Release Hybrid (push) Has been cancelled
snmalloc CI for Morello / morello Release Purecap (push) Has been cancelled
snmalloc CI / all-checks (push) Has been cancelled
added morello build instruction
2025-11-26 12:23:41 +00:00
2025-07-09 07:37:58 +00:00
2025-11-26 12:11:14 +00:00
2025-05-07 09:09:44 +01:00
2019-04-30 09:46:10 +01:00
2025-01-23 13:36:08 +00:00
2025-05-07 09:09:44 +01:00
2019-01-09 06:05:57 -08:00
2025-11-26 12:23:41 +00:00
2020-02-28 09:03:41 +00:00
2019-05-23 15:13:47 +01:00

snmalloc

snmalloc is a high-performance allocator. snmalloc can be used directly in a project as a header-only C++ library, it can be LD_PRELOADed 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 different thread
  • Deallocations occur in large batches

Both of these can cause massive reductions in performance of other allocators, but do not for snmalloc.

The implementation of snmalloc has evolved significantly since the initial paper. The mechanism for returning memory to remote threads has remained, but most of the meta-data layout has changed. We recommend you read docs/security to find out about the current design, and if you want to dive into the code docs/AddressSpace.md provides a good overview of the allocation and deallocation paths.

snmalloc CI

Morello build

Installation

mkdir build/

cd build

cmake -G Ninja .. -DCMAKE_C_FLAGS='-march=morello -mabi=purecap -Xclang -morello-vararg=new' -DCMAKE_CXX_FLAGS='-march=morello -mabi=purecap -Xclang -morello-vararg=new' -DCMAKE_BUILD_TYPE=Debug

ninja

Hardening

There is a hardened version of snmalloc, it contains

  • Randomisation of the allocations' relative locations,
  • Most meta-data is stored separately from allocations, and is protected with guard pages,
  • All in-band meta-data is protected with a novel encoding that can detect corruption, and
  • Provides a memcpy that automatically checks the bounds relative to the underlying malloc.

A more comprehensive write up is in docs/security.

Further documentation

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Description
No description provided
Readme MIT 6.1 MiB
Languages
C++ 95.4%
CMake 3.6%
C 0.5%
Starlark 0.4%
Dockerfile 0.1%