# mysql memory consumption, memory leak ?

**URL:** <https://forums.percona.com/t/mysql-memory-consumption-memory-leak/274>\
**Category:** Other MySQL® Questions\
**Created:** [April 7, 2007, 6:24am UTC](https://forums.percona.com/t/mysql-memory-consumption-memory-leak/274 "2007-04-07T06:24:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![masterzen](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/masterzen/32/746_2.png) [@masterzen](https://forums.percona.com/u/masterzen)\
**Post date:** [April 7, 2007, 6:24am UTC](https://forums.percona.com/t/mysql-memory-consumption-memory-leak/274/1 "2007-04-07T06:24:10Z")

</div>

Hi,

I’m running mysql 5.0.32 (debian Etch for what matters) on x86\_64.  
The server has 4GB or RAM, using 90% of innodb tables, and running only mysql.

Mysql config is:  
key\_buffer = 64M  
max\_allowed\_packet = 16M  
thread\_stack = 128K  
table\_cache = 512  
sort\_buffer\_size = 2M  
join\_buffer\_size = 1M  
read\_buffer\_size = 1M  
read\_rnd\_buffer\_size = 1M  
thread\_cache = 8  
query\_cache\_size = 48M  
tmp\_table\_size = 48M  
query\_cache\_limit = 2M  
myisam\_sort\_buffer\_size = 64M  
myisam\_max\_sort\_file\_size = 10G  
myisam\_max\_extra\_sort\_file\_size = 10G  
innodb\_buffer\_pool\_size = 2800M  
innodb\_file\_per\_table = true  
innodb\_data\_file\_path= ibdata1:2G;ibdata2:1G:autoextend  
innodb\_data\_home\_dir = /data/mysql  
innodb\_flush\_method = O\_DIRECT  
innodb\_log\_buffer\_size = 16M  
innodb\_log\_file\_size = 512M  
innodb\_log\_group\_home\_dir = /data/mysql  
innodb\_additional\_mem\_pool\_size=20M  
innodb\_thread\_concurrency = 12  
innodb\_flush\_log\_at\_trx\_commit = 1  
sync\_binlog=1  
innodb\_support\_xa=0

the rest is default.

Now to the issue:  
Memory usage is constantly (but slowly) growing, and now the server sometimes swaps out (and in) lots of memory, especially when there is high traffic.

Normally it should consume about: 2800+20+16\*2+(0.128+2+1+1+1)\*nb\_of\_threads

The max number of threads is the defautl 100, which gives: 3364MB (3.4GB), so well beyond the RAM limit.

Moreover, in normal usage, there is only 10 to 20 threads connected, but it seems that buffers allocated by old running threads (like sort\_buffer and such) are still allocated and not freed.

I don’t think it is normal behavior.  
Does anybody experienced the same issue ?  
Is there something I didn’t get about per threads buffers ?  
Should I lower the innodb\_buffer\_pool\_size ?

Thanks  
Brice

---

<div class="post-metadata">

**Author:** ![Speeple](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@Speeple](https://forums.percona.com/u/Speeple)\
**Post date:** [April 8, 2007, 7:58am UTC](https://forums.percona.com/t/mysql-memory-consumption-memory-leak/274/2 "2007-04-08T07:58:05Z")

</div>

I understand this is a dedicated MySQL database server you’ve set up, but it’s no suprise your OS is resorting to using swap space when MySQLD itself is consuming 3.4GB of RAM.

---

<div class="post-metadata">

**Author:** ![masterzen](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/masterzen/32/746_2.png) [@masterzen](https://forums.percona.com/u/masterzen)\
**Post date:** [April 8, 2007, 9:12am UTC](https://forums.percona.com/t/mysql-memory-consumption-memory-leak/274/3 "2007-04-08T09:12:27Z")

</div>

Sorry my previous post was not that clear.

The problem is not the OS is using swap, it is more that mysql is using more than 4.5GB (at the moment, still slowly growing from time to time) where it should only use as per my calculation only 3.4GB…

This is no surprise the OS is swapping mysql out in this case (even with 1% swappinness).

I took a pmap snapshot a month ago, and while analysing the differences since now, shows that there are lots of 1016k (around 1MB) of anonymous memory allocated.

Is there a way to track mysql allocations (kind of show mutex but with buffers ?).

Does it mean anything to anyone ?

---

<div class="post-metadata">

**Author:** ![sterin](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@sterin](https://forums.percona.com/u/sterin)\
**Post date:** [April 8, 2007, 10:03am UTC](https://forums.percona.com/t/mysql-memory-consumption-memory-leak/274/4 "2007-04-08T10:03:05Z")

</div>

If one of the 16M that you have there is the max\_allowed\_packet it should be a per client basis.  
But at the same time it should never stay so big. It should always go back to net\_buffer\_length as soon as possible.

But no it is very hard to find out what MySQL is doing internally.  
I myself have a lot of wishes with regard of performance tuning that I would like to be able to see internally in mysql. So you are not alone.
