As RAM shortages become a reality, software optimization is once again taking center stage. Simply disabling swap or hoping that a system can cope without a safety net is a risky approach. Linux relies on a memory-management chain designed to absorb load spikes and smooth out periods of stress. zRAM extends this approach by providing compressed swap space directly in RAM. This means you can use up to twice as much memory as with a conventional setup. Here is how to configure zRAM and use it properly.
In this article
What is zRAM?
zRAM is a Linux kernel module that creates storage space directly in RAM, but in compressed form. Part of the RAM is used as a virtual disk to store memory pages compressed on the fly. This space acts as swap, or backup memory, when RAM starts to fill up. Unlike disk swap, which relies on an HDD or SSD, zRAM works entirely in memory and avoids many slow storage accesses.
Instead of immediately writing rarely used data to a storage device, the system first tries to compress it and keep it in RAM. Compression consumes CPU time, but this cost is lower than the time needed to read from or write to a disk. Thanks to this mechanism, the same amount of physical memory can hold more useful data.
zRAM does not replace adding more RAM when memory pressure becomes real. It does, however, make existing memory much more efficient by reducing memory pressure and limiting slowdowns under load. With RAM shortages and rising prices, zRAM is a software solution for improving memory efficiency and the Linux user experience.
1. Enable zRAM on Linux to get more from your RAM
Before installing anything, start by updating the package list and existing packages on Linux.
sudo apt update && sudo apt upgrade
This ensures that zram-tools and its dependencies are installed in a version compatible with your system.
The zram-tools package provides a ready-to-use service for managing a zRAM device automatically.
sudo apt install zram-tools
Once installed, the system has everything it needs to create a compressed swap device.
Enable the service immediately and make it persistent across reboots:
sudo systemctl enable --now zramswap.service
On Ubuntu, installing the package activates zRAM automatically.
2. Configure zRAM to make better use of your memory
After installing zRAM, you can adjust its behavior to find the best balance between additional memory and CPU overhead.
The settings are stored in a dedicated configuration file.
sudo nano /etc/default/zramswap
This file contains the parameters that determine how much memory zRAM uses and which compression algorithm it applies.
The first setting is the percentage of RAM allocated to zRAM:
PERCENT=50
This value tells zRAM to use the equivalent of half of the physical memory. It is a good compromise for most systems: it provides enough room to absorb inactive memory without placing excessive load on the CPU. You can increase it slightly on a very modest PC or reduce it on a more powerful machine.
The second parameter selects the compression algorithm:
ALGO=zstd
zstd is recommended because it offers an excellent balance between compression ratio and speed. It stores more compressed data in the same amount of memory while preserving good performance.
On an old or low-powered processor, a lighter algorithm such as lz4 may be preferable. Compression is slightly less effective than with zstd, but operations are extremely fast and require less computation.
After setting these parameters, restart the service so the system can apply the new configuration.
sudo systemctl restart zramswap
The restart immediately applies the selected zRAM size and compression algorithm.
Don’t let the algorithm decide for you
Add Assistouest to your preferred sources on Google so you can find our guides faster when you search for an IT solution.
How does zRAM delay system slowdowns?
zRAM becomes useful when a machine starts running short of RAM. As long as enough memory is available, its impact is limited. When the system approaches saturation, zRAM changes how memory is managed. Instead of immediately writing rarely used pages to disk, the kernel compresses them and keeps them directly in RAM. This avoids many storage accesses and significantly reduces the micro-freezes associated with conventional swap.

The benefit mainly depends on the compression ratio, which varies according to the type of data stored in memory. With ordinary anonymous pages, a ratio of around 2:1 is not unusual: 2 GB of data can fit into 1 GB of compressed RAM. This is not guaranteed, but it illustrates the technology’s potential. In practice, zRAM can provide several gigabytes of additional headroom before the system becomes slow or difficult to use.
The impact of the compression algorithm on the CPU
This benefit comes at a cost: compression and decompression use CPU time. On a modern machine, the impact is small. On a very low-powered computer, it may be noticeable. This is why choosing a very fast algorithm such as lz4 can make sense, even if its compression ratio is slightly lower than zstd’s.
Several research projects conducted on mobile platforms and constrained systems confirm these observations. As memory pressure increases, zRAM improves application responsiveness and reduces writes to storage. zRAM does not make a system faster by itself, but it helps keep the system usable for longer when resources become limited.
An error occurred. Please try again in a moment.