Raspberry Pi-4 Model-B

Sometimes you just need more SWAP space on your Raspberry Pi. Per default, it is set to 100 MB if I remember correctly, which is low and depending on what you are running on your Raspberry Pi, filled up pretty fast.

One thing to keep in mind, your SWAP should never be higher than your actual RAM though. SWAP is not meant to serve as “extra Memory”, it’s there for cases where your machine might temporarily need a bit more than just what you have for memory.

In my case. it’s Nextcloud. My Nextcloud is running on a 4 GB Raspberry Pi and when I scroll through my images this 4 GB RAM will be used rather fast, depending on how many images are already cached by Redis and how many thumbnails need to be generated. So it’s starting to use SWAP space and I can assure you, the default setting was not enough here and the system ran into an OOM (Out Of Memory) rather fast. Live image manipulation seems to use quite some memory, so increasing the SWAP it was and I opted to set it to 4 GB as well.

First, you need to deactivate the current SWAP.

sudo dphys-swapfile swapoff

Now modify the SWAP size by editing the /etc/dphys-swapfile. You find the variable CONF_SWAPFILE there. Set it to the size you like to have, like so:

CONF_SWAPSIZE=4096

If you plan on using more than 2 GB of SWAP space, you might have to comment in and change the CONF_MAXSWAP variable as well. and set it to the new SWAP size. CON_MAXSWAP is set to 2 GB as default and as the name already suggests, this is the maximum of SWAP space the system will reserve.

Now, re-create the SWAP file with:

sudo dphys-swapfile setup

And start the SWAP again with:

sudo dphys-swapfile swapon

That’s all, quick and easy.

Leave a Reply

Your email address will not be published. Required fields are marked *