[CRIU] [PATCH 1/2] mem: Make parasite_dump_pages_args to carry data at predefined place

Cyrill Gorcunov gorcunov at openvz.org
Thu Jan 30 04:47:33 PST 2014


We allocate parasite_dump_pages_args structure dynamically so
it can be accessed from both -- criu and parasite code, moreover
the memory slab allocated for it is big enough to carry the max
number of VMAs and IOVECs data. Still we fill this data one by
one thus IOVECs can't be written before all VMAs are.

But we will need to write IOVECs data earlier (or at same
time) as filling VMAs. So introduce @vma_off and @iovec_off
members which will point where to write these two kind of
data independently.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 include/parasite.h | 18 ++++++++++++++++--
 mem.c              |  3 +++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/include/parasite.h b/include/parasite.h
index d53242e493ef..fb71febf6068 100644
--- a/include/parasite.h
+++ b/include/parasite.h
@@ -97,16 +97,30 @@ struct parasite_dump_pages_args {
 	unsigned int	off;
 	unsigned int	nr_segs;
 	unsigned int	nr_pages;
+
+	/*
+	 * VMAs and IOVECs are placed after this
+	 * structure in memory. For fast calculation
+	 * of where they live use these members.
+	 */
+	unsigned int	vma_off;
+	unsigned int	iovec_off;
 };
 
+static inline void pargs_init_offs(struct parasite_dump_pages_args *a, size_t nr_vmas)
+{
+	a->vma_off	= sizeof(*a);
+	a->iovec_off	= sizeof(*a) + nr_vmas * sizeof(struct parasite_vma_entry);
+}
+
 static inline struct parasite_vma_entry *pargs_vmas(struct parasite_dump_pages_args *a)
 {
-	return (struct parasite_vma_entry *)(a + 1);
+	return (void *)a + a->vma_off;
 }
 
 static inline struct iovec *pargs_iovs(struct parasite_dump_pages_args *a)
 {
-	return (struct iovec *)(pargs_vmas(a) + a->nr_vmas);
+	return (void *)a + a->iovec_off;
 }
 
 struct parasite_dump_sa_args {
diff --git a/mem.c b/mem.c
index 81ebef411eb9..b00d03a7f2ee 100644
--- a/mem.c
+++ b/mem.c
@@ -165,6 +165,7 @@ static struct parasite_dump_pages_args *prep_dump_pages_args(struct parasite_ctl
 
 	args = parasite_args_s(ctl, dump_pages_args_size(vma_area_list));
 
+	pargs_init_offs(args, vma_area_list->nr);
 	p_vma = pargs_vmas(args);
 	args->nr_vmas = 0;
 
@@ -182,6 +183,8 @@ static struct parasite_dump_pages_args *prep_dump_pages_args(struct parasite_ctl
 		p_vma++;
 	}
 
+	BUG_ON((void *)p_vma > (void *)pargs_iovs(args));
+
 	return args;
 }
 
-- 
1.8.3.1



More information about the CRIU mailing list