Baike.dev
All toolsTrendingOpen sourceNewsSubmit
Log in
< 返回工具列表
M

mimalloc

> 编程语言
开源

mimalloc is a compact general purpose allocator with excellent performance.

13.2K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

mimalloc is a compact general purpose allocator with excellent performance.

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.5.1 (2026-09-01) recommended.
Latest v2 release: v2.5.1 (2026-09-01) stable, legacy.
Latest v1 release: v1.15.1 (2026-09-01) 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 10k 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.

Releases

  • 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 runtimes, 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 suppor, add riscV to CI. 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 concurrency bug in concurrent heap destroy (v3), detect riscV virtual address bits at runtime, add riscV TLS support, reduce spinlock waits (v2), use TLS slots 126/127 on macOS (v3), and other small fixes. All metadata is now separated from heap objects in v3.

  • 2026-04-29, v1.9.10, v2.3.2, v3.3.2: various bug and security fixes through LLM audit (by @Zoxc). Only increase minimal purge size automatically if allow_thp is set to 2. Enable large OS alignment on all platforms (fixing OS large pages on Windows). Fix accounting of committed memory on Linux/macOS. Update MSVC atomics implementation when using C mode. Upstream Emscripten fixes. Proper atomic do-once implementation.

  • 2026-04-20, v1.9.9, v2.3.1, v3.3.1: various bug and security fixes. Special thanks to @jinpzhanAMD, @res2k, and @GoldJohnKing for their help in improving Windows finalization, and @Zoxc for his help in finding various issues.

  • 2026-04-15, v1.9.8, v2.3.0, v3.3.0: initial support for github (binary) releases, fix visiting of full pages during collection (performance), fix THP alignment (performance), fix arm64 cross-compilation on Windows, enable guard pages in debug mode, always use uncommitted areas between arenas (security), enable static overloading of malloc etc. on Windows with the static CRT (by @Noxybot), fix TLS slot leak on Windows (v3), enable clean DLL load/unload with statically linked mimalloc (v3), fix race in mi_heap_destroy (v3), by default put page meta info separate from allocated objects (v3,security), fix C++ overrides for emscripten. Various bugs found by DeepTest include: fix offset for mi_heap_realloc_aligned, fix mi_(w)dupenv_s buffer size, fix potential overflow in size options, and error codes for mi_reallocarr(ay).

  • 2026-02-03, v3.2.8 (rc3): Fix thread reinitialize issue on macOS. Fix SIMD codegen bug on older GCC versions. Extend Windows TLS slot limit from 64 to 1088. Report commit statistics more precise. Fixes issue in free-page search in arenas.

  • 2026-01-15, v1.9.7, v2.2.7, v3.2.7 (rc2): Fix zero initializing blocks that were OS allocated.
    For v3 various bug and performance fixes. Fix Debian 32-bit compilation.

  • 2026-01-08, v1.9.6, v2.2.6, v3.2.6 (rc1): Important bug fixes. Many improvements to v3 including true first-class heaps where one can allocate in heap from any thread, and track statistics per heap as well. Added MIMALLOC_ALLOW_THP option. This is by default enabled except on Android. When THP is detected on v3, mimalloc will set the MIMALLOC_MINIMAL_PURGE_SIZE to 2MiB to avoid breaking up potential THP huge pages. v3 uses faster TLS access on Windows, and has improved performance for mi_calloc and aligned allocations. Fixed rare race condition on older v3, fixed potential buffer overflow in debug statistics, add API for returning allocated sizes on allocation and free.

  • Older release notes

Special thanks to:

  • Sergiy Kuryata for his contributions on reducing memory commit -- especially on Windows with the Windows thread pool (now implemented in v3).
  • David Carlier (@devnexen) for his many contributions, and making mimalloc work better on many less common operating systems, like Haiku, Dragonfly, etc.
  • Mary Feofanova (@mary3000), Evgeniy Moiseenko, and Manuel Pöter (@mpoeter) for making mimalloc TSAN checkable, and finding memory model bugs using the genMC model checker.
  • Weipeng Liu (@pongba), Zhuowei Li, Junhua Wang, and Jakub Szymanski, for their early support of mimalloc and deployment at large scale services, leading to many improvements in the mimalloc algorithms for large workloads.
  • Jason Gibson (@jasongibson) for exhaustive testing on large scale workloads and server environments, and finding complex bugs in (early versions of) mimalloc.
  • Manuel Pöter (@mpoeter) and Sam Gross(@colesbury) for finding an ABA concurrency issue in abandoned segment reclamation. Sam also created the no GIL Python fork which uses mimalloc internally.

Usage

mimalloc is used in v

核心特点

  • •__small and consistent__: the library is about 10k LOC using simple and
  • •__free list sharding__: instead of one big free list (per size class) we have
  • •__free list multi-sharding__: the big idea! Not only do we shard the free list
  • •__eager page purging__: when a "page" becomes empty (with increased chance
  • •__secure__: _mimalloc_ can be built in secure mode, adding guard pages,
  • •__first-class heaps__: efficiently create and use multiple heaps to allocate across different regions.
  • •__bounded__: it does not suffer from _blowup_ \[1\], has bounded worst-case allocation
  • •__fast__: In our benchmarks (see below),
  • •__v3__: recommended: simplifies the lock-free design of previous versions and improves sharing of
  • •__v2__: stable legacy mimalloc version. Uses thread-local segments to reduce fragmentation. (release tags: v2.x, development branch dev2 and main)

> 标签

C

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月9日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言
Baike.dev

baike.dev helps you discover great languages, frameworks, databases, DevOps and cloud-native tools.

Quick links

  • Home
  • All tools
  • Trending
  • Open source

About

  • About us
  • Community
  • News

Contribute

Found a great developer tool? Share it with the community.

Submit a tool
© 2026 baike.dev Developer EncyclopediaUpdated daily · Discover great developer tools