Tell Your Server to Stop Swapping So Hard

Performance Tuning & Kernel Parameters (Sysctl)

Tell Your Server to Stop Swapping So Hard

🧩 The Challenge

Ever had a server with plenty of RAM just suddenly slow down, even when free shows you’ve got gigs to spare? You start seeing huge I/O wait on disks that aren’t even that busy, and applications just lag. It’s infuriating when all the usual memory metrics look fine, but your system is clearly struggling.

💡 The Fix

Your kernel is likely swapping out active application memory, even with plenty of physical RAM, just to cache files it might need later. A quick kernel parameter adjustment fixes this, telling your system to prioritize active processes and keep things snappy.

# Check current value:
sysctl vm.swappiness

# Set temporarily (resets on reboot):
sudo sysctl -w vm.swappiness=10

# Set permanently (for future reboots):
echo "vm.swappiness = 10" | sudo tee /etc/sysctl.d/99-swappiness.conf
sudo sysctl --system

⚙️ Why It Works

By default, Linux will sometimes prefer to swap out even active application memory to expand its disk caches. vm.swappiness dictates this preference, with 0 telling the kernel to avoid swapping almost entirely unless it runs out of options, and 100 making it super aggressive. A lower value, like 10, means your kernel will keep application data in RAM much longer, only swapping when truly necessary.

🚀 Pro-Tip: Monitor your I/O and vmstat after changing this; you’ll know pretty quick if it helped.

Linux Tips & Tricks | © ngelinux.com | 10/19/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted