]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: ensure init.scope is realized after drop-ins have been loaded
authorLuca Boccassi <bluca@debian.org>
Fri, 20 Jan 2023 23:00:38 +0000 (23:00 +0000)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 23 Jan 2023 20:40:54 +0000 (21:40 +0100)
If we add a drop-in for init.scope (e.g.: to set some memory limit),
it will be loaded long after the cgroup has already been realized.
Do it again when creating the special unit.

src/core/cgroup.c
src/core/cgroup.h
src/core/scope.c
test/TEST-55-OOMD/test.sh
test/units/testsuite-55.sh

index 7f3782ae4139afe45d842ebac23d7043381e9825..4cac3f6a89b1e7ea051beefbab97f59f17072674 100644 (file)
@@ -2528,7 +2528,7 @@ static bool unit_has_mask_enables_realized(
                 ((u->cgroup_enabled_mask | enable_mask) & CGROUP_MASK_V2) == (u->cgroup_enabled_mask & CGROUP_MASK_V2);
 }
 
-static void unit_add_to_cgroup_realize_queue(Unit *u) {
+void unit_add_to_cgroup_realize_queue(Unit *u) {
         assert(u);
 
         if (u->in_cgroup_realize_queue)
index a6a3d186ac7a635c21ffafd7844a5238f2bd411f..d137e3af4f37bc520c2470fc4dff4e87a0efa483 100644 (file)
@@ -264,6 +264,7 @@ int unit_realize_cgroup(Unit *u);
 void unit_prune_cgroup(Unit *u);
 int unit_watch_cgroup(Unit *u);
 int unit_watch_cgroup_memory(Unit *u);
+void unit_add_to_cgroup_realize_queue(Unit *u);
 
 void unit_release_cgroup(Unit *u);
 /* Releases the cgroup only if it is recursively empty.
index e2fc4cc995ef8f1f52e3db9b7b44f7a62adc8234..914d1cc74467174c1db350d6d91da6d8cd3bffef 100644 (file)
@@ -789,6 +789,10 @@ static void scope_enumerate_perpetual(Manager *m) {
 
         unit_add_to_load_queue(u);
         unit_add_to_dbus_queue(u);
+        /* Enqueue an explicit cgroup realization here. Unlike other cgroups this one already exists and is
+         * populated (by us, after all!) already, even when we are not in a reload cycle. Hence we cannot
+         * apply the settings at creation time anymore, but let's at least apply them asynchronously. */
+        unit_add_to_cgroup_realize_queue(u);
 }
 
 static const char* const scope_result_table[_SCOPE_RESULT_MAX] = {
index 4dc414294c94c8c9419197c13d454b3355d022a1..4032896061d8b00072a10c6427a3b17ed35738ac 100755 (executable)
@@ -16,6 +16,12 @@ test_append_files() {
 
         cat >>"${initdir:?}/etc/fstab" <<EOF
 UUID=$(blkid -o value -s UUID "${LOOPDEV}p2")    none    swap    defaults 0 0
+EOF
+
+        mkdir -p "${initdir:?}/etc/systemd/system/init.scope.d/"
+        cat >>"${initdir:?}/etc/systemd/system/init.scope.d/test-55-oomd.conf" <<EOF
+[Scope]
+MemoryHigh=10G
 EOF
     )
 }
index 8fa1d01fd06f1234ec6ecee33737042da9a5d588..0887eac08f7ff98af26c0e6cb3bfb04fa7253921 100755 (executable)
@@ -5,6 +5,9 @@ set -o pipefail
 
 systemd-analyze log-level debug
 
+# Ensure that the init.scope.d drop-in is applied on boot
+test "$(cat /sys/fs/cgroup/init.scope/memory.high)" != "max"
+
 # Loose checks to ensure the environment has the necessary features for systemd-oomd
 [[ -e /proc/pressure ]] || echo "no PSI" >>/skipped
 cgroup_type="$(stat -fc %T /sys/fs/cgroup/)"