# Mysql Master eat up swap space and doesn't release it ... why?

**URL:** <https://forums.percona.com/t/mysql-master-eat-up-swap-space-and-doesnt-release-it-why/6398>\
**Category:** Other MySQL® Questions\
**Created:** [June 4, 2018, 4:05pm UTC](https://forums.percona.com/t/mysql-master-eat-up-swap-space-and-doesnt-release-it-why/6398 "2018-06-04T16:05:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mysql.girl](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/mysql.girl/32/29_2.png) [@mysql.girl](https://forums.percona.com/u/mysql.girl)\
**Post date:** [June 4, 2018, 4:05pm UTC](https://forums.percona.com/t/mysql-master-eat-up-swap-space-and-doesnt-release-it-why/6398/1 "2018-06-04T16:05:43Z")

</div>

I am running a mysql 5.5 master  
on a dedicated mysql master host.  
it has 26Gb swap space and now alert on it’s 93% used  
it was 24GB a week ago and I added a tmp file a 2gb and now it’s eaten up as well.  
Swapoff/on doesn’t work cause it isn’t enough free mem avaliable.  
What can I do ? ( besides reboot the master and wait until it all chewed up again )  
What causes this ? bug in 5.5 ? memory leak ?  
thx

swapoff -a; sleep 2; swapon -a  
swapoff: /dev/sda3: swapoff failed: Cannot allocate memory

| innodb\_buffer\_pool\_size | 30064771072

cat /proc/sys/vm/swappiness  
1

cat /proc/sys/vm/dirty\_ratio  
20

RAM\_ Size HD\_Size HD\_Used HD\_Free Used% Speed Cache HT MySQL OSbits Linux\_Version Model  
49408748 689G 307G 348G 47% 2.40GHz 12288 16 5.5.32 x86\_64 CentOS6.9(Final) R610f

DB\_Type SwapSize SwapUsed SwapFree Usage% Cpu\_1m Cpu\_5m Cpu15m  
master 26869752 25055192 1814560 93.247 2.23 2.30 2.30

free -m  
total used free shared buffers cached  
Mem: 48250 47649 600 0 8 101  
-/+ buffers/cache: 47539 710  
Swap: 26239 24699 1540

# ./find-out-what-is-using-your-swap.sh … Overall swap used: 25019700 kB

# kB pid name

24816896 7087 mysqld  
145968 4636 messaging\_local  
28228 4311 puppet  
7016 3226 snmpd  
2444 30865 rsyslogd  
2420 7746 nscd  
2308 7789 nslcd

---

<div class="post-metadata">

**Author:** ![taraso](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@taraso](https://forums.percona.com/u/taraso)\
**Post date:** [July 3, 2018, 1:39pm UTC](https://forums.percona.com/t/mysql-master-eat-up-swap-space-and-doesnt-release-it-why/6398/2 "2018-07-03T13:39:55Z")

</div>

I have similar thing with 5.7. The binary logs are being cached in the RAM, and then naturally in swap. Tuning helped a bit (which you already have done):  
vm.swappiness = 1

As well as keeping buffer pool below max memory limit to allow some space in RAM for binary logs.

However, I didn’t manage to address the issue completely. Namely, I couldn’t find a way to make mysql push away the logs from the RAM that are older than certain age or make it reclaim memory used by older logs as new logs arrive (i.e. restrict amount of RAM allowed for binlog use). A couple of things that can be used as a workaround:

- reduce amount of logs stored (expire\_logs\_days)
- clear system caches: sync; echo 3 \> /proc/sys/vm/drop\_caches

Another thing that comes to my mind is performance\_schema, but it wasn’t hogging on RAM until 5.7, I think.
