Microsoft has opened the source code of the mimalloc memory allocation system

The company Microsoft has released the library under the MIT license mimalloc with implementations of the memory allocation system originally created for runtime components of languages Koka and Lean. Mimalloc is designed for use in typical applications without modifying their code and can serve as a transparent replacement for the malloc function. It supports operation on Windows, macOS, Linux, BSD, and other Unix-like systems.

A key feature of mimalloc is its compact implementation (fewer than 3500 lines of code) and very high performance. In the conducted tests mimalloc outperformed all competing memory allocation libraries, including jemalloc, tcmalloc, snmalloc, rpmalloc and Hoard.

To evaluate performance, a set of already existing standard tests In some tests, mimalloc outperforms other systems by several times; for example, in the test of object migration between different threads, mimalloc was over 2.5 times faster than tcmalloc and jemalloc. At the same time, lower memory consumption is also observed in most tests, with memory usage reduced by up to 25% in certain scenarios.

Microsoft has opened the source code of the mimalloc memory allocation system

High performance is mainly achieved through the use of free list sharding. Instead of one large list, mimalloc utilizes a series of smaller lists, each tied to a memory page. This approach reduces fragmentation and increases data locality in memory. A memory page is understood as a grouped set of blocks of similar size. On 64-bit systems, the page size is typically 64 KB. If there are no occupied blocks left on a page, it is fully released back to the operating system, which helps reduce memory costs and fragmentation in long-running applications.

The library can be linked at the binding stage or loaded for an already built program (‘LD_PRELOAD=/usr/bin/libmimalloc.so myprogram’). The library also provides API for integrating functionality at runtime and fine-tuning behavior, such as connecting handlers for deferred memory release and monotonically increasing reference counters. There is the possibility to create and use multiple heaps within the application for distributing across different memory areas. It is also possible to release the heap entirely, without iterating through and separately releasing the objects allocated within it.

A safe mode build of the library is available, in which special guard pages are inserted at the block boundaries, and randomization of block allocation and encryption of released block lists are utilized. Such measures allow blocking most common exploitation techniques used in heap buffer overflows. Enabling safe mode decreases performance by about 3%.

Notably, mimalloc is resilient to bloat issues during significant fragmentation. In the worst-case scenario, memory consumption increases by 0.2% for metadata and can reach 16.7% for allocated memory. To avoid conflicts when accessing resources, mimalloc employs only atomic operations.

Source: opennet.ru

Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster