Download More RAM? How ZRAM and EarlyOOM Saved My 8GB Linux Machine from Freezing

Cover photo by Mohamed Metwalli on YouTube.
We have all been there. You have a few too many browser tabs open, a heavy IDE running in the background, and you decide to compile a software package or launch a local Docker container. Suddenly, your mouse cursor stutters. Then it stops entirely. Your hard drive activity light blinks violently, your keyboard inputs are ignored, and your entire desktop session freezes into a digital brick.
For decades, the internet joked about "downloading more RAM." But in the modern Linux ecosystem, you can actually do something very close to it. By pairing ZRAM (in-memory compression) with EarlyOOM (a proactive memory guardian), you can turn an old or budget 8GB machine into a multitasking powerhouse that gracefully survives heavy workloads without freezing.
Here is how to set up this ultimate defense perimeter on your Linux system.
1. The Core Problem: Why the Linux Kernel "Thrashes" Your System
To understand why your computer freezes, you have to understand how standard Linux deals with empty memory.
When your applications completely consume your physical RAM, the Linux kernel relies on a fallback mechanism called Swap Space (usually a dedicated partition or file on your SSD or hard drive). The kernel begins moving "cold" or inactive data blocks out of your fast RAM and onto your slow storage drive to free up space for active programs.
This creates two massive problems:
- The Thrashing Trap: Even the fastest modern NVMe SSDs are orders of magnitude slower than physical RAM. When your system continuously moves memory chunks back and forth between RAM and your hard drive, it enters a state called disk thrashing. The kernel spends 99% of its processing power on basic data transfer rather than running your apps, causing your entire desktop to lock up.
- The Out-Of-Memory (OOM) Killer Delays: Linux does have a built-in emergency mechanism called the OOM Killer. When memory is dangerously depleted, it is supposed to forcefully terminate the largest memory-hogging app. However, the kernel's native OOM killer is notoriously conservative. It will often allow your machine to stay completely frozen and unresponsive for 2 to 5 minutes before it finally steps in to kill the offending process. By then, most users have lost patience and forced a hard shutdown by holding the physical power button.
2. Meet the Dynamic Duo: ZRAM and EarlyOOM
Instead of suffering through system freezes, we can fix memory management using two lightweight background services.
ZRAM: The Digital Trash Compactor
Instead of writing inactive data to a slow physical hard drive, ZRAM creates a virtual swap drive directly inside your physical RAM chips. When your RAM fills up, the system compresses the data on the fly and stores it right there in memory.
Think of it like a trash compactor: instead of running out to the dumpster every time your kitchen trash bin is full, you compress the garbage so you can fit three times as much into the exact same kitchen space. Because everything stays inside your ultra-fast RAM chips, there is no disk lag, no system stuttering, and zero wear-and-tear on your SSD.
EarlyOOM: The Proactive System Bouncer
While ZRAM expands your available memory pool, it isn't infinite. If you still manage to overwhelm your compressed space, EarlyOOM acts as your second line of defense.
Unlike the native kernel OOM killer which waits for total system failure, EarlyOOM operates in the user-space and checks your system memory up to 10 times per second. The moment your available physical RAM and swap drop below a safe pre-configured limit (like 10%), EarlyOOM instantly identifies the single process using the most memory (such as a rogue web browser tab or a leaking script) and kills it instantly. Your system never stutters, your desktop session stays perfectly fluid, and you only lose the single offending application rather than your entire desktop environment.
3. Step-by-Step Guide: Installation and Setup
Setting up these tools takes less than two minutes. Open your terminal and follow the instructions for your specific Linux distribution:
For Ubuntu, Debian, Pop!_OS, Linux Mint, and Zorin OS
Run the following command to update your package repositories and install both daemons:
sudo apt update && sudo apt install -y earlyoom zram-tools
For Fedora and Red Hat Enterprise Linux
Fedora actually enables ZRAM by default! However, you can ensure EarlyOOM is installed and active using dnf:
sudo dnf install earlyoom
sudo systemctl enable --now earlyoom
For Arch Linux
Arch users can pull the packages from the official repositories using pacman:
sudo pacman -S earlyoom systemd-zram-generator
Once installed, your system will automatically configure a baseline compressed ZRAM pool and activate EarlyOOM to run quietly in the background every time your computer boots up.
4. Advanced Tuning: Maximizing Your Performance
While the default settings work great, power users can optimize these tools to squeeze every bit of speed out of an 8GB machine.
Optimizing the "Swappiness" Secret
When using traditional disk-based swap, the common advice is to lower your system's "swappiness" value (often down to 10) so the system avoids using the slow hard drive. With ZRAM, you must do the exact opposite.
Because ZRAM is incredibly fast and saves physical space via compression, you want the Linux kernel to use it aggressively. We want to tell the system to compress idle application memory early and often, leaving the raw, uncompressed physical RAM completely open for active, high-priority tasks.
Open your system configuration file:
sudo nano /etc/sysctl.d/99-zram.conf
Add the following line to increase the kernel's swap priority, mimicking modern defaults used by Fedora:
vm.swappiness = 150
Save and exit (Ctrl+O, then Ctrl+X), then apply the changes immediately:
sudo sysctl --system
Customizing EarlyOOM Safety Thresholds
By default, EarlyOOM will terminate the largest process when both RAM and swap drop below 10%. If you want to change these rules — for example, waiting until memory hits 5% before killing an app — you can adjust its configuration file.
Open the configuration file:
sudo nano /etc/default/earlyoom
Look for the EARLYOOM_ARGS line. You can customize the minimum memory (-m) and minimum swap (-s) percentages:
EARLYOOM_ARGS="-m 5 -s 5 --notifications"
Note: Adding the --notifications flag allows EarlyOOM to send a desktop pop-up notification letting you know exactly which app it closed to save your system.
Restart the service to apply your changes:
sudo systemctl restart earlyoom
5. Potential Trade-offs to Keep in Mind
While ZRAM and EarlyOOM feel like magic, software cannot completely overcome physical hardware limitations. Keep these minor trade-offs in mind:
- CPU Overhead: Compressing and decompressing data on the fly requires processor cycles. Modern algorithms like zstd are incredibly efficient, but if your CPU is already pinned at 100% load during heavy mathematical rendering or video exporting, ZRAM may introduce a tiny sliver of extra CPU overhead.
- Data Selection Limitations: Some types of data do not compress well. If your RAM is full of encrypted containers, raw video files, or
.ziparchives, ZRAM's compression ratio will drop, meaning you won't get as much "virtual" RAM space out of it. - The Absolute Boundary: If you genuinely need to load a 30GB database entirely into memory, an 8GB machine with ZRAM will eventually fail or trigger EarlyOOM. ZRAM expands your daily multitasking runway — it does not turn a budget machine into a heavy-duty enterprise server.
6. The Verdict: A Night and Day Difference
By implementing ZRAM and EarlyOOM, you create an unbreakable shield around your operating system. ZRAM stretches your 8GB of memory to safely act like 12GB or 16GB of usable workspace, and EarlyOOM guarantees that even if you push the machine past its absolute limit, your desktop remains instantly responsive. You can monitor your active compression savings at any time by simply typing zramctl into your terminal.