swap (advanced)

Manage swap space on Linux systems.

medium risk

interactive breakdown — edit the command and press Explain
$ 
⚠ Risks & cautions
What it does

Linux swap (managed via swapon/swapoff and /etc/fstab) extends virtual memory using disk space. On cloud instances, swap files are often preferred over swap partitions. Kubernetes nodes should have swap disabled (swapoff -a) for proper resource accounting.

Examples
swapon --showShow active swap devices and their usage · explain & risk-check →
free -h | grep SwapQuick swap usage summary · explain & risk-check →
fallocate -l 4G /swapfile && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfileCreate and enable a 4GB swap file · explain & risk-check →
swapoff -a && sed -i '/swap/d' /etc/fstabDisable all swap permanently (required for Kubernetes nodes) · explain & risk-check →
sysctl vm.swappiness=10Reduce swap aggressiveness (0-100, lower = prefer RAM) · explain & risk-check →
Pro tip

Set `vm.swappiness=10` on database servers — reduces aggressive swap usage that causes latency spikes. On Kubernetes nodes, set `swappiness=0` or disable swap entirely.

Related
free vmstat sysctl
Open the full explainer →More in Disks & Filesystems

Reference text is hand-written and may be incomplete — check man swap for your version. Test destructive commands on a non-production system first.