Swapfile really needed? Topic is solved

Having issues with your DietPi installation, or, found a bug? Post it here.
naddel81
Posts: 31
Joined: Sun Jul 21, 2019 12:54 pm

Re: Swapfile really needed?

Post by naddel81 »

Swap is activated by default. Can't dietpi create it when it is needed?
User avatar
Joulinar
Posts: 2300
Joined: Sat Nov 16, 2019 12:49 am

Re: Swapfile really needed?

Post 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:~#
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
naddel81
Posts: 31
Joined: Sun Jul 21, 2019 12:54 pm

Re: Swapfile really needed?

Post by naddel81 »

thanks for testing. maybe it could get implemented into a future release?
User avatar
Joulinar
Posts: 2300
Joined: Sat Nov 16, 2019 12:49 am

Re: Swapfile really needed?

Post 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
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
User avatar
WarHawk
Posts: 622
Joined: Thu Jul 20, 2017 8:55 am

Re: Swapfile really needed?

Post 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)
naddel81
Posts: 31
Joined: Sun Jul 21, 2019 12:54 pm

Re: Swapfile really needed?

Post by naddel81 »

btw: what is "tmpfs 743M 6.9M 737M 1% /tmp"

and why is it over 740Mb big?
User avatar
Joulinar
Posts: 2300
Joined: Sat Nov 16, 2019 12:49 am

Re: Swapfile really needed?

Post by Joulinar »

that's a temporary file system and used by the system/application to store temporary files.
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
naddel81
Posts: 31
Joined: Sun Jul 21, 2019 12:54 pm

Re: Swapfile really needed?

Post by naddel81 »

but why does this write to SD card when gigs of ram are still unused?
User avatar
Joulinar
Posts: 2300
Joined: Sat Nov 16, 2019 12:49 am

Re: Swapfile really needed?

Post by Joulinar »

to which point you are referring?
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
naddel81
Posts: 31
Joined: Sun Jul 21, 2019 12:54 pm

Re: Swapfile really needed?

Post by naddel81 »

to temporary file system. that could be done in RAM when available and only swap to SD card when needed.
Post Reply