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

Having issues with your DietPi installation, or, found a bug? Post it here.
Post Reply
dpsguard
Posts: 43
Joined: Mon Aug 03, 2020 12:48 am

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

Post by dpsguard »

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
User avatar
Joulinar
Posts: 2300
Joined: Sat Nov 16, 2019 12:49 am

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

Post by Joulinar »

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.
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
dpsguard
Posts: 43
Joined: Mon Aug 03, 2020 12:48 am

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

Post by dpsguard »

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.
User avatar
Joulinar
Posts: 2300
Joined: Sat Nov 16, 2019 12:49 am

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

Post by Joulinar »

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.
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
dpsguard
Posts: 43
Joined: Mon Aug 03, 2020 12:48 am

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

Post by dpsguard »

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.
User avatar
WarHawk
Posts: 622
Joined: Thu Jul 20, 2017 8:55 am

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

Post by WarHawk »

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

https://haydenjames.io/linux-performanc ... wap-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-performanc ... art2-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/ho ... -on-linux/
User avatar
Joulinar
Posts: 2300
Joined: Sat Nov 16, 2019 12:49 am

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

Post by Joulinar »

ZRAM is something on the todo list for long.

https://github.com/MichaIng/DietPi/issues/94
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
robcarr
Posts: 3
Joined: Mon Jul 20, 2020 4:23 pm

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

Post by robcarr »

WarHawk wrote: Thu Aug 13, 2020 7:27 am This guy did a REALLY writup on why you need a swapspace

https://haydenjames.io/linux-performanc ... wap-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-performanc ... art2-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/ho ... -on-linux/
Thanks a lot! I will check out his writeup right now!
Last edited by robcarr on Fri Sep 11, 2020 7:51 am, edited 2 times in total.
User avatar
MichaIng
Site Admin
Posts: 2333
Joined: Sat Nov 18, 2017 6:21 pm

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

Post by MichaIng »

Check out the zram-swap implementation we just added yesterday for next release: https://github.com/MichaIng/DietPi/comm ... 309c6d0d47
User avatar
WarHawk
Posts: 622
Joined: Thu Jul 20, 2017 8:55 am

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

Post by WarHawk »

Nice!
Post Reply