[CRIU] [PATCH 10/10] restore: Bypass sync points of NS-related stages when not needed

Pavel Emelyanov xemul at virtuozzo.com
Fri Apr 28 05:29:52 PDT 2017


When we don't restore any namespaces criu forces tasks to wake
it up two times simply to no-op and wake up tasks back. This
can be optimized by simply omitting the not needed wakeups.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/cr-restore.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 8494617..92bb325 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -212,6 +212,15 @@ static void restore_wait_other_tasks()
 				participants);
 }
 
+static int restore_finish_ns_stage(int from, int to)
+{
+	if (root_ns_mask)
+		return restore_finish_stage(task_entries, from);
+
+	/* Nobody waits for this stage change, just go ahead */
+	__restore_switch_stage_nw(to);
+	return 0;
+}
 
 static int crtools_prepare_shared(void)
 {
@@ -1508,7 +1517,7 @@ static int restore_task_with_children(void *_arg)
 
 	/* Wait prepare_userns */
 	if (current->parent == NULL &&
-			restore_finish_stage(task_entries, CR_STATE_ROOT_TASK) < 0)
+			restore_finish_ns_stage(CR_STATE_ROOT_TASK, CR_STATE_PREPARE_NAMESPACES) < 0)
 		goto err;
 
 	/*
@@ -1555,7 +1564,7 @@ static int restore_task_with_children(void *_arg)
 		if (prepare_namespace(current, ca->clone_flags))
 			goto err;
 
-		if (restore_finish_stage(task_entries, CR_STATE_PREPARE_NAMESPACES) < 0)
+		if (restore_finish_ns_stage(CR_STATE_PREPARE_NAMESPACES, CR_STATE_FORKING) < 0)
 			goto err;
 
 		if (root_prepare_shared())
@@ -1926,6 +1935,9 @@ static int restore_root_task(struct pstree_item *init)
 		}
 	}
 
+	if (!root_ns_mask)
+		goto skip_ns_bouncing;
+
 	/*
 	 * uid_map and gid_map must be filled from a parent user namespace.
 	 * prepare_userns_creds() must be called after filling mappings.
@@ -1969,7 +1981,11 @@ static int restore_root_task(struct pstree_item *init)
 	if (ret)
 		goto out_kill;
 
-	ret = restore_switch_stage(CR_STATE_FORKING);
+	__restore_switch_stage(CR_STATE_FORKING);
+
+skip_ns_bouncing:
+
+	ret = restore_wait_inprogress_tasks();
 	if (ret < 0)
 		goto out_kill;
 
-- 
2.1.4



More information about the CRIU mailing list