This guide covers how to modify and increase SWAP memory on a KVM virtualization Linux VPS. SWAP memory supplements RAM by storing data that cannot fit into RAM. The recommended SWAP size varies, but in this guide, we'll allocate 6 GB.
Allocating SWAP Memory
- Check Existing SWAP: Verify if SWAP is currently allocated:
The "Swap" line should show zeros if no SWAP is present.
- Create SWAP File: Allocate 6 GB for SWAP:
fallocate -l 6G /swapfile
- Verify File: Ensure the SWAP file was created:
At first, your SWAP may not be allocated due to permission issue and you might be seeing this message:
rw-r--r-- 1 root root 6.0G Dec 5 14:32 /swapfile
- Set Permissions: Adjust permissions for the SWAP file:
Recheck the permissions:
The output should now be -rw------- 1 root root 6.0G Dec 5 14:36 /swapfile
.
- Configure SWAP: Set up the file as a swap area:
- Enable SWAP: Activate SWAP:
- Verify Allocation: Check that SWAP is active:
You should see 6 GB listed under "Swap".
Making SWAP Changes Permanent
To ensure SWAP remains active after a reboot, update /etc/fstab
:
- Backup
fstab
:
cp /etc/fstab /etc/fstab.old
- Edit
fstab
: Add the following line:
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Additional Options
- Swappiness: Controls how aggressively the system uses SWAP. A lower value (e.g., 10) means SWAP is used less frequently.
cat /proc/sys/vm/swappiness
Set swappiness by adding this to /etc/sysctl.conf
:
- VFS Cache Pressure: Adjusts how often the file system cache is updated. A lower value (e.g., 50) can be beneficial.
cat /proc/sys/vm/vfs_cache_pressure
Set cache pressure by adding this to /etc/sysctl.conf
:
vm.swappiness=10
For further assistance, please contact customer support.