# Percona MySQL swapping

**URL:** <https://forums.percona.com/t/percona-mysql-swapping/3235>\
**Category:** Other MySQL® Questions\
**Created:** [January 30, 2014, 2:30am UTC](https://forums.percona.com/t/percona-mysql-swapping/3235 "2014-01-30T02:30:24Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cybex](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@Cybex](https://forums.percona.com/u/Cybex)\
**Post date:** [January 30, 2014, 2:30am UTC](https://forums.percona.com/t/percona-mysql-swapping/3235/1 "2014-01-30T02:30:24Z")

</div>

Dear community,

I have an issue with MySQL swapping. I tried a lot of things to make sure it doesn’t swap and read lot’s of articles, but I can’t seem to solve the problem. Could you please point me in the right direction?

Info about the server:  
Processor: 2x Intel(R) Xeon(R) CPU E5-2650 (8 cores)  
Memory: 64GB  
Storage: 2x SSD 250GB  
Software: Percona Server (GPL), Release rel33.0, Revision 611

MySQL conf: [url][http://pastebin.com/BrffKQiU[/url]](http://pastebin.com/BrffKQiU%5B/url%5D)

Things I tried:

Added numa-interleave to my.cnf

```auto
[mysqld_safe]
numa-interleave

```

I tested if it works, the result:

```auto
cat /proc/19670/numa_maps | cut -d ' ' -f 2 | uniq
interleave:0-1

```

So that works…

I also set vm.swappiness at 2. I didn’t set it to 0 because the server isn’t a dedicated MySQL server, it’s a webserver, mailserver, etc also.

When I run MySQL for about 10 hours it uses about 2GB swap space. How can I make sure it doesn’t do that?

---

<div class="post-metadata">

**Author:** ![Ringdingcoder](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ringdingcoder/32/975_2.png) [@Ringdingcoder](https://forums.percona.com/u/Ringdingcoder)\
**Post date:** [January 30, 2014, 4:57am UTC](https://forums.percona.com/t/percona-mysql-swapping/3235/2 "2014-01-30T04:57:47Z")

</div>

Why do you think that this is a problem?

---

<div class="post-metadata">

**Author:** ![Cybex](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@Cybex](https://forums.percona.com/u/Cybex)\
**Post date:** [January 30, 2014, 5:03am UTC](https://forums.percona.com/t/percona-mysql-swapping/3235/3 "2014-01-30T05:03:00Z")

</div>

because it slows down MySQL obviously?  
Check this also: [url][http://www.mysqlperformanceblog.com/2013/04/19/swap-insanity-tome-iii-the-write-cache/[/url]](http://www.mysqlperformanceblog.com/2013/04/19/swap-insanity-tome-iii-the-write-cache/%5B/url%5D)

---

<div class="post-metadata">

**Author:** ![spgriffinjr](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@spgriffinjr](https://forums.percona.com/u/spgriffinjr)\
**Post date:** [January 30, 2014, 8:01pm UTC](https://forums.percona.com/t/percona-mysql-swapping/3235/4 "2014-01-30T20:01:33Z")

</div>

i’ve been having the same problem. I enabled vm.zone\_reclaim\_mode to 1 and that seems to be doing the trick. If you find another solution please post. I’m not sure how this will affect performance on the server. I’m currently working on increase the innodb buffer pool from 30G to 40G on a server with 64GB and 16 cores.

---

<div class="post-metadata">

**Author:** ![Cybex](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@Cybex](https://forums.percona.com/u/Cybex)\
**Post date:** [January 31, 2014, 1:32am UTC](https://forums.percona.com/t/percona-mysql-swapping/3235/5 "2014-01-31T01:32:42Z")

</div>

I’m surprised there aren’t more replies to this topic. I’ll try the tip with “vm.zone\_reclaim to 1”, maybe that will help. My InnoDB buffer pool is already 40GB and that didn’t do the trick unfortunately.

I noticed however that MySQL is using less swap after letting it run for a while. Like I said, after 10 hours the swap usage was 2GB and now it’s only 440MB. Still I’d rather have it not swap at all of course.

---

<div class="post-metadata">

**Author:** ![Ringdingcoder](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ringdingcoder/32/975_2.png) [@Ringdingcoder](https://forums.percona.com/u/Ringdingcoder)\
**Post date:** [January 31, 2014, 2:51am UTC](https://forums.percona.com/t/percona-mysql-swapping/3235/6 "2014-01-31T02:51:05Z")

</div>

Have you measured an adverse effect of swapping?

---

<div class="post-metadata">

**Author:** ![Cybex](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@Cybex](https://forums.percona.com/u/Cybex)\
**Post date:** [January 31, 2014, 3:58am UTC](https://forums.percona.com/t/percona-mysql-swapping/3235/7 "2014-01-31T03:58:50Z")

</div>

Not measured, but noticed slowness when browsing the sites when swapping occurred. Why do you keep asking if swapping actually degrades performance? Isn’t that obvious?

---

<div class="post-metadata">

**Author:** ![Ringdingcoder](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ringdingcoder/32/975_2.png) [@Ringdingcoder](https://forums.percona.com/u/Ringdingcoder)\
**Post date:** [January 31, 2014, 7:50am UTC](https://forums.percona.com/t/percona-mysql-swapping/3235/8 "2014-01-31T07:50:21Z")

</div>

It only degrades performance when the stuff that gets swapped out is actually used again later, which is not always the case.

---

<div class="post-metadata">

**Author:** ![scott.nemes](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/scott.nemes/32/5_2.png) [@scott.nemes](https://forums.percona.com/u/scott.nemes)\
**Post date:** [January 31, 2014, 10:49am UTC](https://forums.percona.com/t/percona-mysql-swapping/3235/9 "2014-01-31T10:49:58Z")

</div>

Are there any other applications running on the same server? I.e. web server, FTP server, etc.? And what does your memory usage actually look like (free -g)?

---

<div class="post-metadata">

**Author:** ![Cybex](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@Cybex](https://forums.percona.com/u/Cybex)\
**Post date:** [January 31, 2014, 12:01pm UTC](https://forums.percona.com/t/percona-mysql-swapping/3235/10 "2014-01-31T12:01:22Z")

</div>

Yes, it’s a multi purpose server. It’s running apache, FTP, etc.

free -g:

```auto
total used free shared buffers cached
Mem: 62 59 3 0 0 15
-/+ buffers/cache: 44 18
Swap: 15 2 13

```

---

<div class="post-metadata">

**Author:** ![Ringdingcoder](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ringdingcoder/32/975_2.png) [@Ringdingcoder](https://forums.percona.com/u/Ringdingcoder)\
**Post date:** [January 31, 2014, 12:34pm UTC](https://forums.percona.com/t/percona-mysql-swapping/3235/11 "2014-01-31T12:34:11Z")

</div>

I somehow doubt that a short period of slightly lower performance is really a problem in this setting, especially since it should not be that bad considering that you use SSD storage. It also does not sound like the MySQL server is used full throttle around the clock. If it were, it would likely not get swapped out.

---

<div class="post-metadata">

**Author:** ![Cybex](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@Cybex](https://forums.percona.com/u/Cybex)\
**Post date:** [January 31, 2014, 2:21pm UTC](https://forums.percona.com/t/percona-mysql-swapping/3235/12 "2014-01-31T14:21:57Z")

</div>

Okay, I’ll double check if that’s the cause. But what’s the reason for MySQL to swap then? It has more then enough memory allocated…

---

<div class="post-metadata">

**Author:** ![scott.nemes](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/scott.nemes/32/5_2.png) [@scott.nemes](https://forums.percona.com/u/scott.nemes)\
**Post date:** [January 31, 2014, 4:24pm UTC](https://forums.percona.com/t/percona-mysql-swapping/3235/13 "2014-01-31T16:24:11Z")

</div>

Yeah with only 2GB of swap listed, I’d be surprised if this was causing an issue, especially on SSD (somewhat moot point, but a point none the less). You have your buffer pool set to about 62.5% of your total memory, which may be too high considering you are running multiple services on the same DB server that will be competing for memory. Have you done any checks to see what your buffer pool situation looks like, such as how much is actually being used (show global status – \> Innodb\_buffer\_pool\_pages\_free and Innodb\_buffer\_pool\_pages\_total), what your churn is (show engine innodb status → evicted without access)? Point being with some analysis you might be able to lower the buffer pool without any performance hit depending on your DB load.

---

<div class="post-metadata">

**Author:** ![Cybex](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@Cybex](https://forums.percona.com/u/Cybex)\
**Post date:** [February 1, 2014, 3:40am UTC](https://forums.percona.com/t/percona-mysql-swapping/3235/14 "2014-02-01T03:40:39Z")

</div>

I’m not sure how to read those values. It says total 2.6M and free 2.3M. If it’s really true that there’s so much free, then it’s ridiculous that I have such a big InnoDB storage 🙂 I’ll create a InnoDB pool of 20GB and see what happens.
