From 2a4efebb3ba762468937dd45d0b1cb51a5122fde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 31 Mar 2023 18:31:56 +0200 Subject: [PATCH 1/2] core: skip deps on oomd if v2 or memory unavailable Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2055664 Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2172146 User report that systemd repeatedly logs about not being able to start oomd when booted with v1: Feb 20 16:52:33 systemd[1]: systemd-oomd.service - Userspace Out-Of-Memory (OOM) Killer was skipped because of a failed condition check (ConditionControlGroupController=v2). Feb 20 16:52:34 systemd[1]: systemd-oomd.service - Userspace Out-Of-Memory (OOM) Killer was skipped because of a failed condition check (ConditionControlGroupController=v2). Feb 20 16:52:34 systemd[1]: systemd-oomd.service - Userspace Out-Of-Memory (OOM) Killer was skipped because of a failed condition check (ConditionControlGroupController=v2). Feb 20 16:52:34 systemd[1]: systemd-oomd.service - Userspace Out-Of-Memory (OOM) Killer was skipped because of a failed condition check (ConditionControlGroupController=v2). Feb 20 16:52:34 systemd[1]: systemd-oomd.service - Userspace Out-Of-Memory (OOM) Killer was skipped because of a failed condition check (ConditionControlGroupController=v2). Feb 20 16:52:34 systemd[1]: systemd-oomd.service - Userspace Out-Of-Memory (OOM) Killer was skipped because of a failed condition check (ConditionControlGroupController=v2). Feb 20 16:52:34 systemd[2067491]: Queued start job for default target default.target. Feb 20 16:52:34 systemd[1]: systemd-oomd.service - Userspace Out-Of-Memory (OOM) Killer was skipped because of a failed condition check (ConditionControlGroupController=v2). Feb 20 16:52:34 systemd[2067491]: Created slice app.slice - User Application Slice. Feb 20 16:52:34 systemd[1]: systemd-oomd.service - Userspace Out-Of-Memory (OOM) Killer was skipped because of a failed condition check (ConditionControlGroupController=v2). systemd-oomd.service that pulls systemd-oomd.socket in (because it requires it); systemd-oomd.service itself is pulled by user@.service because systemd-oomd package installs an override config file that sets ManagedOOMMemoryPressure=kill. Add a check to the code that adds the implicit dependency to skip the dep if we cannot start it. The check is done exactly the same as in oomd itself. --- src/core/unit.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/core/unit.c b/src/core/unit.c index e3a57e3b84..642db41e41 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1546,7 +1546,8 @@ static int unit_add_mount_dependencies(Unit *u) { static int unit_add_oomd_dependencies(Unit *u) { CGroupContext *c; - bool wants_oomd; + CGroupMask mask; + int r; assert(u); @@ -1557,10 +1558,20 @@ static int unit_add_oomd_dependencies(Unit *u) { if (!c) return 0; - wants_oomd = (c->moom_swap == MANAGED_OOM_KILL || c->moom_mem_pressure == MANAGED_OOM_KILL); + bool wants_oomd = c->moom_swap == MANAGED_OOM_KILL || c->moom_mem_pressure == MANAGED_OOM_KILL; if (!wants_oomd) return 0; + if (!cg_all_unified()) + return 0; + + r = cg_mask_supported(&mask); + if (r < 0) + return log_debug_errno(r, "Failed to determine supported controllers: %m"); + + if (!FLAGS_SET(mask, CGROUP_MASK_MEMORY)) + return 0; + return unit_add_two_dependencies_by_name(u, UNIT_AFTER, UNIT_WANTS, "systemd-oomd.service", true, UNIT_DEPENDENCY_FILE); } From c32f496b9e7326584e49ae478539c4bc5c51ebe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 31 Mar 2023 18:51:17 +0200 Subject: [PATCH 2/2] man: restore description of ConditionControlGroupController=v1|v2 We use ConditionControlGroupController=v2 in systemd-oomd.service, and also this condition makes sense in general, so it should be documented. This reverts a part of 6d48c7cf736ced70c1c2fef1e1f03618911d04bc. Deprecated commandline options and v1 controller names were removed from the description. --- man/systemd.unit.xml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml index 9411ea2e03..c618e403f7 100644 --- a/man/systemd.unit.xml +++ b/man/systemd.unit.xml @@ -1602,14 +1602,23 @@ ConditionControlGroupController= Check whether given cgroup controllers (e.g. cpu) are available - for use on the system. + for use on the system or whether the legacy v1 cgroup or the modern v2 cgroup hierarchy is used. + Multiple controllers may be passed with a space separating them; in this case the condition will only pass if all listed controllers are available for use. Controllers unknown to systemd are - ignored. Valid controllers are cpu, cpuset, - io, memory, and pids. Even if available in - the kernel, a particular controller may not be available if it was disabled on the kernel command - line with cgroup_disable=controller. + ignored. Valid controllers are cpu, io, + memory, and pids. Even if available in the kernel, a + particular controller may not be available if it was disabled on the kernel command line with + cgroup_disable=controller. + + Alternatively, two special strings v1 and v2 may be + specified (without any controller names). v2 will pass if the unified v2 cgroup + hierarchy is used, and v1 will pass if the legacy v1 hierarchy or the hybrid + hierarchy are used. Note that legacy or hybrid hierarchies have been deprecated. See + systemd1 for + more information. +