$ free -h
$ -weight: 600;">sudo fallocate -l 2G /swapfile
$ -weight: 600;">sudo fallocate -l 2G /swapfile
$ -weight: 600;">sudo fallocate -l 2G /swapfile
$ -weight: 600;">sudo chmod 600 /swapfile
$ -weight: 600;">sudo chmod 600 /swapfile
$ -weight: 600;">sudo chmod 600 /swapfile
$ -weight: 600;">sudo mkswap /swapfile
$ -weight: 600;">sudo mkswap /swapfile
$ -weight: 600;">sudo mkswap /swapfile
$ -weight: 600;">sudo swapon /swapfile
$ -weight: 600;">sudo swapon /swapfile
$ -weight: 600;">sudo swapon /swapfile
$ -weight: 600;">sudo swapon --show
$ -weight: 600;">sudo swapon --show
$ -weight: 600;">sudo swapon --show
$ free -h
$ -weight: 600;">sudo cp /etc/fstab /etc/fstab.bak
$ -weight: 600;">sudo cp /etc/fstab /etc/fstab.bak
$ -weight: 600;">sudo cp /etc/fstab /etc/fstab.bak
$ echo '/swapfile swap swap defaults 0 0' | -weight: 600;">sudo tee -a /etc/fstab
$ echo '/swapfile swap swap defaults 0 0' | -weight: 600;">sudo tee -a /etc/fstab
$ echo '/swapfile swap swap defaults 0 0' | -weight: 600;">sudo tee -a /etc/fstab
$ grep swap /etc/fstab
$ grep swap /etc/fstab
$ grep swap /etc/fstab
$ cat /proc/sys/vm/swappiness
$ cat /proc/sys/vm/swappiness
$ cat /proc/sys/vm/swappiness
$ -weight: 600;">sudo nano /etc/sysctl.conf
$ -weight: 600;">sudo nano /etc/sysctl.conf
$ -weight: 600;">sudo nano /etc/sysctl.conf
vm.swappiness=10
vm.swappiness=10
vm.swappiness=10
$ -weight: 600;">sudo sysctl -p
$ -weight: 600;">sudo sysctl -p
$ -weight: 600;">sudo sysctl -p - 0 — only swap when RAM is critically full
- 10 — recommended for servers (keeps more data in RAM)
- 60 — Ubuntu default (more aggressive)
- 100 — swap as aggressively as possible - Monitor swap usage in real time with vmstat 1 during peak load periods
- Increase swap size by repeating these steps with a larger fallocate value
- Explore zswap or zram for in-memory compression as an alternative to disk-backed swap