EarlyOOM: preventable situation OOM in Linux fast and simple

If you are working with “heavy” applications in terms of memory usage, does this sound familiar, like OOM — Out Of Memory is when running programs need more memory than is available in the system. In this situation, the system usually starts to swapits to disk and slow down, which is unpleasant for the user.

Mechanism called OOM Killer to rescue the system based on the Linux from the memory. It works quite simple: when the memory ends it is based on a special algorithm calculates the process of death which will cause the least harm and provide the most slobodnoj memory and kills him.

This mechanism has a controversial reputation among users: on the one hand he almost has no alternatives, on the other — it starts at the moment when the system has a long and profoundly retarded “seat swapping”. Alternatively, the OOM Killer is developed by Early OOM Daemon, which will be discussed further.



Installation and configuration

On the basis of Red Hat (Fedora, Red Hat Enterprise Linux)

sudo dnf install earlyoom

sudo systemctl enable —now earlyoom

On the basis of Arch Linux (Manjaro, Arch)

sudo pacman -S earlyoom

sudo systemctl enable —now earlyoom

For Ubuntu and similar:

Ubuntu 18.04 Early OOM Daemon is present in the default repositories and can be installed with:

apt-get install earlyoom

Early OOM Daemon has no configuration file and the desired options it is necessary to pass as parameters to the command line. To describe them in the file “/etc/default/earlyoom”. In this file there are a number of examples, sufficient for the basic settings. Also quite informative man page of the service. Before you write your configuration consider the basic parameters:

  • -m: the amount of free memory in percent, which must begin the purge.
  • -s: the number of free “swap” in percent at which it is necessary to begin cleaning.
  • -Msame as -m, but the size in KIB (KiB, 1 KiB = 1024 bytes).
  • -S: similar to-s, but the size in KIB (KiB).
  • —prefer: a regular expression that describes the processes that should kill in the first place.
  • —avoid: a regular expression that describes the processes that should kill poslednuyu turn.
  • -N: command used to send notifications in case of activation of the service.

There is an interesting point: parameter -N designed to work in conjunction with utility notify-send from the package “libnotify-bin” and runs the command like this:

COMMAND -l dialog-warning earlyoom "Killing process 10977 Web Content"

And here the problems start: since the service itself is running as root and has access to the user session it is necessary to come up with some workaround. The author of these lines tested earlyroom on the Lubuntu distribution 18.04, working under the account with the name “moose” and was eventually wrote the script “/home/moose/scripts/earlyoom-notify.sh” with the following content:


if [ "$#" -ne "4" ]; then
        echo "Illegal params number"


if [ ${WHOAMI} != ${RUNASUSER} ]; then
        su -c "$0 "$1" "$2" "$3" "$4"" ${RUNASUSER}

DISPLAY=:0 notify-send "$1" "$2" "$3" "$4"

This script is essentially a wrapper for notify-send and runs notify-send in the right environment.

In the file “/etc/default/earlyoom” configuration was described as follows:

EARLYOOM_ARGS="-m 5 -s 60 --prefer '(^|/)(firefox|thunderbird)$' --avoid '(^|/)(sshd|systemd|init)' -N /home/moose/scripts/earlyoom-notify.sh"

Of course, after changing these settings, you must restart the service with the command:

service earlyoom restart

In the described configuration, the cleaning is triggered when memory remains less than 5% free RAM and less than 60% of the space on the swap. The first targets are the browser and mail client, and the last system services. When the application is closed is displayed in the corner of the screen.

Check the operation of the

To know the status of the process Earlyoom you can use the following command:

sudo systemctl status earlyoom.service

If the status shows “Active: active (running)” — that’s all right, Earlyoom is running and works correctly. Now you can arrange in the system a severe lack of RAM to test the operation Earlyoom. To do this, first disable swap on disk, if there is one, so don’t wait until it is filled.

sudo swapoff -a

And now the entire score is available in the system memory with zeroes:

tail /dev/zero

Further, should experience an abnormal the following: process tail must occupy the entire available RAM on the system, after which it needs to nail Earlyoom, thus freeing the RAM. If you have happened that way — congratulations, everything works as it should! Success!

Source: https://www.ylsoftware.com/ and https://imatvey.xyz/


0 0 vote
Article Rating
Notify of
Inline Feedbacks
View all comments

Do NOT follow this link or you will be banned from the site!
Would love your thoughts, please comment.x

Spelling error report

The following text will be sent to our editors: