Swap gives Linux somewhere to put memory pages when physical RAM runs out — and whether to use a dedicated partition or a swap file is a genuinely practical, not just academic, decision.
# Modern distros default to swap files - genuinely easier to resize sudo fallocate -l 4G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile # Make it permanent echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab # Check current swap usage swapon --show free -h
Swap File vs Swap Partition
- Swap partition — a dedicated disk partition, slightly more performant historically (marginal on SSDs today), fixed size requiring repartitioning to change
- Swap file — a regular file treated as swap space, trivially resizable, the modern default on most distros (including Ubuntu’s installer)
On modern SSDs, the performance difference between the two is negligible — swap files have become the practical default specifically because resizing them is a two-command operation, versus repartitioning a live disk for a swap partition.