I investigated this a few years ago, the bottom line was (also described in the article linked by @barryascott) systemd-oomd uses pressure metrics. But I don’t know how I can translate my user level wish on the desktop to the pressure metrics.
An example
I was working on my high memory requirement project yesterday, and I deliberately ran an unconstrained compilation (cmake --build build-dir, no -jN flag to limit the cores). Unlike last time (from the thread above), my desktop didn’t crash, my browser wasn’t killed either. In fact, my compilation processes were killed. However I think there are a few differences between what I was doing before and yesterday.
- I was on XFCE before, yesterday’s test was on KDE
- Previously I was compiling bare metal (open a terminal, and compile), whereas yesterday I was compiling inside a Fedora toolbox.
Another observation, the OOM killer killed the compiler process, not the top-level build process (cmake/make/ninja), so my build actually moved on to the next command. I guess it would stop at some point, because at some point build dependencies won’t be satisfied. But this kinda extends the “sluggish” experience for the user a bit longer.
Hypothesis
I think the 2nd point is the important distinction. From the footnote of the old thread:
man oomd.conf says “… in which all tasks in the control group were delayed.
I don’t really understand cgroups, my naive assumption would be a container is a different cgroup. So maybe the learning is if you anticipate memory issues, run the application containerised, e.g. use toolboxes, or run a flatpak variant of a desktop application. That way rest of your desktop isn’t affected.
Other than this, I think I should also play with the pressure metrics to trigger the killer a bit earlier. During my experiment yesterday, my desktop had effectively “frozen” for ~5-7 mins. If this wasn’t a experiment, probably I would have hard rebooted instead of waiting for the OOM killer to kick-in.
PS: I can do a control experiment later on my desktop where I compile on bare metal.
EDIT: When I repeat my experiment on bare metal, my whole desktop goes down in half a minute!