Swap file and swapiness for production servers

Swapfile

Howto create a 2Gb swapfile, enable it, and add to fstab

fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Swapiness

While the swappiness value of 60 is OK for most Linux systems, for production servers, you may need to set a lower value.

For example, to set the swappiness value to 10, run:

sysctl vm.swappiness=10

To make this parameter persistent across reboots, append the following line to the /etc/sysctl.conf file:

/etc/sysctl.conf
vm.swappiness=10