// learn Β· linux Β· rhcsa Β· 8 min

Linux swap space.

When RAM fills up, swap is the disk-backed safety net. Watch RAM and swap bars fill, see the difference between a swap file and a swap partition, and learn the one tunable (swappiness) that decides how eagerly the kernel uses it.

Linux swap space animated tutorial. What swap is, swap files vs swap partitions, mkswap and swapon, persistent activation via /etc/fstab, and the vm.swappiness tunable. RHCSA EX200 ready.
// swap space

Swap is the disk-backed safety net when RAM fills up. Watch RAM and swap bars fill, see the file vs partition variants, and tune swappiness.

// before you start
you should know
  • Β·Comfortable with df / mount / fstab basics
  • Β·Know what a block device (e.g. /dev/sdb1) is
  • Β·Helpful: kernel-parameters lesson (sysctl)
by the end you'll

Add swap either as a file or partition, persist it in fstab, and tune vm.swappiness for the workload.

pace: 8 minutes

swap β€” step 1 / 6 Β· the safety net
RAM (8 GB)70%
swap0%

What swap is for

Swap is disk space the kernel can use as overflow RAM. When physical memory fills, the kernel pages cold (rarely-accessed) memory out to swap, freeing RAM for hot pages. It's not a substitute for more RAM β€” disk is orders of magnitude slower β€” but it prevents the dreaded OOM killer from shooting your processes the moment RAM is full.

$free -h
$swapon --show
$cat /proc/swaps
// key insight

Swap is a safety net, not extra RAM. Heavy swapping always means "buy more RAM or fix the workload" β€” but having SOME swap is almost always better than running with none, because the kernel uses it to evict truly cold pages and free RAM for what matters. Tune swappiness for the workload; persist via fstab; never forget to chmod 600 a swap file.

// exam-ready Β· swap commands
$free -h
$swapon --show
$cat /proc/swaps
$mkswap /path
$swapon /path
$swapoff /path
$swapon -a / swapoff -a
$fallocate -l 2G /swapfile
$chmod 600 /swapfile
$blkid /dev/sdb1
$UUID=... none swap defaults 0 0
$sysctl vm.swappiness
$sysctl -w vm.swappiness=10
$/etc/sysctl.d/99-swappiness.conf
$vmstat 1
$OOM killer
// check yourself
4 quick questions
Q1

Your server is swapping heavily and getting slow. Adding RAM isn't possible right now. What single tunable might reduce paging?

Q2

You created a swap file at /swapfile and ran swapon. It works now, but disappears after reboot. Why?

Q3

Why chmod 600 on a swap file?

Q4

Difference between a swap partition and a swap file?

These aren't graded β€” they're just for active recall, which is what actually makes the lesson stick.

🎚️
// how to persist tunables

Kernel parameters & tuned

vm.swappiness is one of hundreds of sysctl tunables. Learn the runtime-vs-persistent pattern and how tuned bundles them.

open β†’
// more in linux

keep going β€” these pair well with what you just learned.

see all linux β†’
back to RHCSA trackall lessons