|Type||Linux kernel features|
|License||GNU General Public License|
zram, formerly called compcache, is a Linux kernel module for creating a compressed block device in RAM, i.e. a RAM disk, but with on-the-fly "disk" compression. The block device created with zram can then be used for swap or as general-purpose RAM disk. The two most common uses for zram are for the storage of temporary files (/tmp) and as a swap "disk". Initially, zram had only the latter function, hence the original name "compcache" ("compressed cache").
After four years in Linux' driver staging area, zram was introduced into the mainline Linux kernel in version 3.14, released on March 30, 2014. From Linux kernel version 3.15 onwards (released on June 8, 2014), zram supports multiple compression streams and multiple compression algorithms. Compression algorithms include LZ4 and LZO. The default is LZ4, which is faster at compressing/decompressing, but does not compress quite as efficiently as LZΟ. Like most other system parameters, the compression algorithm can be selected via sysfs.
When used as a compressed swap space, zram is similar to zswap, which is not a general-purpose RAM disk, but rather an in-kernel compressed cache for swap pages. However, unlike zswap, zram cannot use a hard disk as a backing store (currently it's possible see patch for CONFIG_ZRAM_WRITEBACK), i.e. it cannot move less-frequently used pages to disk. On the other hand, zswap requires a backing store, while zram does not.
When used for swap, zram (like zswap also) allows Linux to make more efficient use of RAM, since the operating system can then hold more pages of memory in the compressed swap than if the same amount of RAM had been used as application memory or disk cache. This is particularly effective on machines that do not have much memory. In 2012, Ubuntu briefly considered enabling zram by default on computers with small amounts of installed RAM.
A compressed swap space with zram/zswap also offers advantages for low-end hardware devices such as embedded devices and netbooks. Such devices usually use flash-based storage, which has limited lifespan due to write amplification, and also use it to provide swap space. The reduction in swap usage as a result of using zram effectively reduces the amount of wear placed on such flash-based storage, resulting in prolonging its usable life. Also, using zram results in a significantly reduced I/O for Linux systems that require swapping.
- "Linux kernel 3.14, Section 1.2. zram: Memory compression mechanism considered stable". kernelnewbies.org. March 30, 2014. Retrieved April 1, 2014.
- "Linux kernel 3.15, Section 1.7. zram: LZ4 compression support, improved performance". kernelnewbies.org. June 8, 2014. Retrieved June 15, 2014.
- "Increased performance in Linux with zram (virtual swap compressed in ram)". webupd8.org. October 2, 2011. Retrieved November 8, 2011.
- "compcache Compressed Caching for Linux". code.google.com. April 27, 2010. Retrieved November 11, 2011.
- Dinsan, Francis (December 8, 2012). "Ubuntu Linux Considers Greater Usage of zRAM". Retrieved October 30, 2013.
- "ZRAM Might Finally Be Moved Out Of Linux Staging". Phoronix. August 14, 2013. Retrieved February 9, 2014.
- "zRAM Is Still Hoping For A Promotion". Phoronix. November 25, 2013. Retrieved February 9, 2014.
- Larabel, Michael (March 28, 2013). "Google is Enabling zram for Chrome OS By Default". chromestory.com. Retrieved March 29, 2013.
- Google, Android KitKat | Android Developers.
- "Next Lubuntu provided with zram enabled! – LinuxVillage (en)". linuxvillage.org. October 17, 2013. Retrieved November 10, 2013.
- zram Linux Kernel documentation
- Compcache, Compressed Caching for Linux
- Compcache: in-memory compressed swapping, May 26, 2009, LWN.net, by Nitin Gupta
- In-kernel memory compression, April 3, 2013, LWN.net, by Dan Magenheimer
- The Compression Cache: Virtual Memory Compression for Handheld Computers, March 16, 2000, by Michael J. Freedman