Swap memory usage provides insight into how Linux handles pressure on physical RAM, especially on servers and desktops running many concurrent processes. When RAM fills up, inactive pages are moved to swap so that foreground workloads continue to run, but every page fault that hits disk introduces additional latency.
Under the hood, the kernel's virtual memory subsystem manages a set of swap devices and files, tracks which pages are resident, and exposes statistics through utilities such as free, swapon, and vmstat. These tools read data from interfaces like /proc/meminfo and /proc/swaps, presenting totals, per-device usage, and rates of swapping in and out.
Understanding swap usage requires more than a single number, because high swap consumption with little ongoing swap traffic is often benign, while continuous swapping usually points to memory pressure or misconfigured workloads. The commands below apply to most modern Linux distributions, and interpreting their output carefully helps decide whether tuning, adding RAM, or investigating memory-hungry processes is necessary.
Steps to check swap memory usage:
- Open a terminal emulator on the Linux system.
- Run the free command to view overall memory and swap usage in human-readable units.
$ free -h total used free shared buff/cache available Mem: 23Gi 1.2Gi 20Gi 13Mi 1.6Gi 21Gi Swap: 1.1Gi 0B 1.1GiThe Swap row shows total swap space, swap currently in use, and remaining free swap, which is useful for a quick high-level check.
- List active swap devices and files with swapon.
$ swapon --show NAME TYPE SIZE USED PRIO /var/lib/swap file 1024M 0B -2 /mnt/data/swapfile file 64M 0B -3
The NAME column identifies each swap partition or file, while USED reveals how much swap is consumed on that specific device.
- Display swap statistics directly from /proc/swaps for a kernel-level view.
$ cat /proc/swaps Filename Type Size Used Priority /var/lib/swap file 1048572 0 -2 /mnt/data/swapfile file 65532 0 -3
The data in /proc/swaps backs commands like swapon and is suitable for scripts that parse raw fields.
- Monitor swap activity over time with vmstat.
$ vmstat 5 5 procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu------- r b swpd free buff cache si so bi bo in cs us sy id wa st gu 1 0 0 21727444 304124 1357144 0 0 4 256 509 0 0 0 99 0 0 0 0 0 0 21722216 304124 1357148 0 0 0 1 640 466 2 1 97 0 0 0 0 0 0 21726520 304132 1357148 0 0 0 15 974 1466 0 0 100 0 0 0 0 0 0 21680968 304132 1357440 0 0 0 3091 332 201 1 0 99 0 0 0 1 0 0 21680968 304140 1357440 0 0 0 10 726 1055 0 0 100 0 0 0
The si and so columns show swap in and swap out rates in KiB per second, which should stay near zero on an idle or lightly loaded system.
- Cross-check global swap totals using /proc/meminfo.
$ grep -i swap /proc/meminfo SwapCached: 0 kB SwapTotal: 1114104 kB SwapFree: 1114104 kB Zswap: 0 kB Zswapped: 0 kB
SwapTotal and SwapFree should closely match the values reported by free, confirming that all swap devices are accounted for.
- Use a real-time monitor such as htop to observe per-process memory and swap usage during load.
$ htop
Enable a SWAP column in htop via the Setup menu to identify which processes are actively using swap space.
- Confirm swap usage and activity by ensuring the reported Swap values and si, so rates align with expectations for the current workload.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
