How to Increase the Swap Size on OpenBSD
To increase the size of the swap on my OpenBSD Virtual Private Server with the help of a swap file, I used the following commands:
# create file and set permissions
doas dd if=/dev/zero of=/home/swapfile bs=1m count=512
doas chmod 600 /home/swapfile
# activate swap (swapon)
doas swapctl -a /home/swapfile
# make permanent
echo '/home/swapfile none swap sw' | doas tee -a /etc/fstab
I used the /home partition for the swap file, since it was the one with the most free disk space on my tiny VPS.
The new amount of 768MB is available without a reboot and can be verified using e.g. swapctl or top.
$ swapctl -lk
Device 1K-blocks Used Avail Capacity Priority
/dev/sd0b 262144 13488 248656 5% 0
/home/swapfile 524288 13956 510332 3% 0
Total 786432 27444 758988 3%/dev/sd0b is the 256 MB swap that was automatically set up during installation (sticking mostly to defaults).
It does not hurt to verify the line landed in fstab.
$ tail -1 /etc/fstab
/home/swapfile none swap swOptionally one might reboot the machine and verify the expected swap size.