[08/11] vma: Do not open vmas when inheriting

Submitted by Pavel Emelianov on May 5, 2017, 4:03 p.m.

Details

Message ID 58d20e96-489f-dc5c-84f4-cec23e9c2c02@virtuozzo.com
State New
Series "Do not remap vmas when not needed"
Headers show

Commit Message

Pavel Emelianov May 5, 2017, 4:03 p.m.
Inherited VMAs don't need the descriptor to work with.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/mem.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/mem.c b/criu/mem.c
index a9e6e08..6cefa9d 100644
--- a/criu/mem.c
+++ b/criu/mem.c
@@ -646,16 +646,6 @@  static int premap_private_vma(struct pstree_item *t, struct vma_area *vma, void
 	void *addr;
 	unsigned long nr_pages, size;
 
-	if (vma_area_is(vma, VMA_FILE_PRIVATE)) {
-		ret = vma->vm_open(vpid(t), vma);
-		if (ret < 0) {
-			pr_err("Can't fixup VMA's fd\n");
-			return -1;
-		}
-
-		vma->vm_open = NULL; /* prevent from 2nd open in prepare_vmas */
-	}
-
 	nr_pages = vma_entry_len(vma->e) / PAGE_SIZE;
 	vma->page_bitmap = xzalloc(BITS_TO_LONGS(nr_pages) * sizeof(long));
 	if (vma->page_bitmap == NULL)
@@ -682,6 +672,13 @@  static int premap_private_vma(struct pstree_item *t, struct vma_area *vma, void
 		 */
 		if (vma_entry_is(vma->e, VMA_AREA_AIORING))
 			flag |= MAP_ANONYMOUS;
+		else if (vma_area_is(vma, VMA_FILE_PRIVATE)) {
+			ret = vma->vm_open(vpid(t), vma);
+			if (ret < 0) {
+				pr_err("Can't fixup VMA's fd\n");
+				return -1;
+			}
+		}
 
 		addr = mmap(*tgt_addr, size,
 				vma->e->prot | PROT_WRITE,
@@ -692,6 +689,9 @@  static int premap_private_vma(struct pstree_item *t, struct vma_area *vma, void
 			pr_perror("Unable to map ANON_VMA");
 			return -1;
 		}
+
+		if (vma_area_is(vma, VMA_FILE_PRIVATE))
+			close(vma->e->fd);
 	} else {
 		void *paddr;
 
@@ -725,7 +725,7 @@  static int premap_private_vma(struct pstree_item *t, struct vma_area *vma, void
 	}
 
 	if (vma_area_is(vma, VMA_FILE_PRIVATE))
-		close(vma->e->fd);
+		vma->vm_open = NULL; /* prevent from 2nd open in prepare_vmas */
 
 	*tgt_addr += size;
 	return 0;