Quick start: Checking and Enabling zRAM in 5 Minutes
After using Fedora as my primary coding machine for two years, I absolutely love the package update speed, but one thing I always have to “roll up my sleeves” and tune immediately is zRAM. Unlike the old-school hard Swap partitions on a disk, Fedora has defaulted to zRAM since version 33. To check if your machine has it enabled, open a terminal and type:
zramctl
If you see /dev/zram0 appear along with a compression algorithm (usually lzo-rle), your machine is already running zRAM. See nothing? Installing it only takes a few seconds:
sudo dnf install zram-generator -y
Next, create a basic configuration file at /etc/systemd/zram-generator.conf:
sudo nano /etc/systemd/zram-generator.conf
Paste the following content into the file:
[zram0]
zram-size = ram / 2
compression-algorithm = zstd
Save and run the following command for the changes to take effect immediately:
sudo systemctl daemon-reload
sudo systemctl start /dev/zram0
Now, try typing swapon --show. You’ll see a new swap partition ready to handle the heavy lifting for your system.
What is zRAM and Why is it Fedora’s “Secret Weapon”?
You’ve likely been driven crazy by your machine freezing up when opening 50 Chrome tabs and a few Docker containers simultaneously. That’s when your physical RAM runs out, and the system has to push data to Swap on the hard drive. Even with the best NVMe SSDs, disk write speeds eat dust compared to physical RAM. This is where zRAM shows its value.
Instead of writing data to the disk, zRAM creates a compressed partition right within your RAM. Imagine 1GB of raw data pushed into zRAM using the zstd algorithm occupying only about 300MB. You’re using your CPU’s power to “magically” conjure up more memory capacity.
Fedora’s winning edge is that it prioritizes zRAM before touching on-disk Swap. Compressing and decompressing on modern CPUs happens incredibly fast, keeping the machine responsive instead of waiting for the hard drive to “squeeze out” every bit of data.
Advanced Configuration: Tuning zram-generator Like a Pro
Fedora’s defaults are quite safe, but as developers, we need more. Let’s dive deep into zram-generator.conf to optimize it based on actual hardware configurations.
1. Controlling Maximum Capacity
On a machine with 8GB of RAM, the zram-size = ram / 2 formula will create 4GB of compressed swap. However, if you don’t want zRAM to encroach too much on real memory, use the min function to limit it:
[zram0]
zram-size = min(ram / 2, 4096)
compression-algorithm = zstd
This configuration ensures zRAM takes up to 50% of RAM but never exceeds the 4GB (4096MB) threshold. This keeps enough free RAM available for high-priority tasks.
2. Choosing the Right Compression Algorithm
Your choice of compression algorithm directly impacts the machine’s smoothness:
- lzo-rle: Default on Fedora. Extremely fast and lightweight, but with a lower compression ratio. Suitable for older machines or 2-4 core CPUs.
- zstd: My #1 choice. Extremely high compression ratio (can compress data down to 1/4). While it uses a bit more CPU, it’s a trade-off well worth it for today’s multi-core chips.
- lz4: A balance between speed and capacity, a safe choice for most users.
Real-world Comparison: Do You Still Need Physical Swap?
Many ask: “Since I have zRAM, can I delete the Swap on my hard drive?” The answer is: **Yes, but don’t make it too large.**
zRAM handles “hot” active data exceptionally well. However, if you use the Hibernate feature, you must have a physical Swap partition larger than your actual RAM capacity. If you don’t use Hibernate, just keep about 2GB of physical Swap as a final “safety net” for when both real RAM and zRAM are overloaded.
To check the priority of swap types, type swapon --show. You’ll see zRAM has a higher PRIO index (e.g., 100), while on-disk swap is usually a negative number (-2). The system will always fill up zRAM before considering writing to the hard drive.
Real-world Experience Using Fedora as a Workstation
I regularly run VS Code along with several React projects and Docker simultaneously. Without zRAM, my Thinkpad would have surely “frozen up” long ago. Here are two small tips you should apply:
Increase Swappiness
Swappiness determines when the kernel prioritizes using swap. With zRAM, I prefer pushing this value to its maximum to leverage compression rather than letting the kernel free up cache on its own:
sudo sysctl vm.swappiness=100
To make it permanent, create the file /etc/sysctl.d/99-zram.conf and add the line vm.swappiness=100 inside.
Monitor Efficiency with zramctl
Don’t just set it and forget it. Occasionally type zramctl to look at the DATA (actual data) and COMPR (compressed data) columns. If the ratio reaches 3:1 or 4:1, you’ve succeeded in saving several precious GBs of RAM.
NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 zstd 4G 1.2G 300M 350M 16 [SWAP]
Looking at the example above: 1.2GB of actual data only consumes a mere 350MB of real memory. An impressive number for a software trick!
Conclusion
Optimizing zRAM on Fedora isn’t difficult, but it brings a noticeable change to your daily experience. For Junior Developers, mastering this memory management will help you feel more confident when handling heavy projects on your personal machine. Try experimenting with different algorithms to find the “sweet spot” for your hardware configuration. If you run into trouble editing the zram-generator file, feel free to leave a comment below, and I’ll help you out.

