By default Google Compute Engine (Debian) doesn’t come with any swap space. If you have periodic programs that eat a bit more memory (like my backups do) then instead on just adding more physical memory you can add a swap file.
Swaps files are much slower than physical memory, so should be avoided except when it is needed.
Setting up a swap file on Debian on Google Compute Engine is described here
sudo fallocate -l 2G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile sudo swapon -s
To make this permanent add this to /etc/fstab
/swapfile none swap sw 0 0
If you need to resize the swap file
sudo swapoff /swapfile sudo fallocate -l 4G /swapfile sudo mkswap /swapfile sudo swapon /swapfile
How much swap? Well that is down to your system. Maybe start with 1x your physical memory and then run memory diagnostics tools.
by
Tags:
Comments
One response to “Adding Swap to Google Compute Engine”
-
Thanks. Normally, this gets set up when you create a new system, so you don’t think about it. Setting up a gcloud debian VM didn’t prompt for it, so it didn’t get set up.
This saves the day on a minimal gcloud compute instance – lets me keep it a bit longer before upgrading.
Leave a Reply