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

If you see any issues with any of the above, please email and educate me!

For some smarter people covering these topics, see:

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.