I think my little VPS is OOMing
My IONOS VPS has been suddenly going unresponsive lately. I told Gemini I have this VPS for editing files in Neovim, and it suggested I might be running out of memory, especially if I’m running a TypeScript LSP, which is known for hogging lots of resources. It seems to have happened at least a couple times when I’m editing a .ts file, so that’s a good theory.
Add a swap file
The first thing I did was add a swap file so memory can spill over onto disk if necessary.
Gemini said to do this with fallocate or dd depending on your filesystem, but after looking into it, I decided to just use dd to be safe.
See this Ask Ubuntu thread.
Here’s what I did:
# create the swap file
sudo dd if=/dev/zero of=/var/cache/swapfile bs=1K count=4M
# only root should be allowed to read/write the file, since it can hold sensitive data
sudo chmod 600 /var/cache/swapfile
# format the file as swap
sudo mkswap /var/cache/swapfile
# activate the swap file
sudo swapon /var/cache/swapfile
# check the swap status
sudo swapon --show
free -h
Apparently the swap file won’t automatically get re-mounted after system restart, so to fix that, I edited /etc/fstab and added this line to the bottom:
/var/cache/swapfile none swap sw 0 0
/swapfileis the swap file path.noneis the mount point (swap doesn’t get a standard folder mount point).swapis the filesystem type.swis the mount options, telling the system this is for swap.0 0are the Dump and Pass options, used for filesystem backups and checks; swap doesn’t need them, so they are set to zero.
If you see any issues with any of the above, please email and educate me!
For some smarter people covering these topics, see:
- swap - fallocate vs dd for swapfile? - Ask Ubuntu
- What is swap and how large a swap partition should I create? - Ask Ubuntu
- An introduction to the Linux /etc/fstab file - Red Hat
- Adding a new swap file. How to edit fstab to enable swap after reboot? - Ask Ubuntu
I believe this will fix the OOM problem, but it’s got me thinking about alternatives to my current rig. More to come on that soon.
- ← Previous
Two-sentence post: Mosh is cool