Linux Ubuntu freeze Firefox

3 min read Original article ↗

The problem

Third time it’s happened. I open a few tabs in Firefox, work for a couple of hours, and at some point, the system locks up completely. Nothing works, no mouse, no keyboard. The only option is to hold down the power button:

Out of memory: Killed process 154968 (Isolated Web Co) 
total-vm:8286172kB, anon-rss:5154148kB

Firefox was eating 5GB of RAM. A single “Isolated Web Co” process (which is basically a Firefox tab or content process).

Using last -x, I saw the system had crashed at 11:12, and there were no OOM messages in the logs before the crash. This means the system froze so quickly that the OOM killer didn’t have time to intervene.

My config:

  • 16GB RAM
  • 4GB swap
  • swappiness at 60 (default)

Too little swap, and when RAM fills up quickly, the kernel doesn’t have time to kill processes before everything stalls.

I looked around to understand how to better configure the system. Here are some useful things:

Swap size

Red Hat Documentation and TheLinuxCode state that for systems with more than 8GB of RAM, you should have at least 4GB of swap, but if you experience memory pressure, it’s better to go with 8GB. I was exactly at 4GB, so I decided to increase it to 8GB.

Earlyoom

Then I discovered earlyoom. This is a daemon that monitors memory and kills processes before the system locks up. Unlike the kernel’s OOM killer which intervenes when it’s already too late, earlyoom acts when free memory drops below a certain threshold.

This article by OneUptime explains how to configure it for desktop, using the --prefer and --avoid options to decide what to kill and what to protect.

Zswap

Finally, I found zswap. It is a compressed cache that sits between RAM and disk swap. When memory fills up, zswap compresses inactive pages instead of writing them immediately to disk. Compared to pure zram, zswap integrates better with existing disk swap and doesn’t break hibernation.

On HowToGeek there is a very clear explanation of why zswap helps even on systems with “enough” RAM.

Solutions applied

1. Increased swap to 8GB

sudo swapoff -a
sudo rm /swap.img
sudo fallocate -l 8G /swap.img
sudo chmod 600 /swap.img
sudo mkswap /swap.img
sudo swapon /swap.img

2. Set swappiness to 10

This way, the kernel prefers using RAM and only uses swap when truly necessary:

echo "vm.swappiness=10" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

3. Installed and configured earlyoom

sudo apt install -y earlyoom

Then /etc/default/earlyoom:

EARLYOOM_ARGS="-m 5 -s 5 -k -n \
  --prefer '(^|/)(firefox|chrome|chromium|electron|Isolated Web Co|Web Content)' \
  --avoid '(^|/)(gnome-shell|Xorg|Xwayland|systemd|sshd|gnome-session|gdm|dbus-daemon)'"

This tells earlyoom to:

  • Intervene when RAM or swap drops below 5%
  • Prefer killing Firefox, Chrome, Electron (the main culprits)
  • Protect gnome-shell, Xorg, and system processes

4. Enabled zswap

I modified /etc/default/grub adding these parameters to the kernel:

zswap.enabled=1 zswap.compressor=zstd zswap.max_pool_percent=25 zswap.zpool=z3fold

Then sudo update-grub.

How my system is configured now

Draw

Result

Now if Firefox decides to eat 5GB of RAM for a runaway tab:

  1. zswap compresses inactive pages, gaining time
  2. If that’s not enough, disk swap absorbs the hit
  3. If still not enough, earlyoom kills Firefox BEFORE the system freezes
  4. No freezes

I’ve finished configuring everything and I’m writing this post. I hope it’s useful to someone having the same problem.


Configuration tested on Ubuntu 24.04.4 LTS (Noble Numbat) with 2 x 8 GB DRAM DDR4 at 3200 MHz. Links lead to the sources I used to understand the setup.