Merge pull request #27086 from keszybz/oomd-on-v1

Do not pull in systemd-oomd on v1 to avoid repeated message in logs
This commit is contained in:
Mike Yuan 2023-04-02 16:21:53 +08:00 committed by GitHub
commit 3508b1ba2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 7 deletions

View file

@ -1602,14 +1602,23 @@
<term><varname>ConditionControlGroupController=</varname></term>
<listitem><para>Check whether given cgroup controllers (e.g. <literal>cpu</literal>) are available
for use on the system.</para>
for use on the system or whether the legacy v1 cgroup or the modern v2 cgroup hierarchy is used.
</para>
<para>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 <literal>cpu</literal>, <literal>cpuset</literal>,
<literal>io</literal>, <literal>memory</literal>, and <literal>pids</literal>. Even if available in
the kernel, a particular controller may not be available if it was disabled on the kernel command
line with <varname>cgroup_disable=controller</varname>.</para></listitem>
ignored. Valid controllers are <literal>cpu</literal>, <literal>io</literal>,
<literal>memory</literal>, and <literal>pids</literal>. Even if available in the kernel, a
particular controller may not be available if it was disabled on the kernel command line with
<varname>cgroup_disable=controller</varname>.</para>
<para>Alternatively, two special strings <literal>v1</literal> and <literal>v2</literal> may be
specified (without any controller names). <literal>v2</literal> will pass if the unified v2 cgroup
hierarchy is used, and <literal>v1</literal> will pass if the legacy v1 hierarchy or the hybrid
hierarchy are used. Note that legacy or hybrid hierarchies have been deprecated. See
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> for
more information.</para>
</listitem>
</varlistentry>
<varlistentry>

View file

@ -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);
}