Check
free -h– theMem(RAM) andSwaprows.swapon --show– empty output means there is no swap.
Create
Connect over SSH asroot: Connection.
-
File – 2 GB:
No
fallocate– do the same withdd,count=2048withbs=1Mgives 2 GB: -
Permissions – root only, otherwise the system refuses the file:
-
Format and enable:
Check:
swapon --showandfree -hshow the swap. -
At boot – a line in
/etc/fstab:There must be only one such line, check:grep swapfile /etc/fstab. Duplicates break the boot.
How much
- 1–2 GB RAM – swap equal to RAM.
- 4–8 GB RAM – 2–4 GB.
- 16 GB RAM or more – 2–4 GB is enough.
Swappiness
vm.swappiness from 0 to 100: how eagerly the kernel moves pages to swap. The usual value is 60, 10 suits a server better: swap kicks in only when memory really runs out.
-
Current value:
-
Apply now:
-
Keep after reboot: