Sounds interesting.
In this scenario: do you have zram set as your sole swap device or do you have a swap partition/swapfile available in addition to that?
Itās a good idea, though it depends on the situation. If your OS truly uses all the RAM, then yes, this could bear its own issues. However, if a fraction of the available RAM is usually reservered, though not āin useā, then it shouldnāt cause such issues, I think.
Not sure. Maybe, if you are highly optimising your situation, you might do something even smarter than what the computer does. Iām not sure about that.
The amount of ram used varies dynamically, depending on what software the user is running.
There can be times when it runs out of ram and needs to swap, even when the OS only uses a small fraction of ram when idle.
My main PC has 64Gb of ram, and I have succeeded in making it swap by running one very large process. So I favour a swap partition, but everyones situation is different.
No - have disabled swap⦠part of the reason for the exercise, was to avoid swap, itās slow, and it wears out storage (in this case SD Card which have a finite number of writes - SSDās are the same - finite number of writes).
I often disable swap⦠Iām not using it on my 32 GB Ryzen desktop machine, Iām not using it on my RPi4B⦠I donāt know where, or care, to know, where / how MacOS does swap (but both only have 8 GB RAM)
Iāve never hit an issue where Iāve run out of RAM on a 16 GB machinesā¦
I can see where Iām running a massive database or something - sure - Iāll need swap⦠But I donāt with my desktop machine, or the headless Pi 4 server, or my headless Pi Zero 2Wā¦
Damn - Iāve got a pair of unused 16 GB DDR4 (and 4 x 4 GB DDR4) - but - I recently upgraded my RAM to much higher clockspeed, and it does make a difference, Iām not going to hobble that advantage by adding much slower RAM just to get to 64 GB RAM⦠I guess I should try and sell it but Iām incredibly lazy and just canāt be arsedā¦
If this machine was running lots and lots of VMās yeah⦠Iād want 64 GB or moreā¦
But 32 GB is plenty for my desktop experience - and - my AMD GPU has 8 GB DDR5⦠so in essence Iām running with 40 GB of RAMā¦
When you say āIf your OS truly uses all the RAMā ā¦
⦠do you mean the āpureā OS itself, i.e. after reboot/fresh boot without starting anything by the user
or:
the OS with applications running, like firefox etc.
Iām talking about RAM usage in general. It is really hard to distinguish what is using how much. You can look in htop and see numbers, but itās still not the entire truth always. For example, if a program uses 10MB, it does not sound like much. But what if that program starts 100 such processes? (Which is entirely normal.) Then you have to multiplay 10*100MB, plus account for other overhead created by so many processes, etc.
Or what if you run a script? Do you count in the interpreterās RAM usage or only what the script itself computes?
Itās all not so easy. This is another reason, why I would recommend against looking too extremely into precise RAM numbers and then changing everything based on a couple of RAM numbers.
One of the stupidest things we see a lot are minimalism fanatics, who open free -h once for a second, look at the numbers and say āah, this OS is using too much RAM, why does it use so much RAM, I need something more minimal!!!ā. This is just bad and does not reflect reality, at all.
Yes, free shows RAM usage, but you also have to know how those numbers are created. What they mean. If they are actually that high or if it just feels high, because of things the user looking at it does not know.
So, I would recommend taking any RAM usage number with a big ball of salt. Itās best to look at it in ballparks.
Are you over 10GB usage? Are you under 20 GB of usage? Or do you only use 4GB of RAM?
These are more appropriate questions, because they do not focus too much on precise numbers, which are often not as bad as they seem.
Thanks a lot @Akito for your very detailed account.
Right. Thanks.
That“s certainly good advice.
In actual fact most of the time I“m happy with my 1GB swapfile as it is.
Having 4 GB of RAM available on my system the article I was referring to in post #1 (āEnabling RAM Compression on Lubuntuā) got me intrigued ⦠but rather out of curiosity.
I still have to look into @nevj “s suggestion of trying zswap instead.
Quite. Thanks.
O.K. I ask myself this question⦠and can answer: Yes, I use 4GB of RAM.
To be more precise: I“ve got 4GB of RAM available.
I think thereās some confusion here - I donāt think zswap is stored on disk (neither is zram)ā¦
zswap is a virtual filesystem in RAM, with on the fly compression⦠itās a ācacheā for swap on disk storageā¦
i.e. its sorta / kinda like a āramdiskā maybe? Anyway - I guess it can also save some read/write I/O as a compressed cache - AFAIK the āmemcacheā in the Linux kernel isnāt compressed - but I could be wrong.
Neither zswap or zram actually give you more RAM, but zram comes closer to that goal than zswap maybe?
I also fondly remember MS-DOS days - when you might have a whopping 8 MB of RAM, and an O/S that only went as āhighā as 640 K (whoād ever want or need more?), and you might have a game that might take advantage of some memory extenions (e.g. himem.sys up to 1024 kb) but would NEVER need anywhere near 8 MB, and the whole game EXE and libraries were like less than 4 MB - youād setup a 4 MB RAM disk, copy the game binaries there, and run it off RAM disk - instead of running it off like 1200 RPM piece of crap magnetic hard driveā¦
Here :
Though, as a result of its design, at least one already existing swap device is required for zswap to be used.[15]
Well, as I haven“t done anything noteworthy after rebooting zswap didn“t have much to do, I guess .
The key parameters to look out for are stored_pages which is the number of compressed pages and written_back_pages which is the number of pages which have been written out to the swap file.
(source: see above)
Hi Rosika,
These things take time. Do not ever feel compelled to try something, just because I commented on it.
You need to make it work hard and see if zswap does the right thing
Might hive it a try in Debian in my small desktop. It has only 8Gb so I can make it swap easily
Regards
Neville
That“s really alright. I“m very glad of any comments posted by you.
Yes, that“s perhaps the hardest part - evaluating whether zswap does the right thing.
Perhaps I“ll make it work on my host system (Lubuntu 20.04.5 LTS) and try it there.
ItĀ“s my daily driver after allā¦
I have just 4 GB RAM on Lubuntu. So swapping incidences should occur even more frequently I guess.
just one additional question before I try setting up zswap on Lubuntu.
In the past I used to manually clear my swapfile (every now and then) - for no particular reason actually - with sudo swapoff -a and then switching it on again with sudo swapon -a.
I wonderā¦
If I have zswap enabled by default - what would be the consequences of temporarily turning off my swapfile
I mean zswap still depends on a swap partition or swapfile after allā¦