[systemd-devel] [PATCHv2] Cache aggregated cgroup mask data at the slice level.

david at davidstrauss.net david at davidstrauss.net
Thu Nov 7 21:48:06 PST 2013


From: David Strauss <david at davidstrauss.net>

---
 src/core/cgroup.c | 7 ++++++-
 src/core/cgroup.h | 2 ++
 src/core/unit.c   | 2 ++
 src/core/unit.h   | 1 +
 4 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 6a6c504..81255ea 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -345,6 +345,11 @@ static CGroupControllerMask unit_get_cgroup_mask(Unit *u) {
         return cgroup_context_get_mask(c);
 }
 
+void unit_update_parent_slice_mask(Unit *u) {
+        if (UNIT_ISSET(u->slice))
+                UNIT_DEREF(u->slice)->cgroup_children_mask |= unit_get_cgroup_mask(u);
+}
+
 static CGroupControllerMask unit_get_members_mask(Unit *u) {
         CGroupControllerMask mask = 0;
         Unit *m;
@@ -371,7 +376,7 @@ static CGroupControllerMask unit_get_siblings_mask(Unit *u) {
 
         /* Sibling propagation is only relevant for weight-based
          * controllers, so let's mask out everything else */
-        return unit_get_members_mask(UNIT_DEREF(u->slice)) &
+        return UNIT_DEREF(u->slice)->cgroup_children_mask &
                 (CGROUP_CPU|CGROUP_BLKIO|CGROUP_CPUACCT);
 }
 
diff --git a/src/core/cgroup.h b/src/core/cgroup.h
index 0a079e9..1a24d07 100644
--- a/src/core/cgroup.h
+++ b/src/core/cgroup.h
@@ -113,3 +113,5 @@ int manager_notify_cgroup_empty(Manager *m, const char *group);
 
 const char* cgroup_device_policy_to_string(CGroupDevicePolicy i) _const_;
 CGroupDevicePolicy cgroup_device_policy_from_string(const char *s) _pure_;
+
+void unit_update_parent_slice_mask(Unit *u);
diff --git a/src/core/unit.c b/src/core/unit.c
index e19d281..a018dad 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -981,6 +981,8 @@ int unit_load(Unit *u) {
                                 goto fail;
                 }
 
+                unit_update_parent_slice_mask(u);
+
                 r = unit_add_mount_links(u);
                 if (r < 0)
                         goto fail;
diff --git a/src/core/unit.h b/src/core/unit.h
index 6971048..1a3f21d 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -174,6 +174,7 @@ struct Unit {
         /* Counterparts in the cgroup filesystem */
         char *cgroup_path;
         CGroupControllerMask cgroup_mask;
+        CGroupControllerMask cgroup_children_mask;
 
         UnitRef slice;
 
-- 
1.8.3.1



More information about the systemd-devel mailing list