From 578d0f9ff1716aea3d1f29d8a746dea62dd8288e Mon Sep 17 00:00:00 2001 From: reionwong Date: Sat, 17 Oct 2026 13:56:58 +0800 Subject: [PATCH] feat(dm): keep the display manager and its sessions out of the OOM killer's way --- data/cutefish-dm.service | 2 ++ helper/main.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/data/cutefish-dm.service b/data/cutefish-dm.service index fd85713..e96d2cf 100644 --- a/data/cutefish-dm.service +++ b/data/cutefish-dm.service @@ -11,6 +11,8 @@ OnFailure=plymouth-quit.service ExecStart=/usr/bin/cutefish-dm # The daemon ends the login screen and the session itself. KillMode=mixed +# Its end takes the login screen and every session with it. +OOMScoreAdjust=-900 Restart=always RestartSec=1s EnvironmentFile=-/etc/default/locale diff --git a/helper/main.cpp b/helper/main.cpp index e103e4e..9a06802 100644 --- a/helper/main.cpp +++ b/helper/main.cpp @@ -402,6 +402,18 @@ int main() arguments.push_back(const_cast(argument.c_str())); arguments.push_back(nullptr); + // Out of the OOM killer's way, inherited by the session and everything it + // starts; this process's end ends the session too. The session puts its + // applications back to 0. Not -1000: a runaway session process must remain + // the kernel's last resort. Written as root, it is also the floor no + // descendant can go below. + const int protection = open("/proc/self/oom_score_adj", O_WRONLY | O_CLOEXEC); + if (protection >= 0) { + if (write(protection, "-900", 4) != 4) + perror("oom_score_adj"); + close(protection); + } + // The session runs in a child; this process stays to close the PAM session. const pid_t child = fork(); if (child == 0) {