summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorMichal Koutný <mkoutny@suse.com>2023-08-14 19:59:57 +0200
committerMichal Koutný <mkoutny@suse.com>2024-01-03 13:43:04 +0100
commit93f8e88d23bd383b5134f32c1e2ee315ac3a38c8 (patch)
treec88c62d467735870ecc9ea6b4cd0037860750e70 /src/core
parenttest: Add effective cgroup limits testing (diff)
downloadsystemd-93f8e88d23bd383b5134f32c1e2ee315ac3a38c8.tar.xz
systemd-93f8e88d23bd383b5134f32c1e2ee315ac3a38c8.zip
cgroup: Restrict effective limits with global resource provision
Global resource (whole system or root cg's (e.g. in a container)) is also a well-defined limit for memory and tasks, take it into account when calculating effective limits.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/cgroup.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index f7b776337a..60a8a55087 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -4253,6 +4253,17 @@ static uint64_t unit_get_effective_limit_one(Unit *u, CGroupLimitType type) {
assert(u);
assert(UNIT_HAS_CGROUP_CONTEXT(u));
+ if (unit_has_name(u, SPECIAL_ROOT_SLICE))
+ switch (type) {
+ case CGROUP_LIMIT_MEMORY_MAX:
+ case CGROUP_LIMIT_MEMORY_HIGH:
+ return physical_memory();
+ case CGROUP_LIMIT_TASKS_MAX:
+ return system_tasks_max();
+ default:
+ assert_not_reached();
+ }
+
cc = unit_get_cgroup_context(u);
switch (type) {
/* Note: on legacy/hybrid hierarchies memory_max stays CGROUP_LIMIT_MAX unless configured