Swapfile really needed? Topic is solved

Having issues with your DietPi installation, or, found a bug? Post it here.
User avatar
Joulinar
Posts: 2575
Joined: Sat Nov 16, 2019 12:49 am

Re: Swapfile really needed?

Post by Joulinar »

probably you should have a look what tmpfs is and how it's working

https://en.wikipedia.org/wiki/Tmpfs
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 »

great, so it is a RAMdisk basically. so when that 740 MB RAM space is only used to 1% there should be no need for a swap file, right?
User avatar
MichaIng
Site Admin
Posts: 2422
Joined: Sat Nov 18, 2017 6:21 pm

Re: Swapfile really needed?

Post by MichaIng »

tmpfs is a RAM disk yes, but free tmpfs space and free RAM space are not the same. tmpfs space can be as large as you want it, it doesn't "know" how much RAM is actually available, it will only consume as much RAM as actual file space is used. But RAM of course is used by many other things as well, free and htop can be used to check free/available RAM. So even that the tmpfs shows you plenty of free space, RAM usage could be at its limit because of other processes or background services. Also tmpfs doesn't know about swap, it will simply allocate additional memory as you write files inside. Swapping happens at a different layer, when the kernel recognises that RAM usage comes to its limit and there is some rare used data inside that can be written to disk without affecting performance much (due to low usage of those). On DietPi, we set swappiness=1 (in /etc/sysctl.d/dietpi.conf) which leads to swapping being done as little as possible. 0 would disable it completely, 60 is default on most distros. Using a higher number leads to swapping being done even to make space for file system caching already, so rarely used RAM data is written TO disk to make space for often used files FROM disk, so for performance reasons only. swappiness=1 doesn't rule this out completely, but it will be done very rarely and it's simply the best we can do to reduce disk writes to a minimum while preserving swap as emergency backup memory in case something is consuming unexpectedly much or for peak times, to prevent the "out-of-memory killer" from doing its job ;).

Ah as you asked, /tmp size on DietPi is set to 50% of total memory size (RAM + swap), AFAIK 50% RAM size is default on Debian. However as said its used/free space has nothing to do with actual RAM usage, there are even many other tmpfs mounts that all together provide a much larger "drive space" than actual memory is available ;). Those are simply used for different purpose and all of them have mostly a much larger size than what is ever required, just none of them should be alone larger than total memory.
naddel81
Posts: 31
Joined: Sun Jul 21, 2019 12:54 pm

Re: Swapfile really needed?

Post by naddel81 »

thanks for that huge rundown on information about swap/tmp mechanism in dietpi!!! will sticky this for me and read it again and again.
Post Reply