Home / Alt manpages / proc_swaps(5)

  • proc_swaps(5)
  • File format
  • linux

Read Active Swap Areas from /proc/swaps

Something is swapping and you want to know what, so you run cat against /proc/swaps and see exactly which areas the kernel is using right now. Give it about ten minutes. You need a shell and read access to /proc; every command in this guide is read-only, so nothing here can make things worse.

This matches Linux man-pages 6.7 (Debian package manpages 6.7-2) and the accompanying swapon command from util-linux 2.41.3. Worth knowing up front: /proc/swaps is a live view of kernel state, not a config file, so there is nothing in it 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 shows only the header row: that is normal, not broken. Each row means the kernel currently has that swap area in use, and the filename can be a partition, a regular file, or any other supported swap backing device.

Checkpoint

Save this output before you change anything elsewhere. It gives you a before-state to compare against if something goes wrong later.

2. Interpret each column

The header line names five fields:

  • Filename is the backing path, such as /dev/md0 or /swapfile.
  • Type is the backing type the kernel reports, commonly partition or file.
  • Size is the swap capacity in kibibytes, the traditional unit for this file.
  • Used is the amount currently occupied, also in kibibytes.
  • Priority is the relative preference used when more than one swap area is active.

Do not read Used as a permanent allocation: it is a snapshot that rises and falls with memory pressure, and a non-zero value on its own is not evidence of a fault. Priorities can also be negative, which is valid output, not an error. The kernel prefers the highest priority value it has, and uses areas of equal priority in parallel; if nothing set a priority explicitly, the kernel or activation tool supplied a default. Treat whatever you see as the contract for this boot, not something to guess from the device name.

3. Cross-check with swapon

The util-linux command gives a friendlier view of the same active set, and it is still read-only:

$ swapon --show
NAME      TYPE      SIZE USED PRIO
/dev/md0  partition 16G  3.2G -2

Units and spacing in swapon --show can vary with util-linux version and terminal width. Use /proc/swaps when you need the kernel's fixed column names and kibibyte values; use swapon --show for a quick, compact summary.

For a script, ask for explicit columns and byte units instead of parsing the pretty table:

$ swapon --show=NAME,TYPE,SIZE,USED,PRIO --bytes
NAME      TYPE      SIZE        USED       PRIO
/dev/md0  partition 17162039296 3468963840 -2

The numbers above are host-specific. Check what is actually installed before you build automation around it:

$ swapon --help
$ swapon --version
swapon from util-linux 2.41.3

A zero-row result from swapon --show does not automatically mean 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 confusing cases

Missing file. If /proc/swaps is not there, check whether procfs is mounted before anything else:

$ 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 same test prints the swap table instead. A container can have a restricted or different view of procfs, so do not diagnose host swap from inside a container without checking the execution environment first.

Header only, no rows. The kernel sees no active swap in that environment. That does not prove a swap partition or file is absent, only that it is not activated. Activation and deactivation change state and can affect memory management, so do not copy swapon or swapoff into a production runbook until you have confirmed the target path, capacity and recovery plan.

Used looks high. Record the table and check it again after a short interval rather than repeatedly toggling swap as a diagnostic shortcut. swapoff has to move swapped pages back into memory; it can fail, create severe memory pressure, and it changes live system state.

5. Verify 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 differ, so compare fields rather than expecting identical text. A changing Used value between the two commands is normal on a busy machine. If the active names disagree, stop before touching swap: investigate namespaces, command versions and the timing of the two reads.

Done means

  • Read the active rows straight from /proc/swaps.
  • Explained every column: Filename, Type, Size, Used and Priority.
  • Cross-checked the result with swapon --show and, where it helps, byte units.
  • Treated missing rows, restricted procfs and changing usage as diagnostic clues, not automatic faults.
  • Changed nothing: you never ran swapon or swapoff, so no swap or service state moved.