]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
oomd: move check if processes can be killed into oomd_cgroup_kill()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 22 Nov 2025 01:19:47 +0000 (10:19 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 24 Nov 2025 11:40:13 +0000 (12:40 +0100)
This also adds a debuuging log if the check failed.
Addresses https://github.com/systemd/systemd/pull/39773#discussion_r2549439336.

Follow-up for 38e9d40c8097363b1e8fa025ef06865dadb0a3ac.

src/oom/oomd-util.c

index 0231d62a08198b971d68c277e24f3b4fd3007868..239c335427e813237f55fee92ce43a015ee91997 100644 (file)
@@ -237,6 +237,16 @@ 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;
 
@@ -337,12 +347,6 @@ 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 */
@@ -387,12 +391,6 @@ 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 */