📦microsoft / mimalloc
← 返回首页
mimalloc is a compact general purpose allocator with excellent performance.
⚖️ MIT🌐 microsoft.github.io📅 创建于 2019-06-19🔄 更新于 2026-11-01

📄 仓库 README

在 GitHub 查看 ↗
来自 GitHub 仓库自述文件 · 版权归原作者所有

v3: v2: v1:    v3:

mimalloc

 

mimalloc (pronounced "me-malloc") is a general purpose allocator with excellent performance characteristics. Initially developed by Daan Leijen for the runtime systems of the Koka and Lean languages.

Latest release : v3.6.1 (2026-10-30) recommended.\ Latest v2 release: v2.5.2 (2026-09-12) stable, legacy.\ Latest v1 release: v1.15.2 (2026-09-12) legacy.

mimalloc is a drop-in replacement for malloc and can be used in other programs without code changes, for example, on dynamically linked ELF-based systems (Linux, BSD, etc.) you can use it as:

> LD_PRELOAD=/usr/lib/libmimalloc.so  myprogram

It also includes a way to dynamically override the default allocator in Windows. Notable aspects of the design include:

  • small and consistent: the library is about 12k LOC using simple and consistent data structures. This makes it very suitable to integrate and adapt in other projects. For runtime systems it provides hooks for a monotonic heartbeat and deferred freeing (for bounded worst-case times with reference counting). Partly due to its simplicity, mimalloc has been ported to many systems (Windows, macOS, Linux, WASM, various BSD's, Haiku, MUSL, etc) and has excellent support for dynamic overriding. At the same time, it is an industrial strength allocator that runs (very) large scale distributed services on thousands of machines with excellent worst case latencies.
  • free list sharding: instead of one big free list (per size class) we have many smaller lists per "mimalloc page" which reduces fragmentation and increases locality -- things that are allocated close in time get allocated close in memory. (A mimalloc page contains blocks of one size class and is usually 64KiB on a 64-bit system).
  • free list multi-sharding: the big idea! Not only do we shard the free list per mimalloc page, but for each page we have multiple free lists. In particular, there is one list for thread-local free operations, and another one for concurrent free operations. Free-ing from another thread can now be a single CAS without needing sophisticated coordination between threads. Since there will be thousands of separate free lists, contention is naturally distributed over the heap, and the chance of contending on a single location will be low -- this is quite similar to randomized algorithms like skip lists where adding a random oracle removes the need for a more complex algorithm.
  • eager page purging: when a "page" becomes empty (with increased chance due to free list sharding) the memory is marked to the OS as unused (reset or decommitted) reducing (real) memory pressure and fragmentation, especially in long running programs.
  • secure: mimalloc can be built in secure mode, adding guard pages, randomized allocation, encrypted free lists, etc. to protect against various heap vulnerabilities. The performance penalty is usually around 10% on average over our benchmarks.
  • first-class heaps: efficiently create and use multiple heaps to allocate across different regions. A heap can be destroyed at once instead of deallocating each object separately. New: v3 has true first-class heaps where one can allocate in a heap from any thread.
  • bounded: it does not suffer from blowup [1], has bounded worst-case allocation times (wcat) (upto OS primitives), bounded space overhead (~0.2% meta-data, with low internal fragmentation), and has no internal points of contention using only atomic operations.
  • fast: In our benchmarks (see below), mimalloc outperforms other leading allocators (jemalloc, tcmalloc, Hoard, etc), and often uses less memory. A nice property is that it does consistently well over a wide range of benchmarks. There is also good huge OS page support for larger server programs.

The documentation gives a full overview of the API. You can read more on the design of mimalloc in the technical report which also has detailed benchmark results.

Enjoy!

Versions

There are three maintained versions of mimalloc. These are mostly equal except for how the OS memory is handled. New development is mostly on v3, while v1 and v2 are maintained with security and bug fixes.

  • v3: recommended: simplifies the lock-free design of previous versions and improves sharing of memory between threads. On certain large workloads this version may use (much) less memory. Also supports true first-class heaps (that can allocate from any thread) and has more efficient heap-walking (for the CPython GC for example). (release tags: v3.x, development branch dev3).
  • v2: stable legacy mimalloc version. Uses thread-local segments to reduce fragmentation. (release tags: v2.x, development branch dev2 and main)
  • v1: legacy version: initial design of mimalloc (release tags: v1.x, development branch dev). Send PR's against this version if possible (and otherwise dev3).

Releases

  • 2026-10-30, v3.6.1: (v3) Many small fixes for CPython integration (thank you @DinoV), Emscripten fixes (#1455, thank you @kleisauke) and reduced memory usage on WASI and Emscripten, C23 free_sized(_aligned) overrides (#1470), improved fork support (#1456), fix armv5tej compilation (#1464), fix MSVC overrides for strdup family (#1460), faster STL allocator trait (#1468), always use a 2-level pagemap for security and simplicity. Experimental support for CHERI platforms. Improved Rust bindings (thank you @OscarTHZhang and @Techcable). Add -DMI_SECURE=MINIMAL as improved security with minimal (~1%) performance impact which puts guard pages around all mimalloc meta-data (but does not encode free lists). Move all static variables into a mi_process_t struct (that is guarded).
  • 2026-10-23, v3.6.0: (v3) add initial profiling hooks and default profiler, "always on" detailed statistics per size-bin, and always-on profiling. Initial rust bindings. Better support for large OS page sizes, support a quiescent state based reclamation interfacec (for CPython), better cache line aware allocation, fix heap visitor where some pages might be skipped, improve fork support, avoid over-allocation for naturally aligned allocations, fix stderr console output for XBox, fix huge allocation rollback, refactor the source and include files, immediately purge very large allocations, fix bcrypt dependency on windows, fix heap-destroy bug when a fresh heap was allocated at the same address (giving a segfault), page_reclaim_on_free is now on by default.
  • 2026-09-16, v3.5.3: (v3) critical bug fix (where the first new on a thread could fail on some platforms #1398). Fix bug with mi_free_size on overaligned small allocations (#1400).
  • 2026-09-12, v3.5.2, v2.5.2, v1.15.2: (v3) Reduced cache contention, improved mi_malloc_csize, improved zero'ing of small blocks, mi_wmalloc variants for runtime systems, always enable detailed statistics. Experimental support for profiling hooks (mimalloc-profile.h).
  • 2026-09-01: Added a readme section on getting the best performance.
  • 2026-09-01, v3.5.1, v2.5.1, v1.15.1: (v3) Yet better performance for free calls. (v3) Added mi_free_small(_nonnull) for fast small allocations, and mi_free_csize(_nonnull) for inlined constant size free-ing. (v3) Improved MI_OPT_ARCH options; on arm64, defaults to armv8.3 on Apple and armv8.1 otherwise. (v3) Default to -DMI_ALLOW_THP=FULL on Linux, where we never split transparent huge pages (THP) during purging (#1282). This may increase rss but can also improve performance. Use -DMI_ALLOW_THP=OFF to disable the use of THP. (v3) Improved cache behavior for small allocations. Improved riscV support. Various small build fixes.
  • 2026-08-18, v1.15.0, v2.5.0, v3.5.0: (v3) slightly better performance for free using aligned chunks, cleanup cmake options, require armv8.3 (with MI_OPT_ARCH) for faster load-acquire, increase retired page count from 1 to 3, faster double free detection in secure mode, use faster atomics for the arena bitmaps (thank you Alan Andrade, #1346), faster pagemap lookup. Other: fix numa sparse node count detection (#1365), add theap stats retrieval, use __builtin_thread_pointer on riscV (#1363), fix C mode compilation on x86 with msvc (#1361), improved mingw-ucrt64 support.
  • 2026-08-05, v1.9.15, v2.4.5, v3.4.5: Fix compilation with xmalloc (#1353), make the build deterministic (#1355), mi_zalloc_aligned fix (#763), improve support for mingw (ucrt64), fix fputs fallback on windows (#1354), (v3): use proper lock backoff for first-class heap deletion, improved riscv64 codegen.
  • 2026-08-01, v1.9.14, v2.4.4, v3.4.4: various bug and security fixes through Opus 5 LLM audit (issue #1271, by @Zoxc). (v3): use pthreads by default on macOS (issue #1333, issue #1327), fix glibc 2.44 crash (issue #1341), fix alignment check for realloc_aligned. (v1,v2,v3): Add initial mingw support, set errno on allocation errors, improved double-free checks and size checks in secure mode, enable build for universal windows platform and xbox (pr #1340), fix numa node detection when numa nodes are sparse.
  • 2026-07-20, v3.4.3: revert TLS slots on macOS to 108/109 (issue #1333).
  • 2026-07-14, v1.9.11, v2.4.1, v3.4.1: various bug and security fixes through LLM audit (by @Zoxc). Fix issue with using OS memory instead of arenas for > 4GiB memory usage (v3), fix con

📈 近 7 天 Star 趋势

每日新增 Star(柱)与累计 Star(线)· 数据来自 GitHub

🏆 排名变化趋势

在各榜单中的排名历史(数字越小越靠前)

📋 历史上榜记录

每次快照的详细数据
日期 榜单 排名 周期新增 总 STAR