[CRIU] [PATCH v4 1/7] shmem: pass anonymous shmem pagemap to add_shmem_area

Eugene Batalov eabatalov89 at gmail.com
Thu Aug 11 07:53:51 PDT 2016


From: Fyodor Bocharov <bocharovfedor at gmail.com>

So we would be able to analyze pagemap bits for each
anonymous shmem page and decide on its dirtiness and usage
by dumpee process.

Signed-off-by: Fyodor Bocharov <fbocharov at yandex.ru>
Signed-off-by: Eugene Batalov <eabatalov89 at gmail.com>
---
 criu/cr-dump.c       |  2 --
 criu/include/shmem.h |  3 ++-
 criu/mem.c           | 33 +++++++++++++++++++++------------
 criu/shmem.c         |  4 +++-
 4 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/criu/cr-dump.c b/criu/cr-dump.c
index ea1e356..5c6922a 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -470,8 +470,6 @@ static int dump_task_mm(pid_t pid, const struct proc_pid_stat *stat,
 			ret = 0;
 		else if (vma_entry_is(vma, VMA_AREA_SYSVIPC))
 			ret = check_sysvipc_map_dump(pid, vma);
-		else if (vma_entry_is(vma, VMA_ANON_SHARED))
-			ret = add_shmem_area(pid, vma);
 		else if (vma_entry_is(vma, VMA_AREA_SOCKET))
 			ret = dump_socket_map(vma_area);
 		else
diff --git a/criu/include/shmem.h b/criu/include/shmem.h
index ac1e56d..11edccb 100644
--- a/criu/include/shmem.h
+++ b/criu/include/shmem.h
@@ -1,6 +1,7 @@
 #ifndef __CR_SHMEM_H__
 #define __CR_SHMEM_H__
 
+#include "asm/int.h"
 #include "lock.h"
 #include "images/vma.pb-c.h"
 
@@ -10,7 +11,7 @@ struct vma_area;
 extern int collect_shmem(int pid, struct vma_area *vma);
 extern int collect_sysv_shmem(unsigned long shmid, unsigned long size);
 extern int cr_dump_shmem(void);
-extern int add_shmem_area(pid_t pid, VmaEntry *vma);
+extern int add_shmem_area(pid_t pid, VmaEntry *vma, u64 *map);
 extern int fixup_sysv_shmems(void);
 
 #define SYSV_SHMEM_SKIP_FD	(0x7fffffff)
diff --git a/criu/mem.c b/criu/mem.c
index f0baf14..d222535 100644
--- a/criu/mem.c
+++ b/criu/mem.c
@@ -289,6 +289,7 @@ static int __parasite_dump_pages_seized(struct parasite_ctl *ctl,
 	int ret = -1;
 	unsigned cpp_flags = 0;
 	bool should_xfer = (!delayed_dump || lazy);
+	unsigned long pmc_size;
 
 	pr_info("\n");
 	pr_info("Dumping pages (type: %d pid: %d)\n", CR_FD_PAGES, ctl->pid.real);
@@ -303,8 +304,10 @@ static int __parasite_dump_pages_seized(struct parasite_ctl *ctl,
 	 * Step 0 -- prepare
 	 */
 
+	pmc_size = max(vma_area_list->priv_longest,
+		vma_area_list->shared_longest);
 	if (pmc_init(&pmc, ctl->pid.real, &vma_area_list->h,
-			 vma_area_list->priv_longest * PAGE_SIZE))
+			 pmc_size * PAGE_SIZE))
 		return -1;
 
 	ret = -1;
@@ -340,7 +343,8 @@ static int __parasite_dump_pages_seized(struct parasite_ctl *ctl,
 		u64 off = 0;
 		u64 *map;
 
-		if (!vma_area_is_private(vma_area, kdat.task_size))
+		if (!vma_area_is_private(vma_area, kdat.task_size) &&
+				!vma_area_is(vma_area, VMA_ANON_SHARED))
 			continue;
 		if (vma_entry_is(vma_area->e, VMA_AREA_AIORING)) {
 			if (delayed_dump)
@@ -351,19 +355,24 @@ static int __parasite_dump_pages_seized(struct parasite_ctl *ctl,
 		map = pmc_get_map(&pmc, vma_area);
 		if (!map)
 			goto out_xfer;
+		if (vma_area_is(vma_area, VMA_ANON_SHARED))
+			ret = add_shmem_area(ctl->pid.real, vma_area->e, map);
+		else {
 again:
-		ret = generate_iovs(vma_area, pp, map, &off, has_parent);
-		if (ret == -EAGAIN) {
-			BUG_ON(delayed_dump);
-
-			ret = dump_pages(pp, ctl, args, &xfer, false);
-			if (ret)
+			ret = generate_iovs(vma_area, pp, map, &off,
+				has_parent);
+			if (ret == -EAGAIN) {
+				BUG_ON(delayed_dump);
+
+				ret = dump_pages(pp, ctl, args, &xfer, false);
+				if (ret)
+					goto out_xfer;
+				page_pipe_reinit(pp);
+				goto again;
+			}
+			if (ret < 0)
 				goto out_xfer;
-			page_pipe_reinit(pp);
-			goto again;
 		}
-		if (ret < 0)
-			goto out_xfer;
 	}
 
 	if (lazy)
diff --git a/criu/shmem.c b/criu/shmem.c
index 67e32a4..f8a3ba3 100644
--- a/criu/shmem.c
+++ b/criu/shmem.c
@@ -13,6 +13,7 @@
 #include "page-xfer.h"
 #include "rst-malloc.h"
 #include "vma.h"
+#include "mem.h"
 #include "config.h"
 #include "syscall-codes.h"
 
@@ -484,10 +485,11 @@ err:
 	return -1;
 }
 
-int add_shmem_area(pid_t pid, VmaEntry *vma)
+int add_shmem_area(pid_t pid, VmaEntry *vma, u64 *map)
 {
 	struct shmem_info *si;
 	unsigned long size = vma->pgoff + (vma->end - vma->start);
+	(void)map;
 
 	si = shmem_find(vma->shmid);
 	if (si) {
-- 
1.9.1



More information about the CRIU mailing list