[CRIU] [PATCH] mm: do check on shared pages only if a vma is inherited (v2)

Andrey Vagin avagin at openvz.org
Tue Aug 13 13:29:10 EDT 2013


v2: restore page contents directly into memory
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-restore.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index 52340f6..3161531 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -339,26 +339,31 @@ static int restore_priv_vma_content(pid_t pid)
 			}
 
 			off = (va - vma->vma.start) / PAGE_SIZE;
+			p = decode_pointer((off) * PAGE_SIZE +
+					vma_premmaped_start(&vma->vma));
 
 			set_bit(off, vma->page_bitmap);
-			if (vma->ppage_bitmap)
+			if (vma->ppage_bitmap) { /* inherited vma */
 				clear_bit(off, vma->ppage_bitmap);
 
-			ret = pr.read_page(&pr, va, buf);
-			if (ret < 0)
-				break;
-
-			va += PAGE_SIZE;
-
-			p = decode_pointer((off) * PAGE_SIZE +
-					vma_premmaped_start(&vma->vma));
-
-			if (memcmp(p, buf, PAGE_SIZE) == 0) {
-				nr_shared++;
-				continue;
+				ret = pr.read_page(&pr, va, buf);
+				if (ret < 0)
+					break;
+				va += PAGE_SIZE;
+
+				if (memcmp(p, buf, PAGE_SIZE) == 0) {
+					nr_shared++; /* the page is cowed */
+					continue;
+				}
+
+				memcpy(p, buf, PAGE_SIZE);
+			} else {
+				ret = pr.read_page(&pr, va, p);
+				if (ret < 0)
+					break;
+				va += PAGE_SIZE;
 			}
 
-			memcpy(p, buf, PAGE_SIZE);
 			nr_restored++;
 		}
 
-- 
1.8.3.1



More information about the CRIU mailing list