zram and zswap for making your Linux computer faster

published Mar 12, 2016 10:40   by admin ( last modified Mar 14, 2016 03:01 )

Updated and clarified 2016-03-14

Zram and Zswhap are RAM compressors where your get more space in RAM for using a bit more CPU. This can make your computer handle bigger tasks without slowing down to a crawl or behave erratically.

Zram is supposed to make low memory devices use their memory more efficiently. It is apparently used a lot by e.g. TV manufacturers for their embedded Linuxes. Zram seems to work in such a way as to take RAM away from the computer and set it aside as a swapped RAM disk that uses lzo compression. So it's basically a RAM memory compressor.

Zram does not need a swap partition on a drive and in fact it may behave non-optimally if there is one: First Zram would then fill up, and any pages after that would be swapped to disk, which if we assume a LIFO usage pattern would put all the pages most in demand on the slow disk.

Zswap on the other hand is meant to improve swapping on low-memory systems with rotary hard disks or similar slow swap partitions. It also compresses memory pages and stores them in RAM, but it communicates with swap partitions present on the system and tries to cache in RAM in compressed format the pages most likely to be swapped in again any time soon.

Zswap probably should do good on any-sized system strapped for RAM with a slow swap disk. Now trying it on an 8GB system.

This is what it looks like after having run for a while on an 8GB system that hasn't been restarted since the install of zRam. It should have kicked in working, and it seems like it has shrunk the RAM use quite drastically and the swap just showing old pages since before zRam kicked in. Or I am misunderstanding something about its use. I think zRam is its own swap, but it does not show up when doing "swapon -s"

Increased Performance In Linux With zRam (Virtual Swap Compressed in RAM) ~ Web Upd8: Ubuntu / Linux blog

kernel - zram vs zswap vs zcache Ultimate guide: when to use which one - Ask Ubuntu

However zswap has a chequered history of being available or not depending on kernel build and is regarded as a bit unexplored:

kernel - How can I enable zswap? - Ask Ubuntu

Zswap - ArchWiki

Does 'Zswap' Really Improve Responsiveness ? (Ubuntu 13.10)

kernel - How to verify zswap running? - Ask Ubuntu

You could also go and borrow RAM from another machine with https://oss.oracle.com/projects/tmem/dist/files/RAMster/ramster-howto.txt whiich seems to be a part of the Zcache stuff. However you are unlikely to get better bandwidth than from a local SSD methinks.