[CRIU] [PATCHv1 2/8] proc_parse: collect longest shared vma size

Eugene Batalov eabatalov89 at gmail.com
Wed Dec 16 05:12:10 PST 2015


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>
---
 include/vma.h | 2 ++
 proc_parse.c  | 6 ++++++
 2 files changed, 8 insertions(+)

diff --git a/include/vma.h b/include/vma.h
index fcd3d0e..8ff3493 100644
--- a/include/vma.h
+++ b/include/vma.h
@@ -13,6 +13,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, }
@@ -23,6 +24,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/proc_parse.c b/proc_parse.c
index d0ca134..b83398a 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -495,6 +495,11 @@ 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;
@@ -519,6 +524,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