Skip to content

earlyoom - Early Out-of-Memory Daemon Cheatsheet

earlyoom - Early Out-of-Memory Daemon Cheatsheet

earlyoom is a lightweight userspace daemon that prevents the classic Linux “the whole system froze when it ran out of RAM” problem. When memory runs low, the in-kernel OOM killer often reacts too late, after the machine has already become unresponsive from thrashing. earlyoom monitors available RAM and swap and, when they drop below configurable thresholds, kills the largest memory consumer early — keeping the system interactive instead of hanging. It is simple, dependency-free, and widely used on desktops and servers.

Installation

PlatformCommand
Debian/Ubuntusudo apt install earlyoom
Fedorasudo dnf install earlyoom (default on Fedora Workstation)
Arch Linuxsudo pacman -S earlyoom
From sourcemake && sudo make install from the repo
Verifyearlyoom --version

Enabling the Service

CommandDescription
sudo systemctl enable --now earlyoomEnable and start the daemon
sudo systemctl status earlyoomCheck it is running
journalctl -u earlyoom -fWatch its decisions live
earlyoomRun in the foreground (testing)

How It Decides

earlyoom watches two numbers and acts when both fall below their thresholds:

MetricFlagDefault-ish
Free RAM %-m PERCENTe.g. 10%
Free swap %-s PERCENTe.g. 10%
Kill triggerboth below thresholds
# Kill when RAM < 5% AND swap < 5%
earlyoom -m 5 -s 5

Key Options

OptionDescription
-m PERCENT[,KILL]RAM threshold to warn/kill (two values = warn,kill)
-s PERCENT[,KILL]Swap threshold to warn/kill
-M SIZERAM threshold in KiB instead of percent
-r INTERVALMemory report interval (seconds)
-nEnable desktop notifications on kill
-N COMMANDRun a command on kill (e.g. custom alert)
--prefer REGEXPrefer killing processes matching a name
--avoid REGEXAvoid killing processes matching a name
-pGive earlyoom itself a favorable OOM score
-dEnable debug output

Preferring / Avoiding Processes

# Prefer killing browsers/compilers; protect the display server and sshd
earlyoom -m 8 -s 8 \
  --prefer '(^|/)(chrome|firefox|cc1plus|java)$' \
  --avoid '(^|/)(Xorg|sshd|systemd)$'
DirectiveEffect
--preferKill these first when possible
--avoidKill these only as a last resort

Tuning these keeps a runaway process from taking your session or SSH access with it.

Configuration File

On systemd distros, options usually live in an env file:

# /etc/default/earlyoom  (Debian) or the unit's EnvironmentFile
EARLYOOM_ARGS="-m 5 -s 5 -r 60 --avoid '(^|/)(sshd|Xorg)$'"

Then sudo systemctl restart earlyoom.

earlyoom vs systemd-oomd vs kernel OOM

Aspectearlyoomsystemd-oomdKernel OOM killer
LayerUserspace daemonUserspace (systemd, PSI-based)Kernel
TriggerFree RAM/swap %Pressure Stall Info (PSI)Truly out of memory (late)
GranularityProcess (biggest)cgroup/unitProcess
ConfigSimple flagssystemd oomd policyLimited (oom_score_adj)
Best forSimple, effective safety netsystemd-managed cgroupsLast resort

On modern systemd distros, systemd-oomd (PSI-based) is an alternative; earlyoom remains popular for its simplicity and works anywhere.

Common Workflows

# Desktop: keep the UI responsive, notify on kills, protect the session
earlyoom -m 8 -s 4 -n --avoid '(^|/)(Xorg|gnome-shell|sshd)$'

# Server: conservative thresholds, log every action
sudo systemctl enable --now earlyoom
journalctl -u earlyoom -f

Resources