[CRIU] [PATCHv0 8/8] shmem: implement manual anon shared memory dedup

Eugene Batalov eabatalov89 at gmail.com
Sun Dec 6 05:15:24 PST 2015


From: Fyodor <bocharovfedor at gmail.com>

We use the same dumping and restoring mechanism for anon private and
anon shared memory. Because of this we can implement manual deduplication
of shared anon memory the same way we do it with private anonymous memory.
Also we need to rename pid parameter of cr_dedup_one_pagemap to id because
now we can pass either pid or shmid there and the actual meaning depends
on flags: PR_TASK is for pid, PR_SHMEM is for shmid.

Signed-off-by: Fyodor Bocharov <bocharovfedor at gmail.com>
Signed-off-by: Eugene Batalov <eabatalov89 at gmail.com>
---
 cr-dedup.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/cr-dedup.c b/cr-dedup.c
index b453c3e..1f79819 100644
--- a/cr-dedup.c
+++ b/cr-dedup.c
@@ -9,12 +9,12 @@
 
 #define MAX_BUNCH_SIZE 256
 
-static int cr_dedup_one_pagemap(int pid);
+static int cr_dedup_one_pagemap(int id, int flags);
 
 int cr_dedup(void)
 {
 	int close_ret, ret = 0;
-	int pid;
+	int id;
 	DIR * dirp;
 	struct dirent *ent;
 
@@ -37,10 +37,18 @@ int cr_dedup(void)
 			break;
 		}
 
-		ret = sscanf(ent->d_name, "pagemap-%d.img", &pid);
+		ret = sscanf(ent->d_name, "pagemap-%d.img", &id);
 		if (ret == 1) {
-			pr_info("pid=%d\n", pid);
-			ret = cr_dedup_one_pagemap(pid);
+			pr_info("pid=%d\n", id);
+			ret = cr_dedup_one_pagemap(id, PR_TASK);
+			if (ret < 0)
+				break;
+		}
+
+		ret = sscanf(ent->d_name, "pagemap-shmem-%d.img", &id);
+		if (ret == 1) {
+			pr_info("shmid=%d\n", id);
+			ret = cr_dedup_one_pagemap(id, PR_SHMEM);
 			if (ret < 0)
 				break;
 		}
@@ -60,14 +68,15 @@ err:
 	return 0;
 }
 
-static int cr_dedup_one_pagemap(int pid)
+static int cr_dedup_one_pagemap(int id, int flags)
 {
 	int ret;
 	struct page_read pr;
 	struct page_read * prp;
 	struct iovec iov;
 
-	ret = open_page_read(pid, &pr, PR_TASK | PR_MOD);
+	flags |= PR_MOD;
+	ret = open_page_read(id, &pr, flags);
 	if (ret <= 0) {
 		ret = -1;
 		goto exit;
-- 
1.9.1



More information about the CRIU mailing list