In my case, I’m exploring x86 servers to handle my containers and self-hosted applications more robustly, and I’ll cover that journey in a future article.This experience has further reinforced my love for tinkering and optimizing setups, but also reminded me of the limitations of working on minimal hardware. For anyone trying to push the limits of a Pi like I have, increasing swap space can provide short-term relief, but it’s essential to consider upgrading to hardware with more RAM if you’re regularly maxing out your resources. After some investigation, I found that the default 200 MB swap memory was entirely maxed out. sudo reboot now
Table of Contents
Why Increase Swap Space?
After updating the configuration, recreate the swap file to match the new size by running:
Prerequisites
However, this solution is still not perfect, SD card wear and the slower nature of swap memory mean it’s more of a temporary solution than a permanent fix.
- A Raspberry Pi running Raspberry Pi OS.
- Access to a terminal (either directly or via SSH).
- Sufficient free space on your SD card for the additional swap.
Step 1: Turn off the current swap
sudo nano /etc/dphys-swapfile
sudo dphys-swapfile setup
Recently, I became more ambitious, aiming to expand my setup with Nextcloud for private cloud storage and ONLYOFFICE to create a fully self-hosted ecosystem. This is where things got interesting and a bit messy.Adding Nextcloud and ONLYOFFICE to the mix put a significant strain on my Pi 4, leading to slowdowns, occasional freezes, and a slew of input/output errors.
Step 3: Increase the swap size
To follow along, make sure you have:However, keep in mind that an unnecessarily larger swap file can wear down your SD card over time.
Step 4: Apply the new swap size
sudo dphys-swapfile swapoff
Change the value to your desired size. For instance, setting it to 2048 will give you 2GB of swap space:
Step 5: Turn the wwap back on
Next, open the swap configuration file in a text editor. I prefer nano
, but any editor will do:Running a homelab on a Raspberry Pi can be a rewarding yet challenging experience. My journey began with a Raspberry Pi 4 (4 GB) hosting several WordPress websites and a few Ghost blogs. Increasing my Raspberry Pi’s swap space from 200 MB to 2 GB made a noticeable difference. My Nextcloud and OnlyOffice setup has been running more smoothly, with fewer slowdowns and far less system freezing. Although accessing swap memory is slower than RAM, it can help manage resource-intensive applications by preventing crashes or system freezes. Curious, I thought, “Why limit it to just 200 MB? Let’s see what happens if I increase it.” So, I expanded the swap space to 2 GB, and my Pi started running noticeably smoother.
Final Thoughts
sudo dphys-swapfile swapon
Before resizing the swap file, you’ll need to turn off the active swap space. Run the following command in your terminal:Sometimes, a modest hardware upgrade can make all the difference in creating a smoother, more reliable self-hosted ecosystem.Here’s how I did it, and some tips if you’re considering the same.Now, re-enable swap with:CONF_SWAPSIZE=2048
Remember that the size you specify must be available on your SD card. Save your changes by pressing CTRL + X
, followed by Y
, then Enter
to confirm.