[CRIU] [PATCH] parasite: Cleanup args size fetching

Pavel Emelyanov xemul at parallels.com
Fri Nov 7 05:53:55 PST 2014


Right now we push all the auxiliary arguments to parasite_infect_seized
while 2 of them are only required to calculate the size of args area.

Let's better keep track of required args size and get rid of excessive
arguments to parasite_infect_seized().

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 cr-dump.c                  |  8 ++++++--
 include/parasite-syscall.h |  5 ++---
 parasite-syscall.c         | 22 +++++++++-------------
 3 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 6b00b0e..799a76f 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1411,7 +1411,7 @@ static int pre_dump_one_task(struct pstree_item *item, struct list_head *ctls)
 	}
 
 	ret = -1;
-	parasite_ctl = parasite_infect_seized(pid, item, &vmas, NULL, 0);
+	parasite_ctl = parasite_infect_seized(pid, item, &vmas);
 	if (!parasite_ctl) {
 		pr_err("Can't infect (pid: %d) with parasite\n", pid);
 		goto err_free;
@@ -1500,6 +1500,8 @@ static int dump_one_task(struct pstree_item *item)
 			pr_err("Collect fds (pid: %d) failed with %d\n", pid, ret);
 			goto err;
 		}
+
+		parasite_ensure_args_size(drain_fds_size(dfds));
 	}
 
 	ret = parse_posix_timers(pid, &proc_args);
@@ -1508,13 +1510,15 @@ static int dump_one_task(struct pstree_item *item)
 		goto err;
 	}
 
+	parasite_ensure_args_size(posix_timers_dump_size(proc_args.timer_n));
+
 	ret = dump_task_signals(pid, item);
 	if (ret) {
 		pr_err("Dump %d signals failed %d\n", pid, ret);
 		goto err;
 	}
 
-	parasite_ctl = parasite_infect_seized(pid, item, &vmas, dfds, proc_args.timer_n);
+	parasite_ctl = parasite_infect_seized(pid, item, &vmas);
 	if (!parasite_ctl) {
 		pr_err("Can't infect (pid: %d) with parasite\n", pid);
 		goto err;
diff --git a/include/parasite-syscall.h b/include/parasite-syscall.h
index 0a882e0..4f89cdd 100644
--- a/include/parasite-syscall.h
+++ b/include/parasite-syscall.h
@@ -98,9 +98,8 @@ extern int parasite_cure_local(struct parasite_ctl *ctl);
 extern int parasite_cure_seized(struct parasite_ctl *ctl);
 extern struct parasite_ctl *parasite_infect_seized(pid_t pid,
 						   struct pstree_item *item,
-						   struct vm_area_list *vma_area_list,
-						   struct parasite_drain_fd *dfds,
-						   int timer_n);
+						   struct vm_area_list *vma_area_list);
+extern void parasite_ensure_args_size(unsigned long sz);
 extern struct parasite_ctl *parasite_prep_ctl(pid_t pid,
 					      struct vm_area_list *vma_area_list);
 extern int parasite_map_exchange(struct parasite_ctl *ctl, unsigned long size);
diff --git a/parasite-syscall.c b/parasite-syscall.c
index d17db0b..5b014bd 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -1148,17 +1148,11 @@ int parasite_map_exchange(struct parasite_ctl *ctl, unsigned long size)
 	return 0;
 }
 
-static unsigned long parasite_args_size(struct vm_area_list *vmas, struct parasite_drain_fd *dfds, int timer_n)
+static unsigned long parasite_args_size = PARASITE_ARG_SIZE_MIN;
+void parasite_ensure_args_size(unsigned long sz)
 {
-	unsigned long size = PARASITE_ARG_SIZE_MIN;
-
-	if (dfds)
-		size = max(size, (unsigned long)drain_fds_size(dfds));
-	if (timer_n)
-		size = max(size, (unsigned long)posix_timers_dump_size(timer_n));
-	size = max(size, (unsigned long)dump_pages_args_size(vmas));
-
-	return round_up(size, PAGE_SIZE);
+	if (parasite_args_size < sz)
+		parasite_args_size = sz;
 }
 
 static int parasite_start_daemon(struct parasite_ctl *ctl, struct pstree_item *item)
@@ -1186,8 +1180,7 @@ static int parasite_start_daemon(struct parasite_ctl *ctl, struct pstree_item *i
 }
 
 struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item,
-		struct vm_area_list *vma_area_list, struct parasite_drain_fd *dfds,
-		int timer_n)
+		struct vm_area_list *vma_area_list)
 {
 	int ret;
 	struct parasite_ctl *ctl;
@@ -1199,6 +1192,8 @@ struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item,
 	if (!ctl)
 		return NULL;
 
+	parasite_ensure_args_size(dump_pages_args_size(vma_area_list));
+
 	/*
 	 * Inject a parasite engine. Ie allocate memory inside alien
 	 * space and copy engine code there. Then re-map the engine
@@ -1206,7 +1201,8 @@ struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item,
 	 * without using ptrace at all.
 	 */
 
-	ctl->args_size = parasite_args_size(vma_area_list, dfds, timer_n);
+	ctl->args_size = round_up(parasite_args_size, PAGE_SIZE);
+	parasite_args_size = PARASITE_ARG_SIZE_MIN; /* reset for next task */
 	map_exchange_size = parasite_size + ctl->args_size;
 	map_exchange_size += RESTORE_STACK_SIGFRAME + PARASITE_STACK_SIZE;
 	if (item->nr_threads > 1)
-- 
1.8.4.2



More information about the CRIU mailing list