Skip to contentSkip to conversation

checkpoint: un-blacklist VM_NORESERVE

RFC In review Nathan Lynch 3 participants 4 messages Jun 17, 2010 – Jun 19, 2010 1 message not in the archive Memory management

lore
Share & tools
lore
#0 lore raw

RFC 1/1 checkpoint: un-blacklist VM_NORESERVE

While a region mapped with MAP_NORESERVE may segv on a write in low-memory conditions, reading it (as we do during checkpoint) is fine. Remove the VM_NORESERVE flag from CKPT_VMA_NOT_SUPPORTED.

---

Oren, what do you think about this? I've tested this lightly with no apparent problems; is there some reason I'm missing to not support MAP_NORESERVE regions?

 include/linux/checkpoint.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/checkpoint.h +1 -1
index 84bb7a9..f3e0d11 100644
@@ -301,7 +301,7 @@ extern int restore_memory_contents(struct ckpt_ctx *ctx, struct inode *inode);
 
 #define CKPT_VMA_NOT_SUPPORTED						\
 	(VM_IO | VM_HUGETLB | VM_NONLINEAR | VM_PFNMAP |		\
-	 VM_RESERVED | VM_NORESERVE | VM_HUGETLB | VM_NONLINEAR |	\
+	 VM_RESERVED | VM_HUGETLB | VM_NONLINEAR |	\
 	 VM_MAPPED_COPY | VM_INSERTPAGE | VM_MIXEDMAP | VM_SAO)
 
 /* signals */
Signature · 1 line
1.6.0.2
#1 lore raw
Quoted 9 lines · Nathan Lynch

While a region mapped with MAP_NORESERVE may segv on a write in low-memory conditions, reading it (as we do during checkpoint) is fine. Remove the VM_NORESERVE flag from CKPT_VMA_NOT_SUPPORTED.

---

Oren, what do you think about this? I've tested this lightly with no apparent problems; is there some reason I'm missing to not support MAP_NORESERVE regions?

Sounds reasonable. I originally left it out because I wasn't sure. In particular, my concern was whether a user may cause troubles by specifying this flag. Now I looked deeper, and I think it's safe.

Note, however, it isn't enough to allow the flag, we also need to modify calc_map_flags_bits() to reintroduce MAP_NORESERVE for the flags argument to do_mmap_pgoff(). Otherwise it won't be restored at restart...

No need to repost the patch. I'll do it.

Oren.

Quoted 17 lines
 include/linux/checkpoint.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/checkpoint.h +1 -1
index 84bb7a9..f3e0d11 100644
@@ -301,7 +301,7 @@ extern int restore_memory_contents(struct ckpt_ctx *ctx, struct inode *inode);
 
 #define CKPT_VMA_NOT_SUPPORTED						\
 	(VM_IO | VM_HUGETLB | VM_NONLINEAR | VM_PFNMAP |		\
-	 VM_RESERVED | VM_NORESERVE | VM_HUGETLB | VM_NONLINEAR |	\
+	 VM_RESERVED | VM_HUGETLB | VM_NONLINEAR |	\
 	 VM_MAPPED_COPY | VM_INSERTPAGE | VM_MIXEDMAP | VM_SAO)
 
 /* signals */
#2 lore raw

PATCH 1/1 c/r: Un-blacklist VM_NORESERVE and VM_LOCKED

In reply to Nathan Lynch

Add support for VM_NORESERVE and VM_LOCKED and remove them from the blacklist of vm flags.

VM_NORESERVE: a vma with VM_NORESERVE may segv on a write under low-memory, but reading it (as we do during checkpoint) is fine.

VM_LOCKED: this flag is now explicitly restored for a vma that had this flag, using sys_mlock()

Original patch and reports by Nathan Lynch and Dan Smith.

---
 include/linux/checkpoint.h |    2 +-
 mm/checkpoint.c            |   10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletions(-)
include/linux/checkpoint.h +1 -1
index c338149..a796308 100644
@@ -306,7 +306,7 @@ extern int restore_memory_contents(struct ckpt_ctx *ctx, struct inode *inode);
 
 #define CKPT_VMA_NOT_SUPPORTED						\
 	(VM_IO | VM_HUGETLB | VM_NONLINEAR | VM_PFNMAP |		\
-	 VM_RESERVED | VM_NORESERVE | VM_HUGETLB | VM_NONLINEAR |	\
+	 VM_RESERVED | VM_HUGETLB | VM_NONLINEAR |	\
 	 VM_MAPPED_COPY | VM_INSERTPAGE | VM_MIXEDMAP | VM_SAO)
 
 /* signals */
mm/checkpoint.c +10 -0
index d1d0bcb..70300e8 100644
@@ -24,6 +24,7 @@
 #include <linux/shm.h>
 #include <linux/proc_fs.h>
 #include <linux/swap.h>
+#include <linux/syscalls.h>
 #include <linux/checkpoint.h>
 
 /*
@@ -1018,6 +1019,8 @@ static unsigned long calc_map_flags_bits(unsigned long orig_vm_flags)
 		vm_flags |= MAP_SHARED;
 	else
 		vm_flags |= MAP_PRIVATE;
+	if (orig_vm_flags & VM_NORESERVE)
+		vm_flags |= MAP_NORESERVE;
 
 	return vm_flags;
 }
@@ -1034,6 +1037,7 @@ unsigned long generic_vma_restore(struct mm_struct *mm,
 {
 	unsigned long vm_size, vm_start, vm_flags, vm_prot, vm_pgoff;
 	unsigned long addr;
+	int ret;
 
 	if (h->vm_end < h->vm_start)
 		return -EINVAL;
@@ -1053,6 +1057,12 @@ unsigned long generic_vma_restore(struct mm_struct *mm,
 	ckpt_debug("size %#lx prot %#lx flag %#lx pgoff %#lx => %#lx\n",
 		 vm_size, vm_prot, vm_flags, vm_pgoff, addr);
 
+	if (h->vm_flags & VM_LOCKED && !IS_ERR((void *) addr)) {
+		ret = sys_mlock(addr, vm_size);
+		if (ret < 0)
+			addr = (unsigned long) ret;
+	}
+
 	return addr;
 }
 
Signature · 1 line
1.7.0.4

A message that is not in the archive (sent off-list or not yet received): 1276897775-4911-1-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org

Tested-by
#4 lore raw

Re: [PATCH] c/r: Un-blacklist VM_NORESERVE and VM_LOCKED

OL> Add support for VM_NORESERVE and VM_LOCKED and remove them from OL> the blacklist of vm flags.

OL> VM_NORESERVE: a vma with VM_NORESERVE may segv on a write under OL> low-memory, but reading it (as we do during checkpoint) is fine.

OL> VM_LOCKED: this flag is now explicitly restored for a vma that had OL> this flag, using sys_mlock()

OL> Original patch and reports by Nathan Lynch and Dan Smith.

OL> Signed-off-by: Oren Laadan <[email protected]>

Thanks :)

Signature · 3 lines
Dan Smith
IBM Linux Technology Center
email: danms-r/[email protected]