[CRIU] [PATCH 4/8] parasite: Rework args size evaluation

Pavel Emelyanov xemul at parallels.com
Fri Oct 10 12:02:13 PDT 2014


This is for nicer accounting for aio parasite args size.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 cr-dump.c                  |  8 ++++++--
 include/parasite-syscall.h |  6 +++---
 include/pstree.h           |  1 +
 parasite-syscall.c         | 21 ++++++++-------------
 4 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 65c6f9c..adf8eff 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1421,7 +1421,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;
@@ -1521,6 +1521,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(item, drain_fds_size(dfds));
 	}
 
 	ret = parse_posix_timers(pid, &proc_args);
@@ -1529,6 +1531,8 @@ static int dump_one_task(struct pstree_item *item)
 		goto err;
 	}
 
+	parasite_ensure_args_size(item, 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);
@@ -1536,7 +1540,7 @@ static int dump_one_task(struct pstree_item *item)
 	}
 
 	ret = -1;
-	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 67840fc..c14730b 100644
--- a/include/parasite-syscall.h
+++ b/include/parasite-syscall.h
@@ -99,9 +99,7 @@ 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 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);
@@ -141,4 +139,6 @@ extern int parasite_stop_on_syscall(int tasks, int sys_nr, enum trace_flags trac
 extern int parasite_unmap(struct parasite_ctl *ctl, unsigned long addr);
 extern int ptrace_stop_pie(pid_t pid, void *addr, enum trace_flags *tf);
 
+extern void parasite_ensure_args_size(struct pstree_item *, unsigned long size);
+
 #endif /* __CR_PARASITE_SYSCALL_H__ */
diff --git a/include/pstree.h b/include/pstree.h
index c0fdac6..9a0bc3e 100644
--- a/include/pstree.h
+++ b/include/pstree.h
@@ -39,6 +39,7 @@ static inline struct rst_info *rsti(struct pstree_item *i)
 struct ns_id;
 struct dmp_info {
 	struct ns_id *netns;
+	unsigned long parasite_args_size;
 };
 
 static inline struct dmp_info *dmpi(struct pstree_item *i)
diff --git a/parasite-syscall.c b/parasite-syscall.c
index 7cc1a84..9d4d5ea 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -1121,17 +1121,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)
+void parasite_ensure_args_size(struct pstree_item *item, unsigned long size)
 {
-	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);
+	struct dmp_info *di = dmpi(item);
+	if (di->parasite_args_size < size)
+		di->parasite_args_size = size;
 }
 
 static int parasite_start_daemon(struct parasite_ctl *ctl, struct pstree_item *item)
@@ -1159,14 +1153,14 @@ 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;
 	unsigned long p, map_exchange_size;
 
 	BUG_ON(item->threads[0].real != pid);
+	parasite_ensure_args_size(item, dump_pages_args_size(vma_area_list));
 
 	ctl = parasite_prep_ctl(pid, vma_area_list);
 	if (!ctl)
@@ -1179,7 +1173,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);
+	parasite_ensure_args_size(item, PARASITE_ARG_SIZE_MIN);
+	ctl->args_size = round_up(dmpi(item)->parasite_args_size, PAGE_SIZE);
 	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