I don’t think that is about what you should or should not. The chart gives a bit of simplified picture of what has been discussed earlier in the article. If you want, read the whole article and decide for yourself which one would suit your use case and preferences.
I have switched back to zswap for the time being. I haven’t found any way to “benchmark” the performance of either to see which of them is more performant or more efficient. I haven’t been using my system that heavily either for it to hit the swap. I’ll be monitoring the situation
zram and zswap work only when SWAP usage comes into play. If only RAM is being used and SWAP is not being used then they do not come into play. Is that a correct statement to make?
Also zswap checks if the swap page can be compressed or not. If not then it writes to SWAP file or SWAP partition. While this is not the case with zram. zram always compresses, irrespective of level of compression that it will achieve. So in this case zswap appears to be more efficient than zram but not more effective. Will this also be a correct statement to make?
Efficient in terms of CPU cycles and energy consumed. Effective in terms of not disk thrashing, i.e. NVME or SSD disk thrashing.
If someone works with a large data set (in spreadsheets, json data format, etc) or compiles big programs or works with AI/ML and has experience with zram and zswap setup that would be helpful.
Thanks @dalto. I am thinking more in terms of laptop slowness with time, due to battery degradation. With time all the lithium ion batteries degrade. Thus they are unable to deliver the required level of voltage/power to the CPU to make it function at its best. When that happens, running zram and possibly zswap would also result in issues.
Thanks @ajgringo619, this helps. Would it be possible for you to share some more details of your setup? What type of GPU are you using? Is it integrated with CPU or internal but separate GPU graphics card or is it a eGPU (External GPU kept outside the chassis but connected via Thunderbolt or USB 3.x)?
Does the GPU have dedicated RAM inbuilt or does it share Physical RAM with the CPU?
Did you try to use zswap? Or had both of them working?
@cactux after a period of time, please do update your experience. Also what happens when you use GPU intensive loads or work with large data sets or large files or large work items. Thanks once again for the article it is a gem.
tldr - a single Nvidia GPU (8 GB), desktop system
My original installation had a dedicated swap partition, with zswap enabled. Once I switched to zram, I disabled zswap.
Another thought I want to throw into this discussion: Swapping to a file or a partition is really slow. Regardless if you swap to a fast SSD or NVME: The computer will become really slow when it swaps. May be even to a point where it is unresponsive.
You can try this out with the stress-ng command and monitoring swap usage with your system monitor of choice.
See these instructions from Red Hat:
E.g. My system has 64 GB of RAM with 12 GB of zram swap. I do the stress test with:
This swaps up to 12 GB to zram swap and the computer is still responsive. On the other hand, swapping out 12 GB to a file or a partition takes a few seconds during which the PC may not be responding. You can try this by yourself and feel the difference.
Zram also checks if the content is compressible. If it isn’t then it will be held uncompressed.
It can be useful to be in memory only if there’s lot random access on the dataset. It can also be that your AI/ML app leaks memory like a sieve, so it’s better putting stale memory onto disk eventually.
It depends on setup and workload. If you really want to micro-optimize on that level you have to open a system monitor on your system and look how the system behaves.
True, but in the end we put these in-memory solutions (zswap, zram) in front of the disk-swap to avoid that situation.
It would be interesting to see the result of a similar test in term of system responsiveness for a setup with 8GB RAM and 4/6/8GB Zram.
Also, I don’t think that this test reflects the majority of “real life” use cases where usually almost a negligible amount of pages are swapped out.
I have switched to zswap plus swapfile. I just use my system as I normally would and I am monitoring the swap usage. So far I haven’t noticed any slowdown in the way of system’s operation let alone being unresponsive.
For now I cannot take your categorical statement at face value until I have used this setup for enough long period.
The whole point about zram is to speed up the swap process. If you are swapping just a “negligible amount of data” you will not be able to tell the difference between swapfile, swap partition, zram or zswap. In that case this whole discussion here is pointless.
zram is not “in front of the disk-swap”. zram does not use any disk swap. zswap does use disk swap after compressing swapable pages in memory. zswap is a cache layer for disk swap.
With that in mind I believe zram is faster than zswap. If zswap starts swapping to disc you will likely see a performance drop of your PC.
I would love to read some user reports about zram / zswap comparison with stress-ng.
No I didnt. I leave this up to users who are interested to find the best solution for them.
I have done my testing resp. benchmarking a long while ago. I never considered zswap because i wanted to eliminate any disk involvement because I compared zram with a swap file on NVME and that is a significant performance difference.
My main use case for high RAM usage is photo editing with gimp and darktable. Especially with high res pictures in gimp and multiple layers I can easily saturate my 64 GB RAM. With zram in place I can still work normally when it swaps several GB. That was not possible when I had a swap file.
Your system is not swapping at all. Have you tried to provoke swapping with stress-ng? Lets see how your system behaves when it uses your 15 GB of swap.
Then I don’t understand your categorical statement below since zswap is enabled by default:
It seems to be based on an assumption rather than the result of the test you posted above.
And this one based on a belief?
At any case, there seems to be a tradeoff between higher CPU usage (zram) and slower disk i/o when zswap starts to swap out to the disk.
Then there is also the system configuration (hardware), workload, real life usage etc.
For me, there seem to be many “moving parts” involved to come to a definite conclusion as to which option is “objectively” better, more efficient and so forth.
No. And I don’t think I would do that. I am not interested in “provoking” a situation which has no relevance for my daily usage of my system by filling my zswap and swapfile with “none sense data”.
I am interested to see the difference between these two options in my ordinary day to day usage. So far I haven’t seen any difference.
@cactux
I was just adding my 2 cents here. You do not need to agree.
Here is a summary of my thoughts
*) rotational disk as swap device are a no go because they are too slow
*) SSD and NVME are faster but are aging to fast with heavy swap usage.
*) persistent swap on SSD, NVME or HDD is only mandatory for hibernation
*) zswap uses a persistent swap device after caching pages in-memory. This caching is extending the lifetime of SSD/NVME swap devices. One of the main ideas of zswap.
*) zram is purely in-memory => faster than zswap if lots of swap is needed
*) stress-ng can help to identify best performance solution
It is not a question of agreement or disagreement.
For me it is a question of which of the two options are to be preferred in a “real life” usage where there are many different factors involved: hardware, configuration, workload etc.
Therefore I don’t think that the stress-ng test can be the way to identify the “best performance solution”. Universally and for everybody.
That’s it. And thanks for posting to clarify your thoughts. I appreciate it even though I don’t agree with all of them
Zram doesn’t require disk swap, true, but you can use additional disk swap, either as a writeback device or just as a spill over.
Swapping to disk only affects performance if it can’t be done in the background. stress-ng is an unusual workload that can force that bad performance scenario. If a system isn’t severally memory starved then swapping usually isn’t an instant “half of the RAM” situation though, but a gradual “a few dozen MB”, which will run unnoticed in the background. It depends on the workload, if you’re in a stress-ng situation then prefer zram, sure.
If the OS resp. the kernel is swapping, the amount of data is minimal from kB to a few MB. It happens in the background and all happens unnoticed by the user. If that is what concerns you or what is discussed here in the thread, I am attending the wrong party.
If a RAM hungry applications are swapping the situation is totally different. With blender, video editing or picture editing you can easily bring your PC to a stand still if swap performance is not good.