talira

jemalloc

General-purpose malloc implementation focused on fragmentation and concurrency

open sourceBSD-2-Clausefree

jemalloc is a general-purpose malloc(3) implementation in C that emphasizes avoiding fragmentation and scaling across threads. It has been FreeBSD's libc allocator since 2005 and many applications link it in place of the system allocator for its predictable behaviour. Beyond malloc it has the non-standard mallocx family, per-thread caches and multiple arenas, the mallctl interface for reading statistics and changing settings at run time, runtime options through MALLOC_CONF, background threads that purge unused memory, transparent huge page settings, and optional heap profiling and leak detection. It builds with autoconf on Unix-like systems and with Visual Studio on Windows, and is BSD-licensed; Jason Evans created it, and Meta engineers develop it with the community.

Problems it solves

  • my Ruby on Rails processes keep growing in memory because of fragmentation
  • reduce memory fragmentation in a long-running multithreaded server
  • replace glibc malloc to cut a process's resident memory
  • find where my C or C++ program allocates the most memory with heap profiling
  • detect memory leaks in a native service in production
  • an allocator that scales across many threads without lock contention
  • read allocator statistics from inside my running program
  • tune when freed memory is returned to the operating system
  • use a different global allocator in my Rust program

Features

  • drop-in malloc(3), calloc, realloc and free implementation
  • non-standard mallocx, rallocx, xallocx, sallocx, dallocx, sdallocx and nallocx APIs
  • mallctl interface for statistics and run-time settings
  • runtime options via malloc_conf, /etc/malloc.conf and MALLOC_CONF
  • per-thread caches (tcache) and multiple arenas
  • background threads that purge unused memory
  • transparent huge page options such as metadata_thp
  • heap profiling and leak detection (--enable-prof)
  • configurable API prefix and private namespace for embedding
  • autoconf build for Unix-like systems and Visual Studio build for Windows
View 1 more
  • FreeBSD libc allocator since 2005

Limitations

  • Defaults are conservative: its tuning guide says the default settings are sometimes suboptimal for common workloads and that tuning usually gains a few percent123
  • Heap profiling is a build option: profiling and leak detection need jemalloc built with --enable-prof123
  • Older documentation is partly obsolete: the website warns that many details in older docs no longer apply123

Capabilities

Has official SDKsplan not known