Page 2 of 3

Re: Swapfile really needed?

Posted: Sat Aug 29, 2020 8:13 pm
by naddel81
Swap is activated by default. Can't dietpi create it when it is needed?

Re: Swapfile really needed?

Posted: Sat Aug 29, 2020 10:56 pm
by Joulinar
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.

Code: Select all

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

Code: Select all

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:~#

Re: Swapfile really needed?

Posted: Sun Aug 30, 2020 12:26 am
by naddel81
thanks for testing. maybe it could get implemented into a future release?

Re: Swapfile really needed?

Posted: Sun Aug 30, 2020 12:44 am
by Joulinar
within the next release, DietPi will implement ZRAM. Some kind of compressed SWAP file, that should reduce disk space usage.

https://github.com/MichaIng/DietPi/pull/3714

Re: Swapfile really needed?

Posted: Mon Aug 31, 2020 9:40 am
by WarHawk
Joulinar wrote: Sun Aug 30, 2020 12:44 am within the next release, DietPi will implement ZRAM. Some kind of compressed SWAP file, that should reduce disk space usage.

https://github.com/MichaIng/DietPi/pull/3714
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

Code: Select all

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)

Re: Swapfile really needed?

Posted: Mon Aug 31, 2020 10:50 am
by naddel81
btw: what is "tmpfs 743M 6.9M 737M 1% /tmp"

and why is it over 740Mb big?

Re: Swapfile really needed?

Posted: Mon Aug 31, 2020 10:59 am
by Joulinar
that's a temporary file system and used by the system/application to store temporary files.

Re: Swapfile really needed?

Posted: Mon Aug 31, 2020 9:54 pm
by naddel81
but why does this write to SD card when gigs of ram are still unused?

Re: Swapfile really needed?

Posted: Mon Aug 31, 2020 10:21 pm
by Joulinar
to which point you are referring?

Re: Swapfile really needed?

Posted: Tue Sep 01, 2020 7:55 am
by naddel81
to temporary file system. that could be done in RAM when available and only swap to SD card when needed.