]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup: Restrict effective limits with global resource provision 28797/head
authorMichal Koutný <mkoutny@suse.com>
Mon, 14 Aug 2023 17:59:57 +0000 (19:59 +0200)
committerMichal Koutný <mkoutny@suse.com>
Wed, 3 Jan 2024 12:43:04 +0000 (13:43 +0100)
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.

man/systemd.resource-control.xml
src/core/cgroup.c

index bd8b6a5719d7308aa24f4e8a6c11bfabc17f7623..c2aa5b57e823930986316935146004afb66005e7 100644 (file)
@@ -438,7 +438,7 @@ CPUWeight=20   DisableControllers=cpu              /          \
           <literal>memory.max</literal> control group attribute. For details about this control group attribute, see
           <ulink url="https://docs.kernel.org/admin-guide/cgroup-v2.html#memory-interface-files">Memory Interface Files</ulink>.
           The effective configuration is reported as <varname>EffectiveMemoryMax=</varname> (the value is
-          the most stringent limit of the unit and parent slices).</para>
+          the most stringent limit of the unit and parent slices and it is capped by physical memory).</para>
 
           <para>While <varname>StartupMemoryMax=</varname> applies to the startup and shutdown phases of the system,
           <varname>MemoryMax=</varname> applies to normal runtime of the system, and if the former is not set also to
index f7b776337ae6ef00481cee4e62fbbd136448d41f..60a8a550871f593297588e2498bf58ea475cbf5b 100644 (file)
@@ -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