Rocky Linux logo on mountain scene background
Illustration: Lisa Hornung/TechRepublic

The Linux kernel module zRAM uses compressed RAM for swap space instead of the traditional partition. Even though using zRAM consumes more central processing unit cycles, the increase in speed you’ll experience having a larger RAM-based swap on Linux makes the trade-off worth it. Plus, the CPU zRAM usage is minimal, and you’ll never notice the CPU hit.

Most Linux distributions come with the zRAM kernel module in place. I’ll show you how to enable zRAM for Rocky Linux, but these instructions will work for most RHEL-based distributions.

SEE: 40+ open source and Linux terms you need to know (TechRepublic Premium)

Jump to:

What you need to enable zRAM

You only need two things to follow the steps in this tutorial: a user with sudo privileges and a running instance of Rocky Linux. However, even if you’re using a different RHEL-based distribution such as RHEL, AlmaLinux or CentOS Stream, you’re good to go.

How to enable zRAM on Rocky Linux

First, create a file that will load the zRAM kernel module with the command:

sudo nano /etc/modules-load.d/zram.conf

In that file, paste the following:


Save and close the file.

Next, we’ll create a configuration file for the kernel module with the following:

sudo nano /etc/modprobe.d/zram.conf

In that file, paste the following contents:

options zram num_devices=1

Save and close the file.

Now, we need to configure the size of the zRAM partition. Create a new udev rule with the command:

sudo nano /etc/udev/rules.d/99-zram.rules

In that file, paste the following, which configures a 2GB zRAM partition:

KERNEL=="zram0", ATTR{disksize}="2G",TAG+="systemd"

Save and close the file.

To disable traditional swap, open the fstab file with the following:

sudo nano /etc/fstab

In that file, comment out the swap entry by adding a # character to the beginning of the line. Save and close the file.

Next, we must create a systemd unit file with the command:

sudo nano /etc/systemd/system/zram.service

In that file, paste the following contents:

Description=Swap with zram

ExecStartPre=/sbin/mkswap /dev/zram0
ExecStart=/sbin/swapon /dev/zram0
ExecStop=/sbin/swapoff /dev/zram0


Save and close the file.

Enable the zRAM unit with the command:

sudo systemctl enable zram

Finally, reboot your system, and then verify zRAM is being used with the command:


The output should include something like this:

/dev/zram0 lzo-rle         2G   4K   74B   12K       1 [SWAP]

Get a performance boost for your Linux systems

Enabling zRAM for your Linux systems will give you a quick and easy performance boost, and you won’t find any reliability issues using this system.

Give zRAM a try on your test machines before doing it on production systems. Once you’re convinced it’s worth the effort, use zRAM on your production machines and start enjoying the results.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen. Become a Linux expert with these TechRepublic Academy resources: