I have an old laptop here with only 512 MB of RAM. Since a few kernel releases, I am using zram to convert 256 MB of it to a compressed ramdisk which is then used as swap. This has proved to be very successful and the system is much more responsive, (hard-disk-backed) swap usage has gone down considerably, which slowed the system down before.

Since linux 3.0, the kernel also includes cleancache which, using something like zram as a backend is supposed to transparently compress pages from the page cache. As far as I can see this is different from zram.

Should I enable both on my laptop? Or does cleancache actually supersede the zram solution?

Edit: I have found this gentoo forum link, where it seems that I also have to enable CONFIG_ZCACHE which then makes cleancache use zram to obtain something similar to what I had before. So it seems that I enable all of this and do not use zram explicitly afterwards. Can anybody confirm this?

2 Answers 2


Zram creates a block device backed by compressed ram. You can use that block device for swap. Normally memory pressure first results in the cache being discarded, and only after most of the cache has been freed up and memory is still tight does the system start swapping.

CleanCache allows pages from the page cache to be migrated to a back end, such as xen tmem, which is memory managed by the hypervisor and shared between multiple VM guests. The goal of this is to allow multiple VM guests caching the same data to do so using the same ram, instead of each having their own cache with their own copy of the same data.

ZCache is another CleanCache back end. Instead of passing the memory to the hypervisor to hold ( which only applies if you are using a Xen VM environment ), it stores the cache pages compressed in ram, similar to Zram. The difference is that ZCache transparently stores cache pages, but Zram creates a block device that you can use for swap.

If you have memory hungry applications, then you will need swap space to support them, so you will still want to use zram ( likely with a very high swappiness value ). This is because CleanCache only compresses cache pages; application memory has to be sent to swap. If you aren't using all of your memory on applications, then you can use CleanCache with the ZCache backend to make more effective use of the remaining memory for disk caching by compressing the disk cache. You might even use a mix of the two techniques.

  • OK, thank you, so cache pages are only for disk caching, not for application memory. This was not clear to me.
    – lytenyn
    Aug 4, 2011 at 10:02

As an addition to the above answer, also see https://lwn.net/Articles/454795 for a detailed explanation of the technology.

From what I understand, zram will be superseded by frontswap, which is not yet in the mainline kernel but which has the advantage that no fixed swap size has to be configured. This will make it easy to enable both cleancache and frontswap (instead of zram and cleancache, where memory used for zram cannot be used for cleancache).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .