[CRIU] [PATCH 03/10] cgroup: only collect cgsets once

Tycho Andersen tycho.andersen at canonical.com
Wed Mar 2 11:28:52 PST 2016


Instead of doing all the work in collect_cgroup() to figure out whether or
not we've collected this cgroup already, let's only call it if we created a
new cgset in the first place.

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 criu/cgroup.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/criu/cgroup.c b/criu/cgroup.c
index 218a6e4..887b4b8 100644
--- a/criu/cgroup.c
+++ b/criu/cgroup.c
@@ -172,13 +172,15 @@ static bool cg_set_compare(struct cg_set *set, struct list_head *ctls, int what)
 	}
 }
 
-static struct cg_set *get_cg_set(struct list_head *ctls, unsigned int n_ctls)
+static struct cg_set *get_cg_set(struct list_head *ctls, unsigned int n_ctls, bool *existed)
 {
 	struct cg_set *cs;
+	*existed = false;
 
 	list_for_each_entry(cs, &cg_sets, l)
 		if (cg_set_compare(cs, ctls, CGCMP_MATCH)) {
 			pr_debug(" `- Existing css %d found\n", cs->id);
+			*existed = true;
 			put_ctls(ctls);
 			return cs;
 		}
@@ -675,6 +677,7 @@ int dump_task_cgroup(struct pstree_item *item, u32 *cg_id, struct parasite_dump_
 	LIST_HEAD(ctls);
 	unsigned int n_ctls = 0;
 	struct cg_set *cs;
+	bool existed = false;
 
 	if (item)
 		pid = item->pid.real;
@@ -685,7 +688,7 @@ int dump_task_cgroup(struct pstree_item *item, u32 *cg_id, struct parasite_dump_
 	if (parse_task_cgroup(pid, args, &ctls, &n_ctls))
 		return -1;
 
-	cs = get_cg_set(&ctls, n_ctls);
+	cs = get_cg_set(&ctls, n_ctls, &existed);
 	if (!cs)
 		return -1;
 
@@ -705,7 +708,7 @@ int dump_task_cgroup(struct pstree_item *item, u32 *cg_id, struct parasite_dump_
 		 * The on-stack ctls is moved into cs inside
 		 * the get_cg_set routine.
 		 */
-		if (cs != criu_cgset && collect_cgroups(&cs->ctls))
+		if (cs != criu_cgset && !existed && collect_cgroups(&cs->ctls))
 			return -1;
 	}
 
-- 
2.7.0



More information about the CRIU mailing list