[CRIU] [PATCH 5/9] vma: Keep track of lonest vma in list and sum of its lengths

Pavel Emelyanov xemul at parallels.com
Fri Mar 1 11:03:24 EST 2013


I will have to push some sort of map of pages to dump into parasite.
For this, I need to have estimation of how much memory I'd need for
than in parasite args. These two values will help with it.

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

---
 cr-dump.c         | 1 +
 cr-restore.c      | 2 +-
 include/crtools.h | 2 ++
 proc_parse.c      | 9 +++++++++
 4 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/cr-dump.c b/cr-dump.c
index f02e370..aff3e0c 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -119,6 +119,7 @@ int collect_mappings(pid_t pid, struct vm_area_list *vma_area_list)
 	if (ret < 0)
 		goto err;
 
+	pr_info("Collected, longest ares %lu bytes\n", vma_area_list->longest);
 	pr_info_vma_list(&vma_area_list->h);
 
 	pr_info("----------------------------------------\n");
diff --git a/cr-restore.c b/cr-restore.c
index 53e0645..1b7ee8f 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -70,7 +70,7 @@ static int restore_task_with_children(void *);
 static int sigreturn_restore(pid_t pid, CoreEntry *core);
 static int prepare_restorer_blob(void);
 
-static VM_AREA_LIST(rst_vmas);
+static VM_AREA_LIST(rst_vmas); /* XXX .longest is NOT tracked for this guy */
 
 static int shmem_remap(void *old_addr, void *new_addr, unsigned long size)
 {
diff --git a/include/crtools.h b/include/crtools.h
index bd922e0..d8cc7fc 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -219,6 +219,8 @@ void close_cr_fdset(struct cr_fdset **cr_fdset);
 struct vm_area_list {
 	struct list_head	h;
 	unsigned		nr;
+	unsigned long		priv_size; /* nr of pages in private VMAs */
+	unsigned long		longest; /* nr of pages in longest VMA */
 };
 
 #define VM_AREA_LIST(name)	struct vm_area_list name = { .h = LIST_HEAD_INIT(name.h), .nr = 0, }
diff --git a/proc_parse.c b/proc_parse.c
index 95dcf8f..6c2c2ab 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -179,6 +179,8 @@ int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, bool use_map_file
 	FILE *smaps = NULL;
 
 	vma_area_list->nr = 0;
+	vma_area_list->longest = 0;
+	vma_area_list->priv_size = 0;
 	INIT_LIST_HEAD(&vma_area_list->h);
 
 	smaps = fopen_proc(pid, "smaps");
@@ -345,6 +347,13 @@ int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, bool use_map_file
 done:
 		list_add_tail(&vma_area->list, &vma_area_list->h);
 		vma_area_list->nr++;
+		if (privately_dump_vma(vma_area)) {
+			unsigned long pages;
+
+			pages = vma_area_len(vma_area) / PAGE_SIZE;
+			vma_area_list->priv_size += pages;
+			vma_area_list->longest = max(vma_area_list->longest, pages);
+		}
 	}
 
 	vma_area = NULL;
-- 
1.7.11.7


More information about the CRIU mailing list