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 and format the swap file.
mkswap --size 4G --file /swapfileTip
--file requires util-linux 2.40 or newer. mkswap creates the file, sets mode 0600, preallocates the blocks (ftruncate + posix_fallocate), and, since 2.41, sets the nocow attribute so this also works on Btrfs. Thank @cesarb from HN for the tip!
- Enable it.
swapon /swapfile- Make it persist across boots.
echo "/swapfile none swap defaults 0 0" >> /etc/fstab
probably add setup for /etc files for starting system