[CRIU] [PATCH 4/7] Drop support for zero pagemap entries

Mike Rapoport rppt at linux.vnet.ibm.com
Thu Dec 15 04:10:40 PST 2016


The pagemap entries for pages mapped to zero pfn proved to be not useful...

Signed-off-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
---
 criu/cr-dedup.c          |  2 +-
 criu/include/pagemap.h   | 12 +++---------
 criu/mem.c               | 28 ++++++++++++----------------
 criu/page-xfer.c         | 15 +++------------
 criu/pagemap.c           | 19 +++++++------------
 criu/shmem.c             |  4 ++--
 criu/uffd.c              |  2 +-
 lib/py/images/pb2dict.py |  5 ++---
 8 files changed, 31 insertions(+), 56 deletions(-)

diff --git a/criu/cr-dedup.c b/criu/cr-dedup.c
index d3ea962..e84303f 100644
--- a/criu/cr-dedup.c
+++ b/criu/cr-dedup.c
@@ -83,7 +83,7 @@ static int cr_dedup_one_pagemap(int id, int flags)
 		goto exit;
 
 	while (1) {
-		ret = pr.advance(&pr, true);
+		ret = pr.advance(&pr);
 		if (ret <= 0)
 			goto exit;
 
diff --git a/criu/include/pagemap.h b/criu/include/pagemap.h
index 028bf1c..19cb6bf 100644
--- a/criu/include/pagemap.h
+++ b/criu/include/pagemap.h
@@ -47,7 +47,7 @@ struct page_read {
 	int (*read_pages)(struct page_read *, unsigned long vaddr, int nr,
 			  void *, unsigned flags);
 	/* Advance page_read to the next entry */
-	int (*advance)(struct page_read *pr, bool skip_zero);
+	int (*advance)(struct page_read *pr);
 	void (*close)(struct page_read *);
 	void (*skip_pages)(struct page_read *, unsigned long len);
 	int (*sync)(struct page_read *pr);
@@ -113,20 +113,14 @@ static inline unsigned long pagemap_len(PagemapEntry *pe)
 
 /* Pagemap flags */
 #define PE_PARENT	(1 << 0)	/* pages are in parent snapshot */
-#define PE_ZERO		(1 << 1)	/* pages can be lazily restored */
-#define PE_LAZY		(1 << 2)	/* pages are mapped to zero pfn */
-#define PE_PRESENT	(1 << 3)	/* pages are present in pages*img */
+#define PE_LAZY		(1 << 1)	/* pages can be lazily restored */
+#define PE_PRESENT	(1 << 2)	/* pages are present in pages*img */
 
 static inline bool pagemap_in_parent(PagemapEntry *pe)
 {
 	return !!(pe->flags & PE_PARENT);
 }
 
-static inline bool pagemap_zero(PagemapEntry *pe)
-{
-	return !!(pe->flags & PE_ZERO);
-}
-
 static inline bool pagemap_lazy(PagemapEntry *pe)
 {
 	return !!(pe->flags & PE_LAZY);
diff --git a/criu/mem.c b/criu/mem.c
index a9210cc..ec5ca46 100644
--- a/criu/mem.c
+++ b/criu/mem.c
@@ -109,7 +109,7 @@ bool should_dump_page(VmaEntry *vmae, u64 pme)
 		return false;
 	if (vma_entry_is(vmae, VMA_AREA_AIORING))
 		return true;
-	if (pme & (PME_PRESENT | PME_SWAP))
+	if ((pme & (PME_PRESENT | PME_SWAP)) && !page_is_zero(pme))
 		return true;
 
 	return false;
@@ -143,7 +143,7 @@ static int generate_iovs(struct vma_area *vma, struct page_pipe *pp, u64 *map, u
 {
 	u64 *at = &map[PAGE_PFN(*off)];
 	unsigned long pfn, nr_to_scan;
-	unsigned long pages[4] = {};
+	unsigned long pages[3] = {};
 
 	nr_to_scan = (vma_area_len(vma) - *off) / PAGE_SIZE;
 
@@ -167,18 +167,15 @@ static int generate_iovs(struct vma_area *vma, struct page_pipe *pp, u64 *map, u
 		 * page. The latter would be checked in page-xfer.
 		 */
 
-		if (page_is_zero(at[pfn])) {
-			ret = page_pipe_add_hole(pp, vaddr, PP_HOLE_ZERO);
-			pages[0]++;
-		} else if (has_parent && page_in_parent(at[pfn] & PME_SOFT_DIRTY)) {
+		if (has_parent && page_in_parent(at[pfn] & PME_SOFT_DIRTY)) {
 			ret = page_pipe_add_hole(pp, vaddr, PP_HOLE_PARENT);
-			pages[1]++;
+			pages[0]++;
 		} else {
 			ret = page_pipe_add_page(pp, vaddr, ppb_flags);
 			if (ppb_flags & PPB_LAZY && opts.lazy_pages)
-				pages[2]++;
+				pages[1]++;
 			else
-				pages[3]++;
+				pages[2]++;
 		}
 
 		if (ret) {
@@ -190,13 +187,12 @@ static int generate_iovs(struct vma_area *vma, struct page_pipe *pp, u64 *map, u
 	*off += pfn * PAGE_SIZE;
 
 	cnt_add(CNT_PAGES_SCANNED, nr_to_scan);
-	cnt_add(CNT_PAGES_ZERO, pages[0]);
-	cnt_add(CNT_PAGES_SKIPPED_PARENT, pages[1]);
-	cnt_add(CNT_PAGES_LAZY, pages[2]);
-	cnt_add(CNT_PAGES_WRITTEN, pages[3]);
+	cnt_add(CNT_PAGES_SKIPPED_PARENT, pages[0]);
+	cnt_add(CNT_PAGES_LAZY, pages[1]);
+	cnt_add(CNT_PAGES_WRITTEN, pages[2]);
 
-	pr_info("Pagemap generated: %lu pages (%lu lazy) %lu holes %lu zeros\n",
-		pages[3] + pages[2], pages[2], pages[1], pages[0]);
+	pr_info("Pagemap generated: %lu pages (%lu lazy) %lu holes\n",
+		pages[2] + pages[1], pages[1], pages[0]);
 	return 0;
 }
 
@@ -735,7 +731,7 @@ static int restore_priv_vma_content(struct pstree_item *t)
 	while (1) {
 		unsigned long off, i, nr_pages;
 
-		ret = pr.advance(&pr, true);
+		ret = pr.advance(&pr);
 		if (ret <= 0)
 			break;
 
diff --git a/criu/page-xfer.c b/criu/page-xfer.c
index a22ea3a..fe9563f 100644
--- a/criu/page-xfer.c
+++ b/criu/page-xfer.c
@@ -125,8 +125,6 @@ static int write_pagemap_to_server(struct page_xfer *xfer, struct iovec *iov, u3
 		cmd = PS_IOV_HOLE;
 	else if (flags & PE_LAZY)
 		cmd = PS_IOV_LAZY;
-	else if (flags & PE_ZERO)
-		cmd = PS_IOV_ZERO;
 	else
 		BUG();
 
@@ -359,8 +357,6 @@ static int get_hole_flags(struct page_pipe *pp, int n)
 
 	if (hole_flags == PP_HOLE_PARENT)
 		return PE_PARENT;
-	if (hole_flags == PP_HOLE_ZERO)
-		return PE_ZERO;
 	else
 		BUG();
 
@@ -735,9 +731,6 @@ static int page_server_serve(int sk)
 		case PS_IOV_HOLE:
 			ret = page_server_add(sk, &pi, PE_PARENT);
 			break;
-		case PS_IOV_ZERO:
-			ret = page_server_add(sk, &pi, PE_ZERO);
-			break;
 		case PS_IOV_LAZY:
 			ret = page_server_add(sk, &pi, PE_LAZY);
 			break;
@@ -807,13 +800,11 @@ static int fill_page_pipe(struct page_read *pr, struct page_pipe *pp)
 
 	pr->reset(pr);
 
-	while (pr->advance(pr, false)) {
+	while (pr->advance(pr)) {
 		unsigned long vaddr = pr->pe->vaddr;
 
 		for (i = 0; i < pr->pe->nr_pages; i++, vaddr += PAGE_SIZE) {
-			if (pagemap_zero(pr->pe))
-				ret = page_pipe_add_hole(pp, vaddr, PP_HOLE_ZERO);
-			else if (pagemap_in_parent(pr->pe))
+			if (pagemap_in_parent(pr->pe))
 				ret = page_pipe_add_hole(pp, vaddr, PP_HOLE_PARENT);
 			else
 				ret = page_pipe_add_page(pp, vaddr, pagemap_lazy(pr->pe) ? PPB_LAZY : 0);
@@ -851,7 +842,7 @@ static int page_pipe_from_pagemap(struct page_pipe **pp, int pid)
 		return -1;
 	}
 
-	while (pr.advance(&pr, false))
+	while (pr.advance(&pr))
 		if (pagemap_present(pr.pe))
 			nr_pages += pr.pe->nr_pages;
 
diff --git a/criu/pagemap.c b/criu/pagemap.c
index a211ff2..69f8058 100644
--- a/criu/pagemap.c
+++ b/criu/pagemap.c
@@ -120,16 +120,14 @@ int dedup_one_iovec(struct page_read *pr, unsigned long off, unsigned long len)
 	return 0;
 }
 
-static int advance(struct page_read *pr, bool skip_zero)
+static int advance(struct page_read *pr)
 {
-	do {
-		pr->curr_pme++;
-		if (pr->curr_pme >= pr->nr_pmes)
-			return 0;
+	pr->curr_pme++;
+	if (pr->curr_pme >= pr->nr_pmes)
+		return 0;
 
-		pr->pe = pr->pmes[pr->curr_pme];
-		pr->cvaddr = pr->pe->vaddr;
-	} while (skip_zero && pagemap_zero(pr->pe));
+	pr->pe = pr->pmes[pr->curr_pme];
+	pr->cvaddr = pr->pe->vaddr;
 
 	return 1;
 }
@@ -166,7 +164,7 @@ static int seek_pagemap(struct page_read *pr, unsigned long vaddr)
 			skip_pagemap_pages(pr, end - pr->cvaddr);
 adv:
 		; /* otherwise "label at end of compound stmt" gcc error */
-	} while (advance(pr, true));
+	} while (advance(pr));
 
 	return 0;
 }
@@ -435,9 +433,6 @@ static int read_pagemap_page(struct page_read *pr, unsigned long vaddr, int nr,
 	if (pagemap_in_parent(pr->pe)) {
 		if (read_parent_page(pr, vaddr, nr, buf, flags) < 0)
 			return -1;
-	} else if (pagemap_zero(pr->pe)) {
-		/* zero mappings should be skipped by get_pagemap */
-		BUG();
 	} else {
 		if (pr->maybe_read_page(pr, vaddr, nr, buf, flags) < 0)
 			return -1;
diff --git a/criu/shmem.c b/criu/shmem.c
index edd1127..73f632f 100644
--- a/criu/shmem.c
+++ b/criu/shmem.c
@@ -472,7 +472,7 @@ static int restore_shmem_content(void *addr, struct shmem_info *si)
 		unsigned long vaddr;
 		unsigned nr_pages;
 
-		ret = pr.advance(&pr, true);
+		ret = pr.advance(&pr);
 		if (ret <= 0)
 			break;
 
@@ -712,7 +712,7 @@ static int dump_one_shmem(struct shmem_info *si)
 		pgaddr = (unsigned long)addr + pfn * PAGE_SIZE;
 again:
 		if (pgstate == PST_ZERO)
-			ret = page_pipe_add_hole(pp, pgaddr, PP_HOLE_ZERO);
+			ret = 0;
 		else if (xfer.parent && page_in_parent(pgstate == PST_DIRTY))
 			ret = page_pipe_add_hole(pp, pgaddr, PP_HOLE_PARENT);
 		else
diff --git a/criu/uffd.c b/criu/uffd.c
index f761edd..ade5cbc 100644
--- a/criu/uffd.c
+++ b/criu/uffd.c
@@ -390,7 +390,7 @@ static int collect_lazy_iovecs(struct lazy_pages_info *lpi)
 	if (!mm)
 		return -1;
 
-	while (pr->advance(pr, false)) {
+	while (pr->advance(pr)) {
 		if (!pagemap_lazy(pr->pe))
 			continue;
 
diff --git a/lib/py/images/pb2dict.py b/lib/py/images/pb2dict.py
index 36c351b..769b63b 100644
--- a/lib/py/images/pb2dict.py
+++ b/lib/py/images/pb2dict.py
@@ -101,9 +101,8 @@ rfile_flags_map = [
 
 pmap_flags_map = [
 	('PE_PARENT',	1 << 0),
-	('PE_ZERO',	1 << 1),
-	('PE_LAZY',	1 << 2),
-	('PE_PRESENT',	1 << 3),
+	('PE_LAZY',	1 << 1),
+	('PE_PRESENT',	1 << 2),
 ];
 
 flags_maps = {
-- 
1.9.1



More information about the CRIU mailing list