Skip to content

How to Check Swap Usage in Linux and Find What Uses It

Updated 6 min read

Updated: 12 October 2026 · Applies to: Ubuntu 24.04 (procps 4.0.4, util-linux 2.39, sysstat 12.6, smem 1.5, htop 3.3); AlmaLinux and Rocky Linux 10 ship procps-ng 4.0.4 and sysstat 12.7, and the same commands work on Debian, RHEL and Fedora

To check swap usage in Linux, run free -h: the Swap: line shows the total, used and free swap. swapon --show lists each swap partition or swap file with its own usage, vmstat 1 5 shows whether the server is swapping right now (columns si and so), and grep VmSwap /proc/*/status shows which processes have memory in swap.

The output below is real and comes from a container on our test server (1 vCPU, 3.7 GiB RAM, a 1.2 GiB swap partition). For sections 4 and 5 we started one test process with a 96 MiB memory limit, so that part of it was pushed into swap. It is a lab example, not the performance of a Ucartz server.

1. free: total, used and free swap

$ free -h
               total        used        free      shared  buff/cache   available
Mem:           3.7Gi       660Mi       1.5Gi        70Mi       2.0Gi       3.1Gi
Swap:          1.2Gi       8.8Mi       1.2Gi

Use free -m for megabytes. Read the swap line together with available on the Mem line: a little swap in use while plenty of memory is available is normal. The kernel moves pages that have not been touched for a long time out of RAM and leaves them there until they are needed again. For the memory side of the output, see how to check memory usage in Linux.

2. swapon: usage per swap partition or file

$ swapon --show
NAME      TYPE      SIZE USED PRIO
/dev/sda2 partition 1.2G 8.8M   -2

TYPE is partition or file, and PRIO decides which swap area is used first when there are several. Add --bytes for exact sizes. The older swapon -s and cat /proc/swaps show the same data in KiB:

$ cat /proc/swaps
Filename				Type		Size		Used		Priority
/dev/sda2                               partition	1228776		8960		-2

No output from swapon --show means the server has no swap at all. On Fedora you will usually see /dev/zram0: according to Fedora, swap on zram (compressed swap in RAM) has been the default since Fedora 33.

3. /proc/meminfo: the raw numbers

$ grep -E "^Swap|SwapCached" /proc/meminfo
SwapCached:         1752 kB
SwapTotal:       1228776 kB
SwapFree:        1219816 kB

Used swap is SwapTotal minus SwapFree. This is the file that free, top and the other tools read, so it is the easiest source for scripts and monitoring checks.

4. vmstat and sar: is the server swapping now?

How much swap is in use matters less than how much is moving. Run vmstat 1 7 (one line per second; ignore the first line, it is an average since boot). This is what it showed while the test process was being pushed into swap:

$ vmstat 1 7
procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu-------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st gu
 2  0   8960 1543652 137976 1912940    0    0    14   245   84    1  2  1 94  0  3  0
 2  0   8960 1543652 137976 1912968    0    0     0     0  491 2500 10 30  0  0 60  0
 2  0  70912 1482964 137972 1892972  200 62008   212 62680 2080 5791  3 44  0  0 53  0
 2  1  87360 1480560 137972 1892976 3156 16432  3176 16552 2430 7002  4 42  0  0 54  0
 1  2  90696 1480056 137972 1892944 2148 2736  2176  2744  802 2434  6 35  0  0 59  0
(output shortened)

swpd is swap in use (KiB), so is memory written out to swap per second (KiB) and si is memory read back in. A short burst like this is harmless. When si and so stay above zero for minutes and the server feels slow, it is short of RAM.

With the sysstat package installed, sar -S 1 3 shows swap use in percent and sar -W 1 3 shows pages swapped in and out per second:

$ sar -S 1 2
16:33:57    kbswpfree kbswpused  %swpused  kbswpcad   %swpcad
16:33:58      1116832    111944      9.11     18404     16.44
16:33:59      1099680    129096     10.51     26352     20.41
(output shortened)

5. Which process is using swap?

Each process reports its own swap use as VmSwap in /proc/PID/status. Sorted, largest first:

$ grep VmSwap /proc/[0-9]*/status | sort -k2 -n -r | head -3
/proc/778/status:VmSwap:	  108288 kB
/proc/2/status:VmSwap:	     128 kB
/proc/789/status:VmSwap:	       0 kB

Then ps -p 778 -o pid,comm gives the name (here perl, our test process). smem shows names and swap in one table. It is in the Ubuntu and Debian repositories; for AlmaLinux and Rocky Linux 10.2 the EPEL repository does not have it, only the newer EPEL 10.3 branch does.

$ smem -k -s swap -r -c "pid user command swap rss" | head -3
  PID User     Command                         Swap      RSS
  778 root     perl -e $a = "x" x (160*102   127.2M    82.6M
    2 root     bash                          248.0K     3.1M

In top, the summary line MiB Swap: shows the totals:

MiB Swap:   1200.0 total,   1027.0 free,    173.0 used.   3079.9 avail Mem

The per-process SWAP column is hidden by default. To show it, press f, move to SWAP with the arrow keys, press d to display it and s to sort by it, then q. top -o SWAP starts already sorted by swap. For more ways to list processes, see how to list running processes in Linux.

6. Interactive views: htop, atop, glances

htop shows a Swp bar at the top of the screen; atop and glances show swap next to disk and CPU load. Install them with apt install htop atop glances on Ubuntu and Debian, or dnf install htop on AlmaLinux and Rocky Linux after enabling EPEL (dnf install epel-release).

7. Swappiness: how eagerly Linux swaps

$ cat /proc/sys/vm/swappiness
60

According to the kernel documentation, the value runs from 0 to 200 and the default is 60; lower values make the kernel prefer dropping file cache over swapping. To try a lower value, run sysctl -w vm.swappiness=10, and to keep it after a reboot, put vm.swappiness = 10 in /etc/sysctl.d/99-swappiness.conf. Change it only if monitoring shows that swapping hurts your workload.

What to do when swap usage is high

  1. Check available in free -h and the si and so columns in vmstat 1 10. High swap use with plenty of available memory and no swap activity needs no action.
  2. Find the processes with the most swap (section 5) and check whether one of them is leaking memory or configured too large, for example a database buffer or the number of PHP workers.
  3. To move swapped pages back into RAM, run swapoff -a && swapon -a, but only when available memory is clearly larger than the used swap. Details in how to free up Linux memory safely.
  4. If the server has too little swap or none, add a swap file: how to create a Linux swap file and how much swap you should use.
  5. If it keeps swapping under normal load, the lasting fix is more RAM.

Inside a container, free and top show the host's memory, not the container's limit: our test container had a 96 MiB limit and still showed 3.7 GiB. A KVM VPS such as our KVM VPS plans runs its own kernel, so these commands show the VPS's own RAM and swap.

Official documentation: kernel vm sysctl documentation (swappiness) and the top manual.

War diese Antwort hilfreich?

Still stuck? Open a ticket