From 67cbfbbf4b76d5d66ea32906812278d0ba7eb65c Mon Sep 17 00:00:00 2001 From: Matteo Croce Date: Mon, 24 Nov 2025 12:58:07 +0100 Subject: [PATCH] Revert "oomd: move check if processes can be killed into oomd_cgroup_kill()" This reverts commit 332bce5bd7a9294c3b414b6da72b09986af69d6b. The revert is needed because with the PreKill hook, oomd_cgroup_kill() is not goint to really kill processes but it just creates the callbacks. So the check is deferred to the real kill. --- src/oom/oomd-util.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/oom/oomd-util.c b/src/oom/oomd-util.c index 47b711f0bd3..e8d44f23fee 100644 --- a/src/oom/oomd-util.c +++ b/src/oom/oomd-util.c @@ -239,16 +239,6 @@ int oomd_cgroup_kill(const char *path, bool recurse, bool dry_run) { assert(path); - /* First try to send SIG0 recursively to ensure all child cgroups can be killed. */ - if (recurse) - r = cg_kill_recursive(path, /* sig= */ 0, CGROUP_IGNORE_SELF, - /* killed_pids= */ NULL, /* log_kill= */ NULL, /* userdata= */ NULL); - else - r = cg_kill(path, /* sig= */ 0, CGROUP_IGNORE_SELF, - /* killed_pids= */ NULL, /* log_kill= */ NULL, /* userdata= */ NULL); - if (r < 0) - return log_debug_errno(r, "Failed to send SIG0 to processes in cgroup '%s': %m", path); - if (dry_run) { _cleanup_free_ char *cg_path = NULL; @@ -349,6 +339,12 @@ int oomd_kill_by_pgscan_rate(Hashmap *h, const char *prefix, bool dry_run, char if (c->pgscan == 0 && c->current_memory_usage == 0) continue; + /* First try killing recursively to ensure all child cgroups can be killed. */ + r = cg_kill_recursive(c->path, /* sig= */ 0, CGROUP_IGNORE_SELF, /* killed_pids= */ NULL, + /* log_kill= */ NULL, /* userdata= */ NULL); + if (r < 0) + continue; + r = oomd_cgroup_kill(c->path, /* recurse= */ true, /* dry_run= */ dry_run); if (r == -ENOMEM) return r; /* Treat oom as a hard error */ @@ -393,6 +389,12 @@ int oomd_kill_by_swap_usage(Hashmap *h, uint64_t threshold_usage, bool dry_run, if (c->swap_usage <= threshold_usage) continue; + /* First try killing recursively to ensure all child cgroups can be killed. */ + r = cg_kill_recursive(c->path, /* sig= */ 0, CGROUP_IGNORE_SELF, /* killed_pids= */ NULL, + /* log_kill= */ NULL, /* userdata= */ NULL); + if (r < 0) + continue; + r = oomd_cgroup_kill(c->path, /* recurse= */ true, /* dry_run= */ dry_run); if (r == -ENOMEM) return r; /* Treat oom as a hard error */ -- 2.47.3