Enable jemalloc for MySQL 5.7 WHM Server

clickround

Member
Sep 14, 2020
6
0
1
leb
cPanel Access Level
Root Administrator
Hi

i want to enable jemalloc on MySQL 5.7 on cPanel/WHM server on Centos 7.
i install jemalloc:
Code:
yum list jemalloc
yum install jemalloc.x86_64

after that edit /etc/my.cnf and add:
Code:
[mysqld_safe]
malloc-lib=/usr/lib64/libjemalloc.so.1
then restart mysql server from whm. but when i check if jemalloc if enabled using pt-mysql-summary and also using below:
Code:
lsof -p $(pidof mysqld) | grep mem
but the result that it is not enabled yet.
how to enable it?
Thanks,
 

kdean

Well-Known Member
Oct 19, 2012
365
56
78
Orlando, FL
cPanel Access Level
Root Administrator
Centos 7 requires more steps because it doesn't work when just editing the my.cnf

I use the similar TCMALLOC and had to create a conf file at /etc/systemd/system/mysqld.service.d/

I used limits.conf but I believe it doesn't matter what you use. You would put the following in it

Code:
[Service]
Environment="LD_PRELOAD=/usr/lib64/libjemalloc.so.1"
Here's a link to tell you how to use systemctl edit to do it. I had to use the same method to change memory limits (LimitNOFILE, LimitMEMLOCK) that no longer works in my.cnf as well. systemd brought about these changes.

 
  • Like
Reactions: cPanelLauren

clickround

Member
Sep 14, 2020
6
0
1
leb
cPanel Access Level
Root Administrator
Hi

Thanks for your reply.

is there a specific name i must name the new file inside " mysqld.service.d "?

mention "TCMALLOC", in your opinion and experience which is one is better to use with mysql: TCMALLOC or jemalloc? since iam facing a problem with mysql that with time memory consume and increase to high level even if no load at that time but as some memory not free.

Thanks,
 

kdean

Well-Known Member
Oct 19, 2012
365
56
78
Orlando, FL
cPanel Access Level
Root Administrator
You can name it limits.conf like I did.

I have both tcmalloc and jemalloc installed just in case but I've only ever activated tcmalloc. From what I've read jemalloc is a good choice due to lower memory overhead and may be faster that tcmalloc with larger number of threads. Low threads tcmalloc wins. I should test jemalloc as well, but just never got around to it.

I installed the mallocs for the same reason. MySQL 5.7 built in memory allocator leaks like a sieve and just grows and grows. tcmalloc solved that problem for me but I'm sure that jemalloc should do the same if not better for you.
 

kdean

Well-Known Member
Oct 19, 2012
365
56
78
Orlando, FL
cPanel Access Level
Root Administrator
Look back at things, I think I went with tcmalloc because the latest version I could find for Centos was from 2017, while the latest for jemalloc was from 2014. Both have more recent versions, so not sure why there's not more recent versions for either in the repositories. Not sure if there's some issue with later versions if custom compiled, so I just stuck with what I've had.