zram
also: zRAM, compressed RAM
zram is a Linux kernel module that creates compressed RAM-based block devices, allowing the system to store data in compressed form in memory to reduce physical RAM usage.
zram compresses data in RAM on-the-fly, creating virtual block devices that use significantly less memory than uncompressed storage. When data is written to a zram device, it is automatically compressed; when read, it is decompressed transparently. This is particularly useful for swap space and temporary storage on memory-constrained systems.
A typical use case is replacing traditional disk-based swap with a zram swap device. For example, a system might allocate 2 GB of physical RAM to a zram device, which could store 4–6 GB of compressed data depending on the content. Compression ratios typically range from 2:1 to 5:1 for most data types.
zram is configured through the /sys/block/zram* sysfs interface. A common setup involves creating a zram device, setting its size, and then using it as swap with swapon. Modern systems often enable zram automatically through tools like systemd or custom init scripts.