Creating optimized swap file Ubuntu
After we installed umami v3 with docker I noticed im using about 50% RAM on our CX22 VPS We have not set up a swap file yet. please give me a command to create it and optimize it
ChatGPT 5.2 said:
Run this as root (su -), or prefix each line with sudo.
0) Check if you already have swap
swapon --show || true1) Create a 4GB swapfile (good default for a CX22)
fallocate -l 4G /swapfile && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile2) Make it persistent across reboots
grep -q '^/swapfile' /etc/fstab || echo '/swapfile none swap sw 0 0' >> /etc/fstab3) “Optimize” swap behavior (safer, less eager swapping)
This sets swappiness to 10 and keeps cache pressure reasonable.
cat >/etc/sysctl.d/99-swap-tuning.conf <<'EOF'4) Verify
swapon --showIf you’d rather do 2GB instead of 4GB, change 4G to 2G in the fallocate line.