Zswap, Zram, Zcache desktop usage scenarios

7,193

The best way I can attempt to answer those questions is to say what those three actually are.

zRAM

zRAM is nothing more than a swap device in essence. The memory management will push pages out to the swap device and zRAM will compress that data, allocating memory as needed.

Zswap

Zswap is a compressed swap space that is allocated internally by the kernel and does not appear as a swap device. It is used by frontswap in the same way a swap device may be used, but in a more efficient manner.

Zcache

Zcache is the frontend to frontswap and cleancache.

Zcache supersedes zRAM so you don't really want both of them fighting over resources, although there is some talk about how the two can work well together given the right circumstances. For now I wouldn't bother trying and leave it up to the experts to figure that one out.

Some reading:
Cleancache vs zram?
https://lwn.net/Articles/454795/
https://www.kernel.org/doc/Documentation/vm/zswap.txt
http://www.zeropoint.com/Support/ZCache/ZCachePro/ZCacheAdvantages.html

Personally, I have just disabled zRAM and enabled Zcache on all my systems that have a new enough kernel (zRAM is still enabled on the Android devices).

As for performance: that's something you'd have to look into yourself. Everybody is different. In theory, though, Zcache should be much more memory efficient than zRAM and it works on two levels (frontswap and cleancache), and it can page out to a swap device as needed (on the hard drive, for example). You can also choose which compression algorithm to use, should it be using too much CPU (which I can't imagine it will).

Update: Zcache has been removed from the 3.11 kernel (for now), so zRAM has again become the only option in newer kernels. https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1256503/comments/3 http://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/commit/?id=96256460487387d28b8398033928e06eb9e428f7

Share:
7,193

Related videos on Youtube

Warren
Author by

Warren

Updated on September 18, 2022

Comments

  • Warren
    Warren over 1 year

    I've been trying to understand the difference in use cases for Zswap, Zram, and Zcache. Apologies in advance for the long/slightly sloppily worded question. I've done a bunch of googling, and I understand that zram is basically a block device for compressed swap, while zswap compresses in kernel using the frontswap api. It appears that one advantage of zswap is that it can move some pages to a backing swap when under pressure in a LRU manner, while zram can't do that (please confirm, not sure if this is true).

    So here's my question: 1.) As a desktop user, what is the performance difference between zcache/zswap/zram, especially zswap and zram? For example, is one much better/worse at memory fragmentation (the kind that leads to excessive memory usage and waste)?

    Bonus question: 2.) Is there a likely ideal combination of the above (say, zram+zswap, or zram+zcache) for desktop performance (including responsiveness of desktop, plus minimally disruptive swap behavior and sane memory management)?

    *Citation of sources is greatly appreciated.

    I should add that I'm a decently experienced Linux user (5 years), and have tried to really understand how my system including the kernel works. However, I'm not a programmer, and only have very basic programming knowledge (3 credits college course). But be technical if you need to; I'll parse your meaning on my own time.

    System specs:

    Linux Mint 15
    Processor:Core 2 Quad 6600 (2.4ghz)
    Ram: 8G
    linux kernel: liquorix 3.11 series
    Storage: 128 GB SSD, 1TB HDD 5400rpm
    

    No "buy more ram" comments, please! I've maxed the ram on this motherboard, and have a $0 upgrade budget for the foreseeable future. However I like to keep open memory intensive programs (multiple browsers being the main consumers of my ram) so I don't mind swapping within reasonable performance degradation limits.

  • Ken Sharp
    Ken Sharp over 8 years
    Zswap is enabled in the latest kernels by adding zswap.enabled=1 to the Linux command line.
  • Mikko Rantalainen
    Mikko Rantalainen almost 4 years
    Technically zram is not a swap device. Instead it's a compressed ramdrive that can be used as any other block device. Formatting it as swap device and using it as swap is just one use case for zram.