1) Operating System
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
DL580 G7 128GB RAM
3) MySQL Server version
mysql Ver 14.14 Distrib 5.1.60, for unknown-linux-gnu (x86_64) using EditLine wrapper
$ free -m
total used free shared buffers cached
Mem: 128989 21528 107461 0 286 19360
-/+ buffers/cache: 1881 127108
Swap: 4095 0 4095
$ cat /proc/swaps
Filename Type Size Used Priority
/dev/mapper/rootvg-swaplv1 partition 2097144 0 -1
/dev/mapper/rootvg-swaplv2 partition 2097144 0 -2
Swap space on linux can be managed and inspected with the following commands:
Check swap space & usage:
In this case 4GB of swap configured, with none in use.
Generally speaking on a database server you do not want to use ANY swap, at all. Reason being that the database can much more effectively manage the caches in memory than the operating system caches since it has deeper knowledge of the data structure. You can check your memory usage as follows:
Total – Used + Cached
12GB total, 11GB used, 4GB cache.
12 – 11 + 4 = 5GB free RAM
The reason we add the cache data back in, is that this cache value is RAM used by Linux to cache disk data in memory. If an application requires the memory, it is immediately purged and handed to the application since it was only a cache and simply re-read from disk if needed at a later time. By default Linux will use up as much RAM as disk cache as possible, but just throw it away if the RAM is needed elsewhere. While you can modify this behaviour, 99% of the time it works perfectly fine.
This may even result in the system swapping out some un-used RAM in preference to the OS cache, that is also OK as most of the time the RAM is dead that is allocated by some application but has not been used.
Check and/or modify devices used for swap:
the “cat /proc/swaps” command will list the devices in use for swap and their size.
If you wish to add another device to swap, there are three steps
(1) Prepare the mount point with the “mkswap” command, this will format it as a swap partition, much like any filesystem i.e. ext3, etc.
(2) Add the item to /etc/fstab so that it is added as a swap device on system startup
(3) Unless you reboot, the /etc/fstab entry is not automatically added, so we can save a reboot and add it at runtime as follows:
If for some reason you need to remove a swap device at runtime, the command is “swapoff” — you may also need to remove it from /etc/fstab
Swap Space Sizing
Since as I discussed, we do not want to use SWAP space on a database server, it is not important to have a lot. However, it can help to have at least some swap (1-4GB) so that any application with “dead” / leaked memory that is not in use, can have it swapped out to disk rather than use up RAM.
However in theory you could run fine with no swap configured at all.
You should configuring your monitoring & alert systems to raise an alert if pages swapped in/out is excessive – as you may need to reconfigure your MySQL memory settings to correct the issue.
The default location for the temporary directory is /tmp in most cases. This area is almost always setup correctly on Linux machines.
There are two main concerns with /tmp
(1) Some distributions and systems setup a RAMDISK for /tmp backed by swap, you can note this from the filesystem type being “tmpfs”. This behaviour is not necessarily bad but you need to be aware of it.
(2) Make sure enough free space is available. The only use MySQL has here is in the event it has to create a temporary table to satisfy the exection of some queries. In many cases if they are created they are very small (10s of megabytes) — but it is possible your queries could generate tables that are hundred of megabytes.
In the event the /tmp does fill up, MySQL will simply abort the query and delete it. So you are unlikely to be left with a full drive for very long.