Stupid Linux Swap Tricks with “swappiness”

Want to squeeze a bit more performance out of your MySQL install? Make sure you’re not using swap!

Of course you were probably smart enough to make sure MySQL wasn’t using all the systems memory to begin with so in theory you shouldn’t be swapping. Good idea but the Linux VM isn’t that clever.

It can still make poor decisions and decide to swap portions of MySQL out to disk which can end up hindering performance when it needs to page them back into memory. In replicated installs this can yield to periodic situations where certain MySQL slaves fall far behind and take 30 minutes or more to catch up with the master.

If you’re not sure your MySQL install isn’t using swap you can use vmstat to see realtime stats but I’d recommend using Munin or Ganglia as well.

What you need to do is tune your swappiness (which apparently is the opposite of happiness for MySQL).

Basically just exec:

echo 0 > /proc/sys/vm/swappiness

This will tell the VM to keep application data in memory as much as possible. If you were running a desktop app you might want to set this to 100 (but this is an open debate).

Also… make sure to mount those disks with noatime.

%d bloggers like this: