Why do I need swapfile on a 1GB RPi3B+?

Folks, I have light knowledge of Linux, but my understanding was that OS creates a swap space on hard drive (in this case SD card) to allow it to use it as virtual RAM extension just in case. The RPi 3 with 1GB of RAM running just the Pi-hole has created a swap file of 1072MB on SDcard. My question will be, do I really need the swapfile for my use case and what will happen if I simply disable it? I believe disabling it will also help unnecessary wearing out of SDcard. I looked into the drive manager and recommended value is 1 / auto and it sets it as 2GB-RAM. There is option to disable it by setting it to zero or to then manually set it to value 2.

Similarly for a 2GB RPi4, there should then really be no need for a swapfile, if I am only running couple of applications.

Looking forward to some advice.

Thanks

Hi,

many thanks for your message. Basically SWAP setting depends on your application and usage. If you just running PiHole, it could be ok to disable SWAP as it should not use that much. However you never know if there are other processes, like updates, who might need more RAM. I would recommand to use free -m (available memory) or htop to check current usage and then to assure that total memory (including swap) is at least double of size of what is currently used, to cover peaks.

Thank you as always for your very prompt support Joulinar.

In addition to Pi-hole, I will have the OpenVPN to act as client to Pi-VPN server. Plus XRDP for occasional login that needs http into the wireless AP or to see the Pi-hole stats. On Pi-hole, I will also disable query logs (hopefully that will stop writing unnecessary logs for my application). All this to try to increase the lifespan of microSDCARD (using Sandisk Edge A1) to 5 years. And a small UPS also being installed.

And once everything is working great and troublefree, I intend to not have any automatic updates enabled. In such cases, I am not sure if I need to use the SWAP space especially as I will be using the 2G RAM RPi 4B. If this was a mainly desktop use, then yes, just like a regular windows PC, even with typical 8GB of RAM, I will enable virtual / swap memory.

maybe let it run for a while and use free -m to check how it goes. If swap stays at 0, it should be save to disable it.

Appreciate again.

yes, it makes full sense to watch it for a while and then if swap is not seen used, then disable it.

Stay well.

This guy did a REALLY good writup on why you need a swapspace

https://haydenjames.io/linux-performance-almost-always-add-swap-space/

Even a compressed RAM swapspace will help alot

Look into putting ZRAM and ZSWAP on the distro and setup even a small one will help

https://haydenjames.io/linux-performance-almost-always-add-swap-part2-zram/

I actually went in a tweaked a setting to literally make a 512MB RAM system have 256 available RAM (used 1/2 to create the compressed ZRAM/ZSWAP partition) then compressed zswap to be 3X the “used space” and then turned swappiness up…and it helped immensely not only in lack of swapping to an SD card but actually increasing “available” RAM in the system

Since dietpi is a “debian based distro”
This might help
https://www.techrepublic.com/article/how-to-enable-the-zram-module-for-faster-swapping-on-linux/

ZRAM is something on the todo list for long.

https://github.com/MichaIng/DietPi/issues/94

Check out the zram-swap implementation we just added yesterday for next release: https://github.com/MichaIng/DietPi/commit/60666cac555a8be823191f9244d41a309c6d0d47

Nice!