Managing VPS Swap With vm.swappiness
Since Kernel V2.6.x users have been able to utilize SWAP on Linux servers. It was introduced around the time CentOS 6.x was released, many years ago now. Swap is the ability to push out completed tasks in the physical memory to the disk (swapping). Swapping usually occurs in a separate /swap partition but can also occur in a file. On the First2Host network swapping happens in a dedicated /swap partition on our PCIe NVMe sticks making it extremely fast.
More recently the idea of SWAP has been used in hardware. There is a type of hard drive you can buy called an SSHD hard drive. This uses the same idea as SWAP. It’s a standard SATA hard drive with a SWAP partition. Instead of writing data to the disk, which on a 7200RPM mechanical drive is slow, it writes the information to its SWAP or virtual memory first before transferring the data to the disk in the background making it almost as fast as an SSD drive. The downside of an SSHD drive is if you have a power cut before the data has been written to the disk then you are going to lose some information.
Managing VPS SWAP with vm.swappiness
But on our KVM NVMe VPS Servers, you can manage SWAP and how your server uses SWAP with the vm.swappiness file. The default value on our network is 50 representing 50% of your memory will be free before swapping happens. The lower the value in the vm.swappiness files the less swapping that will happen. The higher the value them more swapping will happen.
0 – No swapping will happen
1 – Minimal swapping will happen but SWAP is still enabled
50 – The server will use 50/50 Swap and physical memory
100 – The server will use SWAP before physical memory
Check current vm.swappiness value
You can check your current SWAP settings by issuing the below command;
This will return the current value in the /proc/sys/vm/swappiness file. If you want to test new SWAP settings change the value in this file and monitor your SWAp usage.
To temporarily change the swappiness settings echo your new value to the
echo 50 > /proc/sys/vm/swappiness
You can also use sysctl to change the swappiness value ;
sysctl -w vm.swappiness=50
Making The Swappiness Change Permanent
This is just a temporary change. After reboot, the value will return to the previous setting. To make the change permanent you need to edit the /etc/sysctl.conf file with nano or another text editor on the command line and add the following line to the bottom of the file;
vm.swappiness = 50
How was this article? – Managing VPS Swap With vm.swappiness
You might also like
More from SolusVM
Free Up Space VirtuozzoWhen using Virtuozzo and Ploop containers sometimes there can be issues with space management. It's possible that …