core/cgroup: check root cgroup earlier for unit_get_memory_accounting
authorMike Yuan <me@yhndnzj.com>
Thu, 13 Jun 2024 09:00:26 +0000 (11:00 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 19 Jul 2024 22:33:14 +0000 (00:33 +0200)
(cherry picked from commit d3d035395eeced715c9609aeb8bfac7157dd0aa9)

src/core/cgroup.c

index 83296f9e52bae5166c622a3178eb2c10024fac50..76d7629798d2ff373e7d9bc04a1c39b03ee0d615 100644 (file)
@@ -4529,6 +4529,10 @@ int unit_get_memory_accounting(Unit *u, CGroupMemoryAccountingMetric metric, uin
         if (!UNIT_CGROUP_BOOL(u, memory_accounting))
                 return -ENODATA;
 
+        /* The root cgroup doesn't expose this information. */
+        if (unit_has_host_root_cgroup(u))
+                return -ENODATA;
+
         CGroupRuntime *crt = unit_get_cgroup_runtime(u);
         if (!crt)
                 return -ENODATA;
@@ -4536,10 +4540,6 @@ int unit_get_memory_accounting(Unit *u, CGroupMemoryAccountingMetric metric, uin
                 /* If the cgroup is already gone, we try to find the last cached value. */
                 goto finish;
 
-        /* The root cgroup doesn't expose this information. */
-        if (unit_has_host_root_cgroup(u))
-                return -ENODATA;
-
         if (!FLAGS_SET(crt->cgroup_realized_mask, CGROUP_MASK_MEMORY))
                 return -ENODATA;