1. Check Existing Swap
swapon -s # active swap
free -m # memory & swap usage
2. Check Storage
df -h
3. Create Swap File
sudo dd if=/dev/zero of=/swapfile bs=1M count=4096 # 4GB
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
Verify:
swapon -s
free -m
4. Make Swap Permanent
grep -qxF '/swapfile swap swap sw 0 0' /etc/fstab || echo '/swapfile swap swap sw 0 0' | sudo tee -a /etc/fstab
5. Optional Tuning
Swappiness (default 30 → set to 10):
sudo sysctl -w vm.swappiness=10
grep -qxF 'vm.swappiness=10' /etc/sysctl.conf || echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
Cache Pressure (default 100 → set to 50):
sudo sysctl -w vm.vfs_cache_pressure=50
grep -qxF 'vm.vfs_cache_pressure=50' /etc/sysctl.conf || echo 'vm.vfs_cache_pressure=50' | sudo tee -a /etc/sysctl.conf
That's all! Thank you, you've learned how to create the vSWAP.
