Enabling and Disabling Jemalloc on Percona Server

Enabling and Disabling Jemalloc on Percona Server

PREVIOUS POST
NEXT POST

Jemalloc on Percona ServerThis post discusses enabling and disabling jemalloc on Percona Server for MySQL.

The benefits of jemalloc versus glibc for use with MySQL have been widely discussed. With jemalloc (along with Transparent Huge Pages disabled) you have less memory fragmentation, and thus more efficient resource management of the available server memory.

For standard installations of Percona Server 5.6+ (releases starting with 5.6.19-67.0), the only thing needed to use jemalloc as the memory library for mysqld is for it to be installed on the server.

Enabling Jemalloc on Percona Server

First thing first: install Jemalloc.

The library is available on the Percona repository, which is available for both apt and yum package management:

Once you have the repo, just run the install command (according to your OS) to install it:

Now that you have the jemalloc package installed, all it takes to start using it is…..

  • Restart the server.

That’s it! No modifications needed on the my.cnf file or anywhere else. Plain and simple!

Disabling Jemalloc on Percona Server

If for any reason you need to disable jemalloc and go back to the default library, you have two options: remove the jemalloc package (not too practical), or add the following line to the [mysqld_safe] section of the my.cnf file:

In other words, an empty path. That will do the trick. Note that commenting or removing the “malloc-lib” parameter on the cnf file won’t work.

How to Know if Jemalloc is Being Used?

There are couple of ways you can verify this, but the less invasive way is by using the pt-mysql-summary (version 2.2.20 and higher) tool from the Percona Toolkit:

PREVIOUS POST
NEXT POST

Share this post

Comments (4)

  • Seveny Media Reply

    Running Persona Server 5.7 here and wasn’t able to find a package called ‘jemalloc’

    # apt-cache search jemalloc
    libjemalloc-dev – development files and documentation for jemalloc
    libjemalloc1 – general-purpose scalable concurrent malloc(3) implementation
    libjemalloc1-dbg – debug symbols for jemalloc

    Installed ‘libjemalloc1’ and it works perfectly:

    # pt-mysql-summary | grep -A5 -i “memory management”
    # Memory management library ##################################
    jemalloc enabled in MySQL config for process with ID 24470
    Using jemalloc from /usr/lib/x86_64-linux-gnu/libjemalloc.so.1
    # The End ####################################################

    January 5, 2017 at 4:39 pm
    • Daniel Guzmán Burgos Reply

      Hi!

      Yes, you’re right. For apt the package name is libjemalloc1. I’ll fix the post. Thanks for catching it up!

      January 6, 2017 at 9:06 am
  • Olivier Doucet Reply

    Please note that this requires Percona Toolkit 3.0+ 😉

    April 24, 2017 at 11:19 am
  • Lee Reply

    I am using mysql-5.7.22 and 23, these two versions, using jemalloc-5.1, combined with MTS, there will be a problem with the memory leak, after the jemalloc is disabled, the memory usage is normal.

    September 26, 2018 at 9:51 pm

Leave a Reply