Use it to add or size swap, or when the system swaps heavily.
swap
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.
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.
memory pressure → kernel reclaims pages → anonymous pages written to swap → read back on access
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
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
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 · 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.
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.
swapon --show— active swapfindmnt— mount tree with optionsdf -hT— usage and filesystem typesfindmnt --verify— check /etc/fstabdmesg -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 -aactivates allswapentries in fstab, except those withnoauto.--showprints a table of the active swap areas, andswapoff -adisables all swap.- Priorities range from 0 to 32767, and higher numbers are used first. The fstab equivalent is
pri=. --discardenables TRIM for the swap area.
Swap files (manual)
| Requirement | Detail |
|---|---|
| No holes | Files created with cp or truncate can be sparse and are rejected |
| Creation | dd from /dev/zero is the most portable method; fallocate works on some file systems (XFS since 4.18) |
| Btrfs | Supported since Linux 5.0, on files with the nocow attribute |
| NFS | Swap over NFS may not work |
| Path | Must be absolute |
Device or file
| Swap partition or LV | Swap file | |
|---|---|---|
| Resize | Resize the partition or LV | Create a new file |
| Setup | mkswap /dev/vg0/swap | dd, chmod 600, mkswap |
| Hibernation | Simpler | Needs 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.
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.
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
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
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%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.
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.
Quick lookup tables
swap operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for swap.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | 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 prove healthy application latency. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin 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 chain | RAM pressure → page reclaim → swap source activation/priority → swap I/O → process memory fault-in → workload latency | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | Swap 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 evidence | Correlated Linux storage evidence can establish this proof path: RAM pressure → page reclaim → swap source activation/priority → swap I/O → process memory fault-in → workload latency | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It 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 check | Continue 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 boundary | swap |
|---|---|
| Topic path | Filesystems & Mounting → swap |
| Runtime state | 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 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 chain | RAM 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 boundary | Swap 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 rule | Prove which configuration source owns the state, then prove that the running consumer loaded or generated the intended state. |