The benefits of jemalloc versus glibc memory allocator for use with MySQL have been widely discussed. With jemalloc (along with Transparent Huge Pages disabled) there is less memory fragmentation, and thus more efficient resource management of the server memory. For MySQL 5.6, installing jemalloc is enough to enable it when starting the MySQL process. However, for MySQL 5.7 and 8.0.X series, you will need to take a few extra steps.
Installing the jemalloc package is simple for Percona. This is because 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 the package is installed, we need to make MySQL working with it. And now, it depends on how you are starting MySQL:
|
1 |
yum install jemalloc / apt-get install libjemalloc1 |
systemctl Command)|
1 |
# cat /etc/sysconfig/mysql<br>LD_PRELOAD=/usr/lib64/libjemalloc.so.1 |
2-) Start MySQL
|
1 |
systemctl start mysql |
If you are starting it manually, in the command line, you need to specify the library in the LD_PRELOAD. So the command to initialize will be similar to this one:
|
1 |
LD_PRELOAD=/usr/lib64/libjemalloc.so.1 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid --user mysql |
pt-mysql-summary which is part of the Percona Toolkit:|
1 |
[root@localhost ~]# pt-mysql-summary | grep -A5 -i "memory management"<br># Memory management library ##################################<br>jemalloc enabled in mysql config for process with id 14490<br>Using jemalloc from /usr/lib64/libjemalloc.so.1<br># The End #################################################### |
|
1 |
pid=$(pidof mysqld)<br>cat /proc/${pid}/environ |
Or:
|
1 |
lsof -Pn -p $(pidof mysqld) | grep jemalloc |
This blog post was written to update the guidelines of jemalloc. Important to mention that using the recommendations above regarding systemd, the changes will persist across MySQL upgrades.
Finally, jemalloc still is a good memory allocator and I consider it part of the best practices that should be implemented before the deployment in production.
Finally, you can reach us through the social networks, our forum, or access our material using the links presented below:
Resources
RELATED POSTS