What swap is, how to see it with free and swapon, how to add a swap file, and what vm.swappiness changes.
Swap is disk space that the Linux kernel uses as an overflow for memory: rarely used memory pages are moved there so RAM stays free for active work. It can be a dedicated partition or a swap file, and it is shown by the commands free -h and swapon --show.
Even with plenty of RAM, swap lets the kernel move idle pages out of memory and gives a buffer before the out-of-memory killer stops processes. Heavy, constant swapping, however, means the machine needs more RAM or fewer workloads.
The kernel setting vm.swappiness (0-200, default 60) influences how readily the kernel swaps compared with dropping file cache. Lower values keep application memory in RAM longer. It is read with 'sysctl vm.swappiness' and set permanently in a file under /etc/sysctl.d/.
A swap file is created, formatted with mkswap, enabled with swapon and added to /etc/fstab to survive reboots. Its permissions must be 600.
sudo dd if=/dev/zero of=/swapfile bs=1M count=2048sudo chmod 600 /swapfilesudo mkswap /swapfilesudo swapon /swapfile/etc/fstabswapon --show and free -h/etc/fstab can stop the system from booting: check the line before rebooting.Last updated: 2026-10-08
How to read df output, why Use% can reach 100% before Avail is zero for normal users, and how to check inodes with df -i.
What a systemd unit is, the common unit types, and how to start, stop, enable and inspect services with systemctl.
How to find what fills a Linux disk with du and the interactive ncdu, with options that stay on one file system.