e43452d
From 54a91c5eae72181cc7aadf618c152e18ac336b5e Mon Sep 17 00:00:00 2001
e43452d
From: Lennart Poettering <lennart@poettering.net>
e43452d
Date: Thu, 3 Nov 2011 19:42:53 +0100
f1996ec
Subject: [PATCH] cgroup: immediately remove all cgroups which run empty
e43452d
e43452d
Some controllers have scaling problems when many empty cgroups exist.
e43452d
Hence, as soon as we get a notification that a cgroup is empty, delete
e43452d
it. This is also nice to keep the systemd-cgls output short.
e43452d
(cherry picked from commit 353fa6a21aab96b0b82ab40cc22b08b1fb0bf652)
e43452d
---
e43452d
 src/cgroup.c |   12 +++++++++---
e43452d
 1 files changed, 9 insertions(+), 3 deletions(-)
e43452d
e43452d
diff --git a/src/cgroup.c b/src/cgroup.c
e43452d
index be837c3..4bbb54f 100644
e43452d
--- a/src/cgroup.c
e43452d
+++ b/src/cgroup.c
e43452d
@@ -363,7 +363,8 @@ int cgroup_notify_empty(Manager *m, const char *group) {
e43452d
         assert(m);
e43452d
         assert(group);
e43452d
 
e43452d
-        if (!(l = hashmap_get(m->cgroup_bondings, group)))
e43452d
+        l = hashmap_get(m->cgroup_bondings, group);
e43452d
+        if (!l)
e43452d
                 return 0;
e43452d
 
e43452d
         LIST_FOREACH(by_path, b, l) {
e43452d
@@ -372,7 +373,8 @@ int cgroup_notify_empty(Manager *m, const char *group) {
e43452d
                 if (!b->unit)
e43452d
                         continue;
e43452d
 
e43452d
-                if ((t = cgroup_bonding_is_empty_list(b)) < 0) {
e43452d
+                t = cgroup_bonding_is_empty_list(b);
e43452d
+                if (t < 0) {
e43452d
 
e43452d
                         /* If we don't know, we don't know */
e43452d
                         if (t != -EAGAIN)
e43452d
@@ -381,9 +383,13 @@ int cgroup_notify_empty(Manager *m, const char *group) {
e43452d
                         continue;
e43452d
                 }
e43452d
 
e43452d
-                if (t > 0)
e43452d
+                if (t > 0) {
e43452d
+                        /* If it is empty, let's delete it */
e43452d
+                        cgroup_bonding_trim_list(b->unit->meta.cgroup_bondings, true);
e43452d
+
e43452d
                         if (UNIT_VTABLE(b->unit)->cgroup_notify_empty)
e43452d
                                 UNIT_VTABLE(b->unit)->cgroup_notify_empty(b->unit);
e43452d
+                }
e43452d
         }
e43452d
 
e43452d
         return 0;
e43452d
-- 
e43452d
1.7.7.5
e43452d