I mostly use CPU-bound applications that don’t require much RAM, therefore I was wondering which one to use. I also use an HDD (yes, I know). I’ve been using zswap all this time and I wondered if I wrong all along. It works fine with zswap, but I don’t use much RAM, so I don’t know if it benefits my use case or not.
I Googled it, and everyone claims somewhat conflicting things. Some argue that zram consumes more CPU resources because it compresses everything, while others say that zswap requires more CPU resources without explanation. The only thing I’ve seen to be constant is that zram is faster than zswap because it uses ram which is faster than a HDD/SSD and because of that zram performs far less reads and writes to the disk, which could improve performance compared to zswap.
I have enough RAM for everything I use (I rarely use more than 40% of it), so I was wondering which one to use. Maybe even no zswap/zram?
The only time I would avoid zram is if your CPU is not fast enough to handle the compression. In those cases the compression overhead may cause performance to decrease.
This comment of yours really cleared things up for me. Thank you again!
If you don’t intend to hibernate your computer, make a ~ 6 GB swap file on the fastest drive you have. That’s all you’ll likely need (assuming you don’t have any special requirements). If you have plenty of RAM, you’ll almost never use that swap file, but it will ensure that your RAM usage is efficient (what constitutes “plenty” depends on what you do, of course, but say 16 or 32 GB is what I would consider a lot of RAM in normal circumstances).
Especially on ext4, swap files are usually better than swap partitions because they can be deleted and recreated without repartitioning the drive. Swap partitions are not very flexible.
Unless you regularly experience OoM situations, you shouldn’t worry about swap affecting your SSD lifespan – on systems that have plenty of RAM, the impact of swap is negligible. You want to use the fastest SSD you have for swap, so that you never notice it being used.
And if you don’t have enough RAM, swap won’t really help you in that regard, it’s a very poor substitute for RAM. On systems with insufficient RAM, the best swap will do is prevent the computer from freezing in an OoM situation, giving you some time to gracefully reboot it.
Of course, this is all just my preference, your use case might be different than mine. But I think it’s a sensible starting point if you are unsure what to do.
This command consumes all RAM and swap. Depending on how many apps are running during the test, I can even go up to 120% memory consumption, which basically consumes all swap.
I am not experiencing any issue with that. In fact, I tested this with regular swap on a fast nvme device. The difference is dramatic. With swap on nvme the PC is slowing down dramatically when several GB of swap are being used. Not so with zram. With zram I can still work normally and the PC is still in good response even when I use 10+ GB of swap.
I would always go for zram if you are not hibernating.
I also use zram extensively. However, we are talking about a highly specialized use case here. A case in which we are highly CPU bound and using very little memory. That is not at all typical for a desktop.
If your CPU is already consumed at max and your workload doesn’t benefit from faster swap you shouldn’t use zram because it will add CPU overhead.
That basically tells me that only very little swap is being used and only at rare occasions. Why would that require traditional swap on disc? From my point of view it is perfectly fine to use zram in that scenario and save some disc read/write cycles. It is not only faster with zram but it also extends the life time of the disc.
I am using zram in conjunction with gimp and very big pictures. Sometimes the gimp operations eat up all RAM and swap while it is applying CPU intense filters to the image. With zram this is not a problem at all. With traditional swap on a fast nvme it is not usable. Therefore I do not believe that your CPU load argument is valid.
That is a different use case than the OP. A use case in which you are consuming lots of RAM and lots of CPU.
Obviously, the best solution would be for the OP to actually test both with their specific workload. However, I have seen plenty of reports of zram decreasing performance when the CPU does not have available cycles.
Every workload is different so in the absence of being able to test both it is all speculation.
Yes, but what I am saying is, that even with fully using 16 GB of swap and the PC 100% under load, the zram performance is excellent with minimal delays.
Now assume you only have a few MB to swap out. With zram you will not notice that process. It is undetectable. You will not see any delays in your apps. But you will save read/write cycles to your disc.