| zram | |
|---|---|
Screenshot of zram running on openSUSE Tumbleweed | |
| Release | March 30, 2014 (Linux 3.14) |
| Written in | C |
| Operating system | Linux |
| Type | Linux kernel features |
| License | GNU General Public License |
| Website | www |
zram, formerly called compcache, is a Linux kernel module for creating a compressed block device in RAM, i.e. a RAM disk with on-the-fly disk compression. The block device created with zram can then be used for swap or as a general-purpose RAM disk. The two most common uses for zram are for the storage of temporary files (/tmp) and as a swap device. Initially, zram had only the latter function, hence the original name "compcache" ("compressed cache"). When empty, zram block device allocates about 0.1% of its size.[1]
After four years in the Linux kernel's driver staging area, zram was introduced into the mainline Linux kernel in version 3.14, released on March 30, 2014.[2] From Linux kernel version 3.15 onwards (released on June 8, 2014), zram supports multiple compression streams and multiple compression algorithms. Compression algorithms include DEFLATE (DEFLATE), LZ4 (LZ4, and LZ4HC "high compression"), LZO (LZO-RLE "run-length encoding"),[3] Zstandard (ZSTD), 842 (842). From kernel 5.1, the default is LZO-RLE,[3] which has a balance of speed and compression ratio. Like most other system parameters, the compression algorithm can be selected via sysfs.[4]
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, zswap always requires a backing store,[5] which is not the case for zram. Since the introduction of CONFIG_ZRAM_WRITEBACK in kernel version 4.14, zram is also able to use a storage device as a backing store, so it is able to move less-frequently used pages to disk, albeit the device can be only a partition at the moment[6] (and the process cannot be managed automatically by kernel when the memory needs to be freed, but requires pre-emptive user-space programming[7]). Since kernel version 7.0, zram can send the data to the backing store without decompressing them first.[8]
When used for swap, zram (like zswap) 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.[9][10] In 2012, Ubuntu briefly considered enabling zram by default on computers with small amounts of installed RAM.[11] For this same reason, Fedora enabled zram by default starting with release 33.[12]
Using compressed swap space with zram or 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 may also use it to provide swap space. Using zram or zswap reduces the swap usage, which effectively reduces the amount of wear placed on flash-based storage and makes it last longer. Using zram also results in significantly reduced I/O for Linux systems that require swapping.[13][14]
Additionally, zram in specific workloads can act as a method of nearly doubling memory (albeit at great risk without backup swap) while running faster than if zram was disabled. This is usually seen when using zram on low-end hardware alongside garbage-collected and I/O intensive workloads with slow (i.e. USB) storage, where writes to swap may cause long freezes. This can make persistent USB Linux installations more usable on low-memory systems.[15]
Usage by Android
editzram is used by Android as part of its memory management[16], manufacturers typically referred this feature with their own names such as RAM Plus for Samsung, Extended RAM for Vivo, and Memory Extension for Xiaomi.[17]
See also
editReferences
edit- ^ "zram: Compressed RAM-based block devices — The Linux Kernel documentation". docs.kernel.org. Retrieved February 25, 2024.
- ^ "Linux kernel 3.14, Section 1.2. zram: Memory compression mechanism considered stable". kernelnewbies.org. March 30, 2014. Retrieved April 1, 2014.
- ^ a b "ZRAM Will See Greater Performance On Linux 5.1 - It Changed Its Default Compressor - Phoronix". Phoronix.com.
- ^ "Linux kernel 3.15, Section 1.7. zram: LZ4 compression support, improved performance". kernelnewbies.org. June 8, 2014. Retrieved June 15, 2014.
- ^ Jonathan Corbet (February 19, 2026). "Modernizing swapping: virtual swap spaces". lwn.net. Retrieved June 19, 2026.
- ^ "zram: Compressed RAM-based block devices — The Linux Kernel documentation". www.kernel.org. 2026. Retrieved June 19, 2026.
- ^ "Debunking zswap and zram myths - Performance under memory pressure". chrisdown.name. 2026. Retrieved June 19, 2026.
- ^ Daroc Alden (February 23, 2026). "The second half of the 7.0 merge window". lwn.net. Retrieved June 19, 2026.
- ^ "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.
- ^ "Fedora 33 Looking To Use Swap On zRAM By Default With systemd's zram-generator - Phoronix". Phoronix.com. Retrieved March 29, 2021.
- ^ "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.
- ^ "Using zram with the Raspberry Pi". Pi My Life Up. January 30, 2022. Retrieved February 16, 2026.
- ^ "Memory allocation among processes | App quality". Android Developers. Retrieved January 22, 2026.
- ^ Debasish (April 30, 2025). "The truth about Android's virtual RAM: it barely uses internal storage". Gizmochina. Retrieved January 22, 2026.
External links
edit- zram Linux kernel documentation and zramctl(8) manual page
- 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

