Hi at all,
I have a Pi 2B and only use it for Phiole and wireguard. It is installed on a 4gb Card. The Pi tells me there is not enough space when updating. Can I simply disable swap file? Why ist 4gb not sufficient?
Best wishes.
Hi at all,
I have a Pi 2B and only use it for Phiole and wireguard. It is installed on a 4gb Card. The Pi tells me there is not enough space when updating. Can I simply disable swap file? Why ist 4gb not sufficient?
Best wishes.
Hi,
many thanks for your message. Basically SWAP setting depends on your application and usage. By default, DietPi will create a swap file fir SBC running less than 2GB RAM. If you just running PiHole + Wireguard, 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 recommend 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. Best is to perfrom checks not directly after reboot, as for sure there not much RAM uses. Therefore let it run for some days and check how it looks like.
Regarding disk space, you can have a look using df -h how much space is left on your device. For safety reason, DietPi expect at least 500 MB free space if you run dietpi-software
thanks for your help. currently I have this situation:
https://abload.de/img/dietpigwjfu.png
I guess it is not enough space for an update. I only have pihole and wireguard installed. shouldn’t there be more space left?
yes, the amount of used space is quite normal and similar to my system
root@DietPi4:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 29G 3.5G 25G 13% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 1.6M 1.9G 1% /dev/shm
tmpfs 1.9G 8.3M 1.9G 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 2.0G 0 2.0G 0% /tmp
tmpfs 50M 28K 50M 1% /var/log
/dev/mmcblk0p1 253M 55M 198M 22% /boot
root@DietPi4:~#
Anyway, let’s check your memory usage and if we can reduce SWAP. Pls can you post free -m
problem is that I only have 400 MB available now
there you go:
Hi,
there is no need to do screen prints. You are able to copy the content from putty directly. Just mark it in putty and paste it here
problem is that I only have 400 MB available now
Not really a problem, just a small challenge
let’s reduce your SWAP file down to 512MB. pls do
/boot/dietpi/func/dietpi-set_swapfile 512
You should have sufficient free space now
great, but would this here help aswell?
→ https://www.zdnet.com/article/raspberry-pi-extending-the-life-of-the-sd-card/
not sure what you mean exactly. But DietPi is using quite some tmpfs already
root@DietPi3:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 15G 1.2G 13G 9% /
devtmpfs 456M 0 456M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 13M 476M 3% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 488M 0 488M 0% /sys/fs/cgroup
tmpfs 50M 8.0K 50M 1% /var/log
tmpfs 743M 0 743M 0% /tmp
/dev/mmcblk0p1 253M 55M 198M 22% /boot
root@DietPi3:~#
I thought using RAM and completely abandon swap file unless it is needed (RAM is full). that would save space.
Well SWAP was used on the picture you shared
https://abload.de/img/dietpi2k5j98.png
That’s why we reduced it by 50% to gain space but still have some SWAP file if needed.
Swap is activated by default. Can’t dietpi create it when it is needed?
A swap file is created automatically for systems running less than 2GB memory. But you are able to change swap file size depending on your needs. And it’s not DietPi who needs the swap. This depends on your applications and running processes on your system. In theory you could manage the swap automatically by using swapspace. But I never tested it nor is it implemented in DietPi.
https://packages.debian.org/en/buster/swapspace
I did some quick and dirty testing. The tool was starting with a smaller swap file. The more I was forching the system to swap (using stress tool), even more files got created. Bit it did not seems to remove the files as soon as the high load situation ends. Maybe it will take some time.
root@DietPi3:~# swapon -s
Filename Type Size Used Priority
/var/lib/swapspace/1 file 255056 0 -2
root@DietPi3:~#
root@DietPi3:~# stress --vm-bytes $(awk '/MemAvailable/{printf "%d\n", $2 * 0.3;}' < /proc/meminfo)k --vm-keep -m 4 --timeout 60
stress: info: [506] dispatching hogs: 0 cpu, 0 io, 4 vm, 0 hdd
stress: info: [506] successful run completed in 60s
root@DietPi3:~#
root@DietPi3:~# swapon -s
Filename Type Size Used Priority
/var/lib/swapspace/1 file 255056 19572 -2
/var/lib/swapspace/2 file 372308 872 -3
root@DietPi3:~#
root@DietPi3:~# stress --vm-bytes $(awk '/MemAvailable/{printf "%d\n", $2 * 0.4;}' < /proc/meminfo)k --vm-keep -m 4 --timeout 60
stress: info: [516] dispatching hogs: 0 cpu, 0 io, 4 vm, 0 hdd
stress: info: [516] successful run completed in 60s
root@DietPi3:~#
root@DietPi3:~# swapon -s
Filename Type Size Used Priority
/var/lib/swapspace/1 file 255056 18792 -2
/var/lib/swapspace/2 file 372308 436 -3
/var/lib/swapspace/3 file 392508 648 -4
root@DietPi3:~#
EDIT:
Ok after some time, swap files getting removed again until they are all gone
root@DietPi3:~# swapon -s
Filename Type Size Used Priority
/var/lib/swapspace/1 file 255056 17144 -2
/var/lib/swapspace/2 file 372308 348 -3
/var/lib/swapspace/3 file 392508 336 -4
root@DietPi3:~# htop
root@DietPi3:~# swapon -s
Filename Type Size Used Priority
/var/lib/swapspace/1 file 255056 17144 -2
/var/lib/swapspace/2 file 372308 348 -3
/var/lib/swapspace/3 file 392508 336 -4
root@DietPi3:~# swapon -s
Filename Type Size Used Priority
/var/lib/swapspace/1 file 255056 16884 -2
/var/lib/swapspace/2 file 372308 296 -3
root@DietPi3:~# swapon -s
Filename Type Size Used Priority
/var/lib/swapspace/1 file 255056 16884 -2
/var/lib/swapspace/2 file 372308 296 -3
root@DietPi3:~# swapon -s
Filename Type Size Used Priority
/var/lib/swapspace/1 file 255056 16852 -2
root@DietPi3:~# swapon -s
root@DietPi3:~#
thanks for testing. maybe it could get implemented into a future release?
within the next release, DietPi will implement ZRAM. Some kind of compressed SWAP file, that should reduce disk space usage.
AWESOME!!!
Unfortunately I am using Orange Pi’s right now [specifically and OPi Lite] (so an armbian build)…and it comes standard…however I have tweaked out my build
warhawk@orangepilite:~$ cat /proc/swaps
Filename Type Size Used Priority
/dev/zram1 partition 1513472 66560 5
warhawk@orangepilite:~$ free -h
total used free shared buff/cache available
Mem: 492Mi 200Mi 85Mi 5.0Mi 206Mi 280Mi
Swap: 1.4Gi 65Mi 1.4Gi
Yeah…it seems ALOT overkill…but the system is stable as a rock…and NO writes to the SD Card (I am using a Sandisk Ultra A1 of course)
It’s running one of my 3D printers and sometimes octoprint can be a resource hog (especially when it’s calculating print time on a fresh .gcode upload)
btw: what is “tmpfs 743M 6.9M 737M 1% /tmp”
and why is it over 740Mb big?
that’s a temporary file system and used by the system/application to store temporary files.
but why does this write to SD card when gigs of ram are still unused?
to which point you are referring?
to temporary file system. that could be done in RAM when available and only swap to SD card when needed.