Zram
   HOME

TheInfoList



OR:

zram, formerly called compcache, is a Linux kernel module for creating a compressed
block device In Unix-like operating systems, a device file or special file is an interface to a device driver that appears in a file system as if it were an ordinary file. There are also special files in DOS, OS/2, and Windows. These special files allow a ...
in RAM, i.e. a
RAM disk Ram, ram, or RAM may refer to: Animals * A male sheep * Ram cichlid, a freshwater tropical fish People * Ram (given name) * Ram (surname) * Ram (director) (Ramsubramaniam), an Indian Tamil film director * RAM (musician) (born 1974), Dutch * ...
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 () and as a swap device. Initially, zram had only the latter function, hence the original name "compcache" ("compressed cache"). 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. From Linux kernel version 3.15 onwards (released on June 8, 2014), zram supports multiple compression streams and multiple
compression algorithm In information theory, data compression, source coding, or bit-rate reduction is the process of encoding information using fewer bits than the original representation. Any particular compression is either lossy or lossless. Lossless compressio ...
s. Compression algorithms include DEFLATE (DEFLATE), LZ4 (LZ4, and LZ4HC "high compression"), LZO (LZO-RLE "run-length encoding"),
Zstandard Zstandard, commonly known by the name of its reference implementation zstd, is a lossless data compression algorithm developed by Yann Collet at Facebook. ''Zstd'' is the reference implementation in C. Version 1 of this implementation was r ...
(ZSTD),
842 __NOTOC__ Year 842 ( DCCCXLII) was a common year starting on Sunday (link will display the full calendar) of the Julian calendar. Events By place Byzantine Empire * January 20 – Emperor Theophilos dies of dysentery at Constantin ...
(842). From kernel 5.1, the default is LZO-RLE, which has a balance of speed and ratio. 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 zswap is a Linux kernel feature that provides a compressed write-back Cache (computing), cache for Paging, swapped pages, as a form of virtual memory compression. Instead of moving memory pages to a swap device when they are to be swapped ou ...
, which is not a general-purpose RAM disk, but rather an in-kernel compressed cache for swap pages. Until the introduction of CONFIG_ZRAM_WRITEBACK in kernel version 4.14, unlike zswap, zram was unable to use a storage device as a backing store, so it was unable to move less-frequently used pages to disk. However, zswap always requires a backing store, which is not the case for zram. 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. In 2012,
Ubuntu Ubuntu ( ) is a Linux distribution based on Debian and composed mostly of free and open-source software. Ubuntu is officially released in three editions: '' Desktop'', ''Server'', and ''Core'' for Internet of things devices and robots. All ...
briefly considered enabling zram by default on computers with small amounts of installed RAM. For this same reason, Fedora enabled zram by default starting with release 33. 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 Write amplification (WA) is an undesirable phenomenon associated with flash memory and solid-state drives (SSDs) where the actual amount of information physically written to the storage media is a multiple of the logical amount intended to be wr ...
, 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.


See also

* Swap partitions on SSDs


References

120


External links


zram
Linux kernel documentation an

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 Michael J. Freedman is an American computer scientist who is the Robert E. Kahn Professor of Computer Science at Princeton University, where he works on distributed systems, networking, and security. He is also the cofounder of database company ...
{{Operating system Memory management Linux kernel features Virtual memory