regolith-linux / ilia

A GTK-based Desktop Executor
Apache License 2.0
83 stars 10 forks source link

feat: launch apps and commands using systemd-run #86

Closed SoumyaRanjanPatnaik closed 4 months ago

SoumyaRanjanPatnaik commented 4 months ago

Overview

This change causes ilia to use systemd-run to start applications in their own cgroup. This allows specific applications to be killed by systemd-oomd instead of the entire session in out-of-memory situations.

Why this is important

Ubuntu has been using systemd-oomd to handle out-of-memory situations since v22.04. The systemd-oomd documentation recommends starting applications with systems user manager to prevent multiple processes from starting within the same cgroup.

Be aware that if you intend to enable monitoring and actions on user.slice, user-$UID.slice, or their ancestor cgroups, it is highly recommended that your programs be managed by the systemd user manager to prevent running too many processes under the same session scope (and thus avoid a situation where memory intensive tasks trigger systemd-oomd to kill everything under the cgroup). If you're using a desktop environment like GNOME or KDE, it already spawns many session components with the systemd user manager.

Currently applications launched by ilia inherit the cgroup of ilia, which is usually going to be regolith-wayland.service, regolith-x11.service or user@.service (for non systemd based sessions). As per the docs, this means, if any of the processes started by ilia are causing out-of-memory, the entire session (or user) will be killed.

When Fedora migrated to systemd-oomd, they provided the following recommendation to prevent everything from being in the same cgroup.

How will this work if everything is in the same cgroup?

It will not work as systemd-oomd acts on a per-cgroup level. Applications will need to spawn processes into separate cgroups (e.g. with systemd-run) or use a desktop environment (e.g. GNOME, KDE) that does this for them.

Following this guideline, the PR will ensure that all the processes are launched in their own cgroups using systemd-run.

kgilmer commented 4 months ago

Just realized that w/ the deprecation of focal/bullseye the older branch no longer needs to be maintained

kgilmer commented 4 months ago

This fixes https://github.com/regolith-linux/regolith-desktop/issues/637