Join WhatsApp
Join Now
Join Telegram
Join Now

Boosting Linux Performance on Low-Memory Systems with ZRAM Swap

Avatar for Noman Mohammad

By Noman Mohammad

Published on:

Your rating ?

My Tiny Laptop Was Dying… Until ZRAM Saved It

I grabbed my 2012 netbook last week. Twelve tabs? Sure. One hour later the fan screamed like a kettle and the mouse stuttered like it had too much coffee. Sound familiar?

I had **1 GB** of RAM and the swap was thrashing my painfully slow spinning-disk. Instead of chucking the laptop in the trash, I spent ten minutes setting up **ZRAM**. Suddenly the machine breathed again—same tabs, smooth scrolling, no sound of death. Here’s exactly how I did it.

What ZRAM Actually Is (In Plain English)

Think of RAM as a tiny but **super-fast** desk. When the desk overflows, Linux normally shoves stuff to a dusty drawer (hard-disk swap). That drawer takes forever to open.

ZRAM is like a magic pencil box inside the desk itself: you *compress* the papers so more can fit. Takes a smidge of CPU, but still way faster than that rusty drawer.

Walk-Through: Install & Switch On

1. Grab the package

Open a terminal and type the one-liner for your distro:

  • Debian / Ubuntu
    sudo apt install zram-config
  • Fedora
    sudo dnf install zram-generator
  • Arch
    sudo pacman -S zram-generator

2. Tell Linux how much

Most guides say “tune files.” I just rolled it into a tiny on-boot script.
Open a new file:

sudo nano /usr/local/bin/zram-setup

Paste this 5-liner, then replace **2G** with about half your physical RAM:

#!/bin/bash
modprobe zram
echo 1 > /sys/class/zram-control/hot_add
echo lz4 > /sys/block/zram0/comp_algorithm
echo 2G > /sys/block/zram0/disksize
mkswap /dev/zram0 && swapon -p 100 /dev/zram0

Make it executable:

sudo chmod +x /usr/local/bin/zram-setup

3. Run at boot

Dead simple systemd unit. One more file:

sudo nano /etc/systemd/system/zram-swap.service
[Unit]
Description=Enable ZRAM swap
After=local-fs.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/zram-setup
ExecStop=/usr/sbin/swapoff /dev/zram0

[Install]
WantedBy=multi-user.target

Now start and enable:

sudo systemctl daemon-reload
sudo systemctl enable --now zram-swap.service

Watch It Work

Right after boot, type:

zramctl

You’ll see something cute like:

/dev/zram0 lz4 2G 158M 41M 1.2G 4 [SWAP]

That line says: 158 MB of compressed stuff is tucked inside only 41 MB of real RAM. Instant fake disk space!

Four Extra Tuning Knobs

  • Size: Machines with 2 GB RAM get comfy with 2 GB ZRAM. My netbook needed just 1 GB.
  • Algorithm**: lz4** is fastest. If you run an ancient Atom, keep it. Newer laptops can handle **zstd** for squishier compression.
  • Swappiness trick: I like aggressive swapping into ZRAM. Try sudo sysctl vm.swappiness=150 and watch the load drop.
  • nvme drive? Give yourself a disk swap and ZRAM. Set swappiness to 10 so the lightning-fast NVM doesn’t wear out.

When Something Breaks

Oops, boot loops? Disable it quick.

sudo swapoff /dev/zram0
sudo systemctl disable zram-swap

You’re back to ordinary RAM.

Bottom Line

Before → “Even one spreadsheet pinned the system at 100 % wait.”
After → “Twenty tabs, Spotify, Slack, and still at 70 % memory.”

Zero hardware changed. My old netbook now lasts through a train ride of coding without rage-quitting. Consider ZRAM free extra memory. You just have to ask for it.

Leave a Comment