In defense of swap
Published:
"In defense of swap: common misconceptions" is an article by Chris Down, a Linux kernel developer at Meta. Turns out, swap is actually useful and not just a crutch, or a last-ditch rescue mechanism for low-memoty situations.
After reading the article I made some space for swap on my WD_BLACK SN7100. The NVME drive is way faster than my other disks (I am still rolling plenty of HDDs), so it was a natural choice for swap. Before configuring swap, I first had to resize one btrfs-formatted LVM logical volume.
btrfs filesystem resize '-64G' /var
Resizing a btrfs filesystem can be done online, without unmounting it. Have I mentioned that I really like btrfs yet? No? Then let me tell you, dear reader, that I really like btrfs.
lvreduce --resizefs --size '-64G' /dev/wdblacksn7100/var
Despite resizing the filesystem contained by the volume manually before
resizing the volume itself, lvreduce complained and would not
proceed without the --resizefs flag.
mkswap /dev/wdblacksn7100/var
swapon /dev/wdblacksn7100/var
This is an ad-hoc change to a running system.
To make it permanent you have to change the /etc/fstab file.
UUID=deadbeef-c0ff-eeba-be01-dead2137f00d none swap defaults 0 0
You should check what UUID your swap partition has and change it, but you can leave every other value as it is in the example (learn what they mean by reading the fstab(5) manpage). You can find out what the UUID of your swap using lsblk(8).
lsblk -o FSTYPE,UUID | grep swap
After you have configured swap in the filesystem table, you are done.