Why This Matters
A practitioner argument that Linux distributions' default installer behavior—carving out a fixed swap partition—is outdated, since swap files have matched partition performance for over two decades. For admins and desktop users, swap files are far easier to resize, add, or remove after install, making them the more flexible default.
Key Takeaways
- Swap files have performed on par with swap partitions for 20+ years, yet installers still push partitions.
- Swap files can be added, extended, or removed post-install without repartitioning.
- Setup is a few commands: fallocate (or dd), chmod 0600, mkswap, swapon, plus an fstab entry for persistence.
Stop making swap partitions—use swap files instead!
Swap files have had the same performance characteristics as swap partitions for more than 20 years and yet, linux distributions continue to encourage the use of swap partitions during install.
Swap files are easier to use/add/remove/modify/extend after installation. They're better in every way––use swap files!
Create a swap file.
💡 You can use dd for this too but if your filesystem supports it, fallocate is faster.
fallocate -l 4G /swapfile
Only root should be able to write to the swap file.
chmod 0600 /swapfile
Format the swap file.
mkswap /swapfile
... continue reading