From 2c70a81de6e9a3b4c13899dfd75d155ba6143f6e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 12 Dec 2023 10:54:55 +0100 Subject: [PATCH 1/2] cgroup: bring list of delegated cgroup attributes up-to-date with current kernels THis brings the list of attributes to delegate to managers of subcgroups to the state of kernel 6.6. We probably should unify this list, and maybe generate it automatically from /sys/kernel/cgroup/delegate, but let's do that another time. --- src/nspawn/nspawn-cgroup.c | 2 ++ src/shared/cgroup-setup.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/nspawn/nspawn-cgroup.c b/src/nspawn/nspawn-cgroup.c index a9d36627a8..a5002437c6 100644 --- a/src/nspawn/nspawn-cgroup.c +++ b/src/nspawn/nspawn-cgroup.c @@ -35,6 +35,8 @@ static int chown_cgroup_path(const char *path, uid_t uid_shift) { "cgroup.stat", "cgroup.subtree_control", "cgroup.threads", + "memory.oom.group", + "memory.reclaim", "notify_on_release", "tasks") if (fchownat(fd, fn, uid_shift, uid_shift, 0) < 0) diff --git a/src/shared/cgroup-setup.c b/src/shared/cgroup-setup.c index 811f129f6c..934a16eaf3 100644 --- a/src/shared/cgroup-setup.c +++ b/src/shared/cgroup-setup.c @@ -421,6 +421,8 @@ int cg_set_access( { "cgroup.procs", true }, { "cgroup.subtree_control", true }, { "cgroup.threads", false }, + { "memory.oom.group", false }, + { "memory.reclaim", false }, {}, }; From 113defc76b3c85ee9041c0489883cd1eace7fe3c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 13 Dec 2023 10:10:56 +0100 Subject: [PATCH 2/2] test: test that delegation of some newer attrs that shall be delegated work --- test/units/testsuite-19.delegate.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/units/testsuite-19.delegate.sh b/test/units/testsuite-19.delegate.sh index 83446a5704..74d36c405d 100755 --- a/test/units/testsuite-19.delegate.sh +++ b/test/units/testsuite-19.delegate.sh @@ -26,6 +26,19 @@ systemd-run --wait \ -w /sys/fs/cgroup/system.slice/test-0.service/cgroup.procs -a \ -w /sys/fs/cgroup/system.slice/test-0.service/cgroup.subtree_control +# Test if this also works for some of the more recent attrs the kernel might or might not support +for attr in cgroup.threads memory.oom.group memory.reclaim ; do + + if grep -q "$attr" /sys/kernel/cgroup/delegate ; then + systemd-run --wait \ + --unit=test-0.service \ + --property="DynamicUser=1" \ + --property="Delegate=" \ + test -w /sys/fs/cgroup/system.slice/test-0.service/ -a \ + -w /sys/fs/cgroup/system.slice/test-0.service/"$attr" + fi +done + systemd-run --wait \ --unit=test-1.service \ --property="DynamicUser=1" \