← Back to VPS & Dedicated

How to Configure Swap Space

Swap space extends your VPS memory by using disk as overflow RAM. It prevents out-of-memory crashes on low-RAM servers, though it's much slower than physical RAM.

Checking Existing Swap

swapon --show\nfree -h

If there's no output from swapon --show, no swap is configured.

Creating a Swap File

# Create a 2GB swap file\nfallocate -l 2G /swapfile\nchmod 600 /swapfile\nmkswap /swapfile\nswapon /swapfile\n\n# Make permanent across reboots\necho '/swapfile none swap sw 0 0' >> /etc/fstab

Tuning Swappiness

Swappiness (0–100) controls how aggressively the kernel uses swap. For a server with good RAM, set it low:

echo 'vm.swappiness=10' >> /etc/sysctl.conf\nsysctl -p

A value of 10 means the kernel will only use swap when RAM is 90% full.

Was this article helpful?

On This Page