Using MariaDB with TCMalloc or jemalloc

Using tcmalloc

TCMalloc is a malloc replacement library optimized for multi-threaded usage. It also features a built-in heap debugger and profiler. You can build MariaDB with it or LD_PRELOAD it.

To build MariaDB 5.5 with TCMalloc, you need to use the following command


Many other malloc replacement libraries (as well as heap debuggers and profilers) can be used with MariaDB in a similar fashion.

You can also start a standard MariaDB server with TCmalloc with:

/usr/sbin/mysqld_safe --malloc-lib=tcmalloc

or add it to my.cnf. Alternatively just set LD_PRELOAD to point to the to be used malloc library:

export LD_PRELOAD=/path/to/library

Using jemalloc

The above procedure also works with jemalloc. Just replace tcmalloc with jemalloc in the above commands.

Finding memory leaks with jemalloc

jemalloc can provide a report of memory leaks at program exit:

MALLOC_CONF=prof_leak:true,lg_prof_sample:0,prof_final:true \
LD_PRELOAD=${JEMALLOC_PATH}/lib/  path-to-mariadbd

This will produce something like:

<jemalloc>: Leak summary: 267184 bytes, 473 objects, 20 contexts
<jemalloc>: Run jeprof on "jeprof.19678.0.f.heap" for leak detail

You can learn more about the memory leaks with jeprof, that is included with jemalloc:

jeprof --show_bytes path-to-mariadbd jeprof.19678.0.f.heap

You can also generate a PDF call graph of the leak:

jeprof --show_bytes --pdf path-to-mariadbd  jeprof.19678.0.f.heap > /tmp/mariadbd.pdf

See Also


Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.