Hostxpeed
Login Get Started →
Server Management

How to Tune Swappiness

4 min read
23 views
Jun 10, 2026

Prerequisites

Before tuning swappiness, make sure you have:

  • SSH access to your VPS
  • Root or sudo privileges

What is Swappiness?

Swappiness is a kernel parameter (0-100) that controls how aggressively the system uses swap space.

  • 0-10 – Use swap only when necessary (recommended for servers with enough RAM)
  • 60 – Default value (balanced)
  • 100 – Aggressively use swap (not recommended)

Step 1: Check Current Swappiness

Connect to your VPS:

ssh hxroot@YOUR_SERVER_IP -p 22
cat /proc/sys/vm/swappiness

Output is usually 60.

Step 2: Temporarily Change Swappiness

Set to 10 (good for VPS with 4GB+ RAM):

sudo sysctl vm.swappiness=10

Verify:

cat /proc/sys/vm/swappiness

Step 3: Make Permanent

sudo nano /etc/sysctl.conf

Add at the end:

vm.swappiness=10

Apply:

sudo sysctl -p

Recommended Swappiness Values

  • VPS with HD (spinning disk) – 10-20 (swap is slow, avoid it)
  • VPS with SSD/NVMe – 10-30 (swap is fast but still slower than RAM)
  • VPS with less than 2GB RAM – 40-60 (need swap frequently)
  • Database servers – 1-5 (swap hurts database performance)
  • Container hosts (Docker) – 10-20

Check if Swappiness Change is Helping

Monitor swap usage before and after:

free -h
vmstat 2 5

Look at the "si" and "so" columns (swap in/out). Lower is better.

Reset to Default

sudo sysctl vm.swappiness=60

Remove or comment line in /etc/sysctl.conf.

Swappiness per Process? (Advanced)

Use cgroups or numactl for per-process memory policies.

✅ Swappiness tuned. Your server will use swap less aggressively, improving performance.

Was this article helpful?