SynologyRS
Performance

Understanding Linux memory and swap tuning

📅 2024-12-24✎ 8 min read

swappiness, vm.dirty_ratio and the bits that matter on a 1–2 GB VPS.

Memory tuning has a huge amount of folklore around it. On a small VPS most of the knobs do nothing; a few actually move the needle and one of them can make things worse if you turn it the “obvious” way.

swappiness is not the whole story

The default of 60 is fine for a desktop. On a server that should keep working sets in RAM, 10–20 is usually better. But swappiness is a nudge, not a switch — it will not stop swapping if you genuinely lack RAM.

sysctl vm.swappiness
# set persistently:
echo "vm.swappiness=15" | sudo tee -a /etc/sysctl.d/60-custom.sysctl

The dirty pages stuff that actually bites

vm.dirty_ratio and vm.dirty_background_ratio control when writers flush to disk. Push them down on a small box and your occasional big writes stop turning into multi-second stalls.

vm.dirty_ratio=10
vm.dirty_background_ratio=5
# sysctl --system to apply

Watch before you change

iostat -xmY 1
free -h
cat /proc/vmstat | grep -E "^pgscan|^pswp"

If si/so are consistently non-zero and your apps feel sluggish, you are swap-bound, and no tuning fixes that — you need more RAM or less working set. Tuning only helps when you have some swap but not too much.

Measure first. The memory knob you are most tempted to turn is usually the one that does nothing.