[CRIU] [PATCH v3 02/12] proc_parse: collect longest shared vma size

Eugene Batalov eabatalov89 at gmail.com
Sun Aug 7 06:11:06 PDT 2016


From: Fyodor Bocharov <bocharovfedor at gmail.com>

To dedup anon shared memory we need to know its longest size so we could
create page cache of appropriate size when dumping pages.

Signed-off-by: Fyodor Bocharov <fbocharov at yandex.ru>
Signed-off-by: Eugene Batalov <eabatalov89 at gmail.com>
---
 criu/include/vma.h | 2 ++
 criu/proc_parse.c  | 7 +++++++
 2 files changed, 9 insertions(+)

diff --git a/criu/include/vma.h b/criu/include/vma.h
index dae59be..32201a8 100644
--- a/criu/include/vma.h
+++ b/criu/include/vma.h
@@ -15,6 +15,7 @@ struct vm_area_list {
 	unsigned int		nr_aios;
 	unsigned long		priv_size; /* nr of pages in private VMAs */
 	unsigned long		priv_longest; /* nr of pages in longest private VMA */
+	unsigned long		shared_longest; /* nr of pages in longest shared VMA */
 };
 
 #define VM_AREA_LIST(name)	struct vm_area_list name = { .h = LIST_HEAD_INIT(name.h), .nr = 0, }
@@ -25,6 +26,7 @@ static inline void vm_area_list_init(struct vm_area_list *vml)
 	vml->nr = 0;
 	vml->priv_size = 0;
 	vml->priv_longest = 0;
+	vml->shared_longest = 0;
 }
 
 struct file_desc;
diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index 477aeb5..55546a5 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -633,6 +633,12 @@ static int vma_list_add(struct vma_area *vma_area,
 		pages = vma_area_len(vma_area) / PAGE_SIZE;
 		vma_area_list->priv_size += pages;
 		vma_area_list->priv_longest = max(vma_area_list->priv_longest, pages);
+	} else if (vma_area_is(vma_area, VMA_ANON_SHARED)) {
+		unsigned long pages;
+
+		pages = vma_area_len(vma_area) / PAGE_SIZE;
+		vma_area_list->shared_longest =
+			max(vma_area_list->shared_longest, pages);
 	}
 
 	*prev_vfi = *vfi;
@@ -658,6 +664,7 @@ int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list,
 	vma_area_list->nr_aios = 0;
 	vma_area_list->priv_longest = 0;
 	vma_area_list->priv_size = 0;
+	vma_area_list->shared_longest = 0;
 	INIT_LIST_HEAD(&vma_area_list->h);
 
 	f.fd = open_proc(pid, "smaps");
-- 
1.9.1



More information about the CRIU mailing list