summaryrefslogtreecommitdiffstats
path: root/src/oom/oomd-util.c
diff options
context:
space:
mode:
authorAnita Zhang <the.anitazha@gmail.com>2022-01-19 19:40:46 +0100
committerAnita Zhang <the.anitazha@gmail.com>2022-01-20 23:15:11 +0100
commit2ee209466bb51f39ae9df7fec4d5594ce8cfa3f0 (patch)
tree592c61558e664281ac1238214a539883660d4005 /src/oom/oomd-util.c
parentboot: Use -ffile-prefix-map when present (diff)
downloadsystemd-2ee209466bb51f39ae9df7fec4d5594ce8cfa3f0.tar.xz
systemd-2ee209466bb51f39ae9df7fec4d5594ce8cfa3f0.zip
oomd: fix race with path unavailability when killing cgroups
There can be a situation where systemd-oomd would kill all of the processes in a cgroup, pid1 would clean up that cgroup, and systemd-oomd would get ENODEV trying to iterate the cgroup a final time to ensure it was empty. systemd-oomd sees this as an error and immediately picks a new candidate even though pressure may have recovered. To counter this, check and handle path unavailability errnos specially. Fixes: #22030
Diffstat (limited to 'src/oom/oomd-util.c')
-rw-r--r--src/oom/oomd-util.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/oom/oomd-util.c b/src/oom/oomd-util.c
index 64ea8cf7e4..b54bf483d6 100644
--- a/src/oom/oomd-util.c
+++ b/src/oom/oomd-util.c
@@ -196,7 +196,14 @@ int oomd_cgroup_kill(const char *path, bool recurse, bool dry_run) {
r = cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, path, SIGKILL, CGROUP_IGNORE_SELF, pids_killed, log_kill, NULL);
else
r = cg_kill(SYSTEMD_CGROUP_CONTROLLER, path, SIGKILL, CGROUP_IGNORE_SELF, pids_killed, log_kill, NULL);
- if (r < 0)
+
+ /* The cgroup could have been cleaned up after we have sent SIGKILL to all of the processes, but before
+ * we could do one last iteration of cgroup.procs to check. Or the service unit could have exited and
+ * was removed between picking candidates and coming into this function. In either case, let's log
+ * about it let the caller decide what to do once they know how many PIDs were killed. */
+ if (IN_SET(r, -ENOENT, -ENODEV))
+ log_debug_errno(r, "Error when sending SIGKILL to processes in cgroup path %s, ignoring: %m", path);
+ else if (r < 0)
return r;
r = increment_oomd_xattr(path, "user.oomd_kill", set_size(pids_killed));