Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 7e5dce9d40

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


This is a minimal-effort stand-alone jemalloc distribution for Linux.  The main
rough spots are:

* __isthreaded must be hard-coded, since the pthreads library really needs to
  be involved in order to toggle it at run time.  Therefore, this distribution
  builds two separate libraries:

  + : Use for multi-threaded applications.
  + : Use for single-threaded applications.

  Both libraries link against libpthread, though with a bit more code hacking,
  this dependency could be removed for the single-threaded version.

* MALLOC_MAG (thread-specific caching, using magazines) is disabled, because
  special effort is required to avoid memory leaks when it is enabled.  To make
  cleanup automatic, we would need help from the pthreads library.  If you
  enable MALLOC_MAG, be sure to call _malloc_thread_cleanup() in each thread
  just before it exits.

* The code that determines the number of CPUs is sketchy.  The trouble is that
  we must avoid any memory allocation during early initialization.

In order to build:


This generates two shared libraries, which you can either link against, or

Linking and running, where /path/to is the path to libjemalloc (-lpthread
required even for

    gcc app.o -o app -L/path/to -ljemalloc_mt -lpthread
    LD_LIBRARY_PATH=/path/to app


    LD_PRELOAD=/path/to/ app

jemalloc has a lot of run-time tuning options.  See the man page for details:

    nroff -man malloc.3 | less

In particular, take a look at the B, F, and N options.  If you enable
MALLOC_MAG, look at the G and R options.

If your application is crashing, or performance seems to be lacking, enable
assertions and statistics gathering by removing MALLOC_PRODUCTION from CPPFLAGS
in the Makefile.  In order to print a statistics summary at program exit, run
your application like:


Please contact Jason Evans <> with questions, comments, bug
reports, etc.
Something went wrong with that request. Please try again.