Thought this was useful to note, but these are just the commands from this article from DigitalOcean about enabling swap without reading everything (basically a tl;dr): https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-20-04
Checking swap:
swapon --show
free -h
Enabling (temp):
fallocate -l 1G /swapfile
chmod 600 /swapfile
sudo mkswap /swapfile
Enabling (perm):
fallocate -l 1G /swapfile
cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Configuring (in /etc/sysctl.conf):
Set to minimize swap on VPS to reduce host hardware impact (values between 0-100, 0 being reduced swapping, 100 being more swapping, values here are all the way down to minimize swap usage as much as possible):
- vm.swappiness=1
- vm.vfs_cache_pressure=25
Checking configuration for above:
- cat /proc/sys/vm/swappiness
- cat /proc/sys/vm/vfs_cache_pressure
- cat /proc/sys/<sysctl options, ‘/’=’.’>
Disabling:
- swapoff -a
Leave a Reply