[CRIU] [PATCH] cg: Don't walk cgroup tree when it's not required

Pavel Emelyanov xemul at parallels.com
Tue Jul 15 06:57:55 PDT 2014


We have two bugs actually.

First, the check for 'item == root_item' in dump_task_cgroup fires
twice: first when we rite inventory (item == NULL as argument and
root_item == NULL because we haven't yet collected tasks) and the
2nd time when we dump the root task itself.

The 2nd issue sits in dump_cgroups() -- if root_cgset == criu_cgset
we don't write cgroups information at all (checking that we don't
have them with list_is_singular() inside that if). That said, we
don't need to read the cgroups tree if we're not going to dump it.

This patch fixes both.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>

---

diff --git a/cgroup.c b/cgroup.c
index 400ffe8..0a1ef42 100644
--- a/cgroup.c
+++ b/cgroup.c
@@ -439,9 +439,6 @@ int dump_task_cgroup(struct pstree_item *item, u32 *cg_id)
 	if (parse_task_cgroup(pid, &ctls, &n_ctls))
 		return -1;
 
-	if (item == root_item && collect_cgroups(&ctls) < 0)
-		return -1;
-
 	cs = get_cg_set(&ctls, n_ctls);
 	if (!cs)
 		return -1;
@@ -454,6 +451,13 @@ int dump_task_cgroup(struct pstree_item *item, u32 *cg_id)
 		BUG_ON(root_cgset);
 		root_cgset = cs;
 		pr_info("Set %d is root one\n", cs->id);
+
+		/*
+		 * The on-stack ctls is moved into cs inside
+		 * the get_cg_set routine.
+		 */
+		if (cs != criu_cgset && collect_cgroups(&cs->ctls))
+			return -1;
 	}
 
 	*cg_id = cs->id;



More information about the CRIU mailing list