Ubuntu Developers Have An Idea For Handling The Over-Eager Systemd OOMD App Killing
Systemd-oomd on Ubuntu 22.04 LTS is too easily killing user applications like web browsers and other memory intense but user-critical applications. This killing of applications under memory pressure is often being done without the user aware of what's happening or any notice.
They've discussed altering their systemd-oomd tunables, even changing the swap size of Ubuntu by default as a possibility, and other changes. Based on the latest mailing list messages and activity by Canonical engineers, they are wanting an upstream change to systemd and then modifications to key desktop components so they can properly communicate that OOM killing of them should be avoided.
Systemd has a "ManagedOOMPreference" setting already that service files can use where one of the supported values is "avoid" if the out-of-memory preference is to try to avoid killing the unit's cgroup when systemd-oomd is figuring out how to reduce memory consumption. The avoided services will only be killed if no other viable candidates for killing are available (or there is also "omit" where in no case would OOMD kill that unit's cgroup). But the problem right now is the ManagedOOMPreference is only honored for cgroups owned by root, which isn't the case in the desktop realm.
Canonical's Nick Rosbrook has opened a preliminary pull request to upstream systemd that would allow ManagedOOMPreference to work for all cgroups, just not the root-owned ones. Systemd upstream isn't opposed to it and there was even a similar idea last year that hadn't been merged for allowing user control over this preference.
So it looks like this change may go forward upstream and Ubuntu 22.04 LTS could then back-port the change. User service files could then set ManagedOOMPreference to omit or avoid, as desired. However, this wouldn't do good for applications launched by the GNOME Shell or Snapd. So further work would be needed integrating the ManagedOOMPreference handling into GNOME Shell for passing the preference to selected applications when launched. There is also a matter of figuring out all of which services/applications to set for the ManagedOOMPreference=avoid behavior.
At least from the ubuntu-devel thread this appears to be their preferred path forward for taming Ubuntu's systemd-oomd to not kill prominent user-space/desktop applications. It will still take some time though for the change to be upstreamed and for that better desktop integration to occur.