Swap being used when RAM is almost half free

While it is true that kernel uses swap even if there may be memory left, using more than two thirds of it may be an indicator that historically the server may have been running out of memory and that is why it started swapping. I would correlate swap usage with memory usage in the sar reports to deduce whether the system has enough ram. I would also check dmesg or the logs to determine if the server has in fact ran out of memory, and the oom-killer kicked in.


The Linux Kernel starts to swap out memory pages even if you have plenty of ram free. You can fine tune this behaviour by setting a custom swappiness.

http://en.wikipedia.org/wiki/Swappiness

For servers, I'd recommend to set the swappiness to 1 if you have always enough memory for your workload. For workstations, I'd recommend using the default of 60.

# check the current value
cat /proc/sys/vm/swappiness
60

# swappiness = 1 (swap only if necessary)
echo 1 > /proc/sys/vm/swappiness

# or use sysctl
sysctl -w vm.swappiness=1

Make the setting permanent in /etc/sysctl.conf by setting

vm.swappiness=1

and reload it with

sysctl -w