Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

swap

Direct answer

Swap is disk space (a partition or swap file) used when RAM is short; the kernel moves inactive pages there. vm.swappiness controls how eagerly it swaps.

When to use this

Use it to add or size swap, or when the system swaps heavily.

First 30 seconds

1. swapon --show — devices and use.

2. vmstat 1 — si/so continuously > 0?

3. Add a file: fallocate -l 4G /swapfile; chmod 600 /swapfile; mkswap /swapfile; swapon /swapfile.

4. Persist in fstab.

5. sysctl vm.swappiness.

Operational verification

memory pressure → kernel reclaims pages → anonymous pages written to swap → read back on access

Evidence · next step

For Filesystems & Mounting → swap, continue with the first unproven Topic check: List active swap sources, type, size, usage and priority. If that boundary is healthy, advance to the adjacent check: Correlate vm pressure, swap-in/out and OOM events with the incident timeline. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.

Continue only after interpreting the current observation.
Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
linux
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformlinux
Scope / prerequisiteUse it to add or size swap, or when the system swaps heavily.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

5 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Operational evidence path Verify boundary

RAM pressure → page reclaim → swap source activation/priority → swap I/O → process memory fault-in → workload latency

Healthy evidence: expected swap sources are active with intended priorities, no storage errors occur and paging behavior remains compatible with workload latency objectives.

Step 2 Verification and output interpretation Verify boundary

Existing fast checks for this Topic. - List active swap sources, type, size, usage and priority.

  • Correlate vm pressure, swap-in/out and OOM events with the incident timeline.
  • Verify persistent activation configuration separately from current activation.
  • After changes, re-test workload latency and memory behavior rather than only swap capacity.

Verification chain. RAM pressure → page reclaim → swap source activation/priority → swap I/O → process memory fault-in → workload latency

Step 3 Commands Verify boundary
swapon --show
free -h
mkswap /swapfile && swapon /swapfile
cat /proc/sys/vm/swappiness
Step 4 Failure modes and next checks Narrow the fault

Suspicious evidence: persistent heavy swap-in/out, missing expected swap activation, slow backing storage or using swap to mask runaway memory consumption indicates further investigation.

Step 5 Common mistakes Narrow the fault
  • Swap file with wrong permissions (must be 600).
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points

Heavy swap activity (si/so in vmstat) slows everything — it means too little RAM for the workload. Swap files need chmod 600 and mkswap; add to fstab. Some workloads (Kubernetes nodes) require swap off.

Key checks
  • swapon --show — active swap
  • findmnt — mount tree with options
  • df -hT — usage and filesystem types
  • findmnt --verify — check /etc/fstab
  • dmesg -T | grep -iE 'ext4|xfs|btrfs' — filesystem kernel messages
ReferenceWhat it is1 section · depth on demand

Core model

Identify active swap devices/files, priority and capacity, then correlate swap-in/out with memory pressure and workload latency. Separate swap configured in fstab from currently activated swap. For swap files, filesystem support and file properties matter.

ReferenceImportant terms & boundaries5 sections · depth on demand

What this shows and what it does not

Swap evidence shows paging capacity and activity, not root cause of memory pressure or acceptable application performance.

In depth

Swap: devices, files and priorities

Swap is disk space the kernel uses for memory pages that aren't currently needed. The swapon(8) manual page describes how swap is managed:

  • swapon -a activates all swap entries in fstab, except those with noauto.
  • --show prints a table of the active swap areas, and swapoff -a disables all swap.
  • Priorities range from 0 to 32767, and higher numbers are used first. The fstab equivalent is pri=.
  • --discard enables TRIM for the swap area.

Swap files (manual)

RequirementDetail
No holesFiles created with cp or truncate can be sparse and are rejected
Creationdd from /dev/zero is the most portable method; fallocate works on some file systems (XFS since 4.18)
BtrfsSupported since Linux 5.0, on files with the nocow attribute
NFSSwap over NFS may not work
PathMust be absolute

Device or file

Swap partition or LVSwap file
ResizeResize the partition or LVCreate a new file
Setupmkswap /dev/vg0/swapdd, chmod 600, mkswap
HibernationSimplerNeeds the resume offset

How much swap

There's no single rule. Swap lets rarely used pages leave RAM, and gives warning time before the OOM killer acts. On servers, a few GiB is common. Watch the swap-in and swap-out rates, not how full the swap area is. Constant swapping means the system needs more memory.

host$ swapon --show
NAME          TYPE      SIZE  USED PRIO
/dev/dm-2     partition   8G 1.2G   -2
host$ sudo dd if=/dev/zero of=/swapfile bs=1M count=4096 status=progress
host$ sudo chmod 600 /swapfile && sudo mkswap /swapfile
host$ sudo swapon -p 10 /swapfile
host$ echo '/swapfile none swap defaults,pri=10 0 0' | sudo tee -a /etc/fstab
host$ swapon --show
NAME      TYPE      SIZE  USED PRIO
/dev/dm-2 partition   8G 1.2G   -2
/swapfile file        4G   0B   10
host$ vmstat 1 5 | awk 'NR<=2 || NR>2 {print $7, $8}'
host$ sysctl vm.swappiness

Reading the example

The new swap file has priority 10, higher than the partition's −2, so the kernel uses it first. In vmstat, the si and so columns show swap-in and swap-out per second. Sustained non-zero values matter more than the "USED" figure.

Documented example, not captured output.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

How it works at runtime

swap is part of Filesystems & Mounting → swap. swap provides anonymous-memory backing on a partition, logical volume or file, allowing the kernel to page memory under pressure; configured swap does not substitute for sufficient RAM or show healthy application latency.

Topic-specific state model. swap provides anonymous-memory backing on a partition, logical volume or file, allowing the kernel to page memory under pressure; configured swap does not substitute for sufficient RAM or show healthy application latency.

Interpretation rule. - Swap configured ≠ swap currently active.

  • Swap free space ≠ memory pressure absent.
  • Swap usage > 0 ≠ immediate fault by itself.
  • Adding swap ≠ fixing a memory leak or latency-sensitive workload.

Quick reference

Swap gives the kernel somewhere to move inactive anonymous memory.

swapon --show; free -h
cat /proc/sys/vm/swappiness
sysctl -w vm.swappiness=10; echo 'vm.swappiness=10' > /etc/sysctl.d/90-swap.conf
# swap file
fallocate -l 4G /swapfile && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile
echo '/swapfile none swap defaults 0 0' >> /etc/fstab
# zram (compressed RAM swap) on Fedora/Ubuntu: zram-generator

A little swap helps the kernel evict unused pages; heavy swapping (vmstat si/so) means not enough RAM. Btrfs swap files need chattr +C and no compression/snapshots on that subvolume.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Limits and how it fails

Primary failure point. Swap evidence shows paging capacity and activity, not root cause of memory pressure or acceptable application performance.

ReferenceConfiguration & state1 section · depth on demand

Configuration, persistence and lifecycle

Distribution/platform context. swap owns Linux swap backing and activation semantics. Resource Monitoring owns memory-pressure analysis; Filesystems owns swap-file backing constraints.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor doclinux current

Authoritative/upstream documentation reviewed for bounded claims in Filesystems & Mounting → swap. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://docs.kernel.org/filesystems/index.html · confidence 94%
Technical changelog & impact

What changed and what may be affected

Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
linux swapswap partitionswap fileswapon memory
Embedded reference data

Quick lookup tables

swap operational reference

Topic-specific lookup boundaries, proof limits and next-step Evidence for swap.

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateswap provides anonymous-memory backing on a partition, logical volume or file, allowing the kernel to page memory under pressure; configured swap does not substitute for sufficient RAM or prove healthy application latency.Establish exactly what this Topic owns before crossing into another subsystem.
Fast verificationPin host + incident/change time → capture block topology and stable identities → validate partition/device metadata → validate filesystem identity/integrity and effective mount namespace/options → validate PV/VG/LV/device-mapper state where used → make one controlled change at the first failed boundary → re-read effective storage state → repeat original workload I/O/acceptance test.Use the shortest evidence path first; a fast check is a boundary test, not blanket proof.
Verification chainRAM pressure → page reclaim → swap source activation/priority → swap I/O → process memory fault-in → workload latencyTrace requested/configured state through effective state to the observed workload result.
Failure boundarySwap evidence proves paging capacity and activity, not root cause of memory pressure or acceptable application performance.Stop broad troubleshooting at the first boundary that is not supported by evidence.
Positive evidenceCorrelated Linux storage evidence can establish this proof path: RAM pressure → page reclaim → swap source activation/priority → swap I/O → process memory fault-in → workload latencyUse this observation only for the specific claim it actually supports.
Evidence limitIt does not independently prove behavior outside the captured device, metadata, mapping, mount or workload scope. Swap evidence proves paging capacity and activity, not root cause of memory pressure or acceptable application performance.Do not promote a local success signal into end-to-end or adjacent-dependency proof.
Next troubleshooting checkContinue from the first unproven boundary: prove backing identity, then on-device metadata, then filesystem/LVM mapping and effective mount/device state, and finally repeat the original workload I/O before any additional storage change.Continue to the next unresolved boundary while preserving the original test condition.

swap · operational reference

Compact Linux state, persistence, verification and boundary reference for fast lookup.

Reference boundaryswap
Topic pathFilesystems & Mounting → swap
Runtime stateswap provides anonymous-memory backing on a partition, logical volume or file, allowing the kernel to page memory under pressure; configured swap does not substitute for sufficient RAM or prove healthy application latency.
Fast checks- List active swap sources, type, size, usage and priority. - Correlate vm pressure, swap-in/out and OOM events with the incident timeline. - Verify persistent activation configuration separately from current activation. - After changes, re-test workload latency and memory behavior rather than only swap capacity.
Verification chainRAM pressure → page reclaim → swap source activation/priority → swap I/O → process memory fault-in → workload latency Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary.
Failure boundarySwap evidence proves paging capacity and activity, not root cause of memory pressure or acceptable application performance. Boundary chain: process credentials/namespace → path/mount lookup → DAC/ACL/LSM → filesystem metadata → block/device/backend → completion/read-back.
Persistence ruleProve which configuration source owns the state, then prove that the running consumer loaded or generated the intended state.
Confirmation

Confirm action

Continue?