Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
27
rated 0 times [  27] [ 0]  / answers: 1 / hits: 16925  / 1 Year ago, tue, february 28, 2023, 5:44:10

Ubuntu 22.04 comes with the systemd-oomd service enabled by default, which has been "helpfully" killing my IDE and / or terminals whenever I try to compile an application using an abundance of threads / memory.


What is the right way to either turn this off, or configure the service to not shoot random processes in the face while I'm using them?


I'm aware that I can mitigate this behavior in a few ways; e.g. by increasing the size of the swap space, but this is still not a panacea since:



  • The OOM daemon kills the entire process tree, so even the terminal hosting the processes that were killed will suddenly vanish;



  • The OOM daemon kills the process tree without providing any notification to the user, so all the user knows is that their terminal / IDE / application hosting memory-hungry processes has suddenly vanished.




A user could find out what happened post-hoc via journalctl or something similar if they knew what to look for, but I don't think the average Ubuntu desktop user would think to do this.


As an example, normally when a process crashes via a deadly signal or similar, a crash reporter will tell the user that something went wrong. Shouldn't there be a similar facility for processes killed by the OOM daemon?




Edited to add requested output re: swap space; as far as I know these are just the defaults that were set when Ubuntu 22.04 was installed.


$ free -h
total used free shared buff/cache available
Mem: 31Gi 5.2Gi 3.1Gi 210Mi 23Gi 25Gi
Swap: 2.0Gi 0.0Ki 2.0Gi

$ sysctl vm.swappiness
vm.swappiness = 60

$ swapon -s
Filename Type Size Used Priority
/swapfile file 2097148 792 -2

More From » systemd

 Answers
1

Most systemd services can be managed via the systemctl utility. In this case, we want to disable the systemd-oomd service. This can be done with:


$ systemctl disable --now systemd-oomd

You should see something like (depending on your OS):


$ systemctl disable --now systemd-oomd
Removed /etc/systemd/system/multi-user.target.wants/systemd-oomd.service.
Removed /etc/systemd/system/dbus-org.freedesktop.oom1.service.

You can then verify that the service is disabled, with:


$ systemctl is-enabled systemd-oomd

And you should then see:


$ systemctl is-enabled systemd-oomd
disabled

It is possible, however, that other services might attempt to restart the systemd-oomd service. To prevent this, you can 'mask' the service. For example:


$ systemctl mask systemd-oomd
Created symlink /etc/systemd/system/systemd-oomd.service → /dev/null.

And then systemctl is-enabled should now report:


$ systemctl is-enabled systemd-oomd
masked

If you'd like to later unmask (or re-enable) a service, that can be done with, for example,


$ systemctl enable systemd-oomd
$ systemctl unmask systemd-oomd

See man systemctl for more details; in particular, note the caveats regarding masking of systemd services.


[#596] Wednesday, March 1, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
housecoarmer

Total Points: 434
Total Questions: 116
Total Answers: 120

Location: Albania
Member since Sun, Nov 22, 2020
4 Years ago
housecoarmer questions
;