LinuxSenior

Server is crawling: heavy swapping

When memory runs out the kernel swaps to disk and everything slows down. Confirm swap activity with vmstat, find the memory hog, then add RAM or cap the app.

What you see

  • Everything is slow, including a plain shell
  • vmstat shows non-zero si and so
  • Load is high while CPU use is low

What it means

Swap moves memory pages to disk to free RAM. It works as a safety valve, but disk is far slower than memory. When a system swaps constantly, it spends its time moving pages in and out instead of running work, which is called thrashing.

If swapping does not relieve the pressure, the kernel falls back to the out-of-memory killer.

How to confirm the cause

  1. 1
    Watch swap in and swap out live
    vmstat 1 10

    si is memory swapped in from disk per second and so is memory swapped out to disk. Sustained non-zero so means active pressure.

  2. 2
    See memory and swap totals
    free -h

    Little available memory with swap in heavy use confirms it.

  3. 3
    Find the biggest memory users
    ps aux --sort=-%mem | head -10

    The top few processes are your suspects.

Causes and fixes

  • A process uses far more memory than expected

    HOW TO TELL
    One process dominates the ps list and its size grows over time.
    ROOT CAUSE
    A leak or an unbounded cache keeps taking memory until RAM is gone.
    FIX
    Fix or restart the process, and set a memory limit so it cannot starve the host.
  • The host is too small for the workload

    HOW TO TELL
    No single culprit; many processes add up.
    ROOT CAUSE
    The combined working set is larger than RAM, so the kernel has to swap.
    FIX
    Add memory, reduce what runs on the host, or move workloads elsewhere.

How to stop it coming back

  • Alert on sustained swap-out, not only on free memory.
  • Set limits on containers and services so one cannot starve the rest.
  • Size hosts from measured peak use.

Keep going

Sources

Linux man-pages (man7.org) and the systemd manual (freedesktop.org), read 18 Nov 2026. Command options were checked against those pages.

Search

Search cheat sheets and projects