- Notifications
You must be signed in to change notification settings - Fork114
Message passing based allocator
License
microsoft/snmalloc
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
snmalloc is a high-performance allocator.snmalloc can be used directly in a project as a header-only C++ library,it can beLD_PRELOAD
ed on Elf platforms (e.g. Linux, BSD),and there is acrate to use it from Rust.
Its key design features are:
- Memory that is freed by the same thread that allocated it does not require anysynchronising operations.
- Freeing memory in a different thread to initially allocated it, does not takeany locks and instead uses a novel message passing scheme to return thememory to the original allocator, where it is recycled. This enables 1000s of remotedeallocations to be performed with only a single atomic operation enabling greatscaling with core count.
- The allocator uses large ranges of pages to reduce the amount of meta-datarequired.
- The fast paths are highly optimised with just two branches on the fast pathfor 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 difficultscenarios 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, butdo not for snmalloc.
The implementation of snmalloc has evolved significantly since theinitial paper.The mechanism for returning memory to remote threads has remained, but most of the meta-data layout has changed.We recommend you readdocs/security to find out about the current design, andif you want to dive into the codedocs/AddressSpace.md provides a good overview of the allocation and deallocation paths.
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 indocs/security.
This project welcomes contributions and suggestions. Most contributions require you to agree to aContributor License Agreement (CLA) declaring that you have the right to, and actually do, grant usthe rights to use your contribution. For details, visithttps://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to providea CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructionsprovided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted theMicrosoft Open Source Code of Conduct.For more information see theCode of Conduct FAQ orcontactopencode@microsoft.com with any additional questions or comments.
About
Message passing based allocator