Swap exists so that the OS can move idle memory pages to disk and use RAM for active work. On a healthy cPanel host with swap configured, swap usage is small and stable — a few hundred MB of paged-out idle pages, mostly OS daemons that have not been touched in days. Swap thrashing — actively paging in and out under load — is a different state. The host appears to be functioning, but every page-out and page-in adds milliseconds of disk IO, and the host’s effective capacity is decimated. MySQL is the most common victim.
What’s happening
When the kernel decides memory is tight, it picks pages to evict to swap based on the vm.swappiness policy. Default swappiness is 60 — moderately eager to swap. When the kernel evicts a MySQL buffer pool page or a PHP-FPM worker’s heap, the next access to that page reads from swap. Disk reads are 1000x slower than RAM reads. The kernel may also re-evict the page minutes later if memory stays tight.
On a host where the working set exceeds RAM, this becomes a loop: page A out, page B in, then page B back out to bring page A in again. The disks are pegged with swap IO, real workloads stall, and the host load skyrockets — but CPU usage looks fine because everyone is waiting on IO.
How to verify
Free memory and swap snapshot:
free -h
vmstat 1 10
swapon --show
The si (swap in) and so (swap out) columns in vmstat 1 are the diagnostic. Both at zero = no swap activity. Sustained values above zero = active swapping. Both above zero simultaneously over many seconds = thrashing.
Which processes are swapped out:
for f in /proc/*/status; do
awk '/VmSwap|Name/{printf $2 " "} END{print ""}' $f
done | sort -k2 -n -r | head -20
This lists processes by swap use. A MySQL process with multi-GB of swap is bad; a few hundred KB on backgrounded daemons is fine.
The fix
-
First, find why memory is tight.
ps auxf --sort=-%mem | head -20. The top processes are usually mysqld, php-fpm pool processes, clamd, or — if you have not turned them off — pdns and other unused daemons. -
Address the actual memory pressure, not just swap behavior. Resize MySQL buffer pool down, kill unused daemons (covered in the disable-unused-services article), or raise host RAM.
-
Lower swappiness for SSD hosts:
sysctl -w vm.swappiness=10 echo 'vm.swappiness=10' >> /etc/sysctl.d/99-cpanel-perf.confSwappiness 10 tells the kernel to swap reluctantly — only when really under memory pressure.
-
For MySQL specifically, lock its memory pages with
mlock:[mysqld] memlock = 1This prevents MySQL pages from being paged out. Caveat: ensure host RAM truly covers MySQL + everything else, otherwise OOM kicks in.
-
As a last resort, disable swap entirely. On a host with enough RAM for the workload, swap-off (
swapoff -a) means OOM kills bad processes instead of thrashing. Coordinate with monitoring — without swap as a buffer, OOM kills are sudden. -
Watch swap reads in iostat:
iostat -xz 1 10If the swap device has high
%utilandawait, swap IO is on the critical path.
The honest answer is that a cPanel host actively swapping under normal load is undersized. Tuning swappiness or memlock buys time; the durable fix is more RAM or fewer tenants. Stack Harbor sizes hosts as part of environment management.