Read Active Swap Areas from /proc/swaps
You will finish with a safe, repeatable way to see which swap areas the running Linux kernel is using, how much space each one holds, and how much is currently occupied. Allow about ten minutes. You need a shell and access to /proc; the inspection commands below do not need elevated privileges.
The route
Jump straight to the step you need, or tick off Done means at the end.
This guide describes the behaviour documented by Linux man-pages 6.7, installed locally as Debian package manpages 6.7-2. The accompanying swapon command is from util-linux 2.41.3. The file is a live view of the current kernel state, not a configuration file to edit.
1. Read the kernel's swap table
Run cat against the exact path from proc_swaps(5):
$ cat /proc/swaps
Filename Type Size Used Priority
/dev/md0 partition 16759804 3387660 -2
Your rows will differ. A machine with no active swap normally shows only the header. A row means that the kernel currently has that swap area in use. The filename may be a partition, a regular file, or another supported swap backing device.
Checkpoint: save the output before making a change elsewhere. This gives you a before-state for troubleshooting without changing anything on the host.
2. Interpret each column
The first line names five fields:
Filenameidentifies the backing path, such as/dev/md0or/swapfile.Typedescribes the backing type reported by the kernel, commonlypartitionorfile.Sizeis the swap capacity in kibibytes in the traditional/proc/swapsdisplay.Usedis the amount currently occupied, also in kibibytes.Priorityis the relative preference used when more than one swap area is active.
Do not read Used as a permanent allocation. It is a snapshot of pages currently placed in swap and can rise or fall as memory pressure changes. A non-zero value is not, by itself, evidence of a fault.
Priorities can be negative. That is valid output, not an error. When the kernel has several eligible areas, it prefers the highest priority value and uses areas with equal priority in parallel. If no explicit priority was set, the kernel and activation mechanism may supply a default. Treat the values you observe as the contract for this boot, rather than guessing from the device name.
3. Cross-check with swapon
The util-linux command provides a human-friendly view of the same active set. This is still read-only:
$ swapon --show
NAME TYPE SIZE USED PRIO
/dev/md0 partition 16G 3.2G -2
The displayed units and spacing can vary with util-linux and terminal width. Use /proc/swaps when you need the kernel's fixed column names and traditional kibibyte values; use swapon --show when a compact summary is easier to scan.
For a script, request explicit columns and byte units rather than parsing the pretty table:
$ swapon --show=NAME,TYPE,SIZE,USED,PRIO --bytes
NAME TYPE SIZE USED PRIO
/dev/md0 partition 17162039296 3468963840 -2
The exact numbers are host-specific. Check the command's installed help if you are building automation:
$ swapon --help
$ swapon --version
swapon from util-linux 2.41.3
Do not assume that a zero-row result from swapon --show means the command is broken. Compare it with cat /proc/swaps, then check whether the command is reading the same host and mount namespace as your shell.
4. Diagnose the common confusing cases
If /proc/swaps is missing, first check whether procfs is mounted:
$ test -r /proc/swaps && cat /proc/swaps || echo '/proc/swaps is not readable'
/proc/swaps is not readable
This example intentionally shows the fallback branch. On an ordinary host with procfs mounted, the test prints the swap table instead. A container may have a restricted or different view of procfs, so do not diagnose host swap from inside a container without checking the execution environment.
If the header appears but there are no rows, the kernel sees no active swap areas in that environment. That does not prove that a swap partition or file is absent: it may exist but not be activated. Activation and deactivation are state-changing operations, and can affect memory management. Do not copy commands such as swapon or swapoff into a production runbook until you have confirmed the target path, capacity and recovery plan.
If Used is unexpectedly high, record the table and check it again after a short interval. Avoid repeatedly toggling swap as a diagnostic shortcut. swapoff must move swapped pages back into memory and can fail or create severe memory pressure; it also changes live system state and may disrupt workloads.
5. Verify the result without changing state
Run both views and compare the active names, types, sizes, usage and priorities:
$ cat /proc/swaps
$ swapon --show=NAME,TYPE,SIZE,USED,PRIO --bytes
The formats are different, so compare the fields rather than expecting identical text. A changing Used value between commands is normal on a busy machine. If the active names disagree, stop before changing swap: investigate namespaces, command versions and the timing of the two reads.
Done means
- You can read the active swap rows from
/proc/swaps. - You can explain
Filename,Type,Size,UsedandPriority. - You cross-checked the result with
swapon --showand, where useful, byte units. - You treated missing rows, restricted procfs and changing usage as diagnostic clues, not automatic faults.
- You did not run
swaponorswapoff, so no swap or service state changed.