[CRIU] [RFC PATCH v2 18/23] page-read: introduce dup_page_read

Mike Rapoport rppt at linux.vnet.ibm.com
Mon Feb 6 03:44:11 PST 2017


The dup_page_read performs a shallow copy of a page_read object. It is
required for implementation of fork event in lazy-pages daemon.
When a restored process fork()'s a child, the lazy-pages daemon will handle
page faults of the child process, and it will use the parent process memory
dump for that.

Signed-off-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
---
 criu/include/pagemap.h |  7 +++++++
 criu/pagemap.c         | 13 +++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/criu/include/pagemap.h b/criu/include/pagemap.h
index ea034a4..e629f3c 100644
--- a/criu/include/pagemap.h
+++ b/criu/include/pagemap.h
@@ -103,6 +103,13 @@ extern int open_page_read(int pid, struct page_read *, int pr_flags);
 extern int open_page_read_at(int dfd, int pid, struct page_read *pr,
 		int pr_flags);
 
+/*
+ * Create a shallow copy of page_read object.
+ * The new object shares the pagemap structures with the original, but
+ * maintains its own set of references to those structures.
+ */
+extern void dup_page_read(struct page_read *src, struct page_read *dst);
+
 extern int dedup_one_iovec(struct page_read *pr, unsigned long base,
 			   unsigned long len);
 
diff --git a/criu/pagemap.c b/criu/pagemap.c
index 033aa0b..329b7ca 100644
--- a/criu/pagemap.c
+++ b/criu/pagemap.c
@@ -721,3 +721,16 @@ int open_page_read(int pid, struct page_read *pr, int pr_flags)
 {
 	return open_page_read_at(get_service_fd(IMG_FD_OFF), pid, pr, pr_flags);
 }
+
+
+#define DUP_IDS_BASE 1000
+
+void dup_page_read(struct page_read *src, struct page_read *dst)
+{
+	static int dup_ids = 1;
+
+	memcpy(dst, src, sizeof(*dst));
+	INIT_LIST_HEAD(&dst->async);
+	dst->id = src->id + DUP_IDS_BASE * dup_ids++;
+	dst->reset(dst);
+}
-- 
1.9.1



More information about the CRIU mailing list