Skip to contentSkip to conversation

Xen 4.0.1 "xc_map_foreign_batch: mmap failed: Cannot allocate memory"

DISCUSSION Jan Beulich 3 participants 5 messages Jan 7, 2011 – Jan 10, 2011

lore
Share & tools
lore
#0 lore raw
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines · Charles Arnold
Quoted 1 line · Charles Arnold

Attached is the messages file with the printk output.

Hmm, a failure due to may_expand_vm() is really odd. Something must be explicitly setting a non-infinite RLIMIT_AS on qemu-dm (or one of its parents), as the default is "infinite" (as reaching "infinity"
- being ~0UL - is simply impossible, and unduly large lengths should be caught by get_unmapped_area() already).

/proc/<pid>/limits would at least tell us what the limit is.

And certainly qemu-dm needs to be prepared to have a non-infinite address space limit set on it.

Jan - Charles

Quoted 82 lines
Quoted 81 lines
Quoted 79 lines

---

mm/mmap.c +6 -2
index b179abb..3f65277 100644
@@ -991,16 +991,20 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned 
 
 
 long addr,
 
 	/* Careful about overflows.. */
 	len = PAGE_ALIGN(len);
-	if (!len)
+	if (!len) {
+		printk("DEBUG PAGE_ALIGN ENOMEM\n");
 		return -ENOMEM;
+	}
 
 	/* offset overflow? */
 	if ((pgoff + (len >> PAGE_SHIFT)) < pgoff)
                return -EOVERFLOW;
 
 	/* Too many mappings? */
-	if (mm->map_count > sysctl_max_map_count)
+	if (mm->map_count > sysctl_max_map_count) {
+		printk("DEBUG too many mappings ENOMEM\n");
 		return -ENOMEM;
+	}
mm/mmap.c +6 -2
 	/* Obtain the address to map to. we verify (or select) it and ensure
 	 * that it represents a valid section of the address space.
@@ -1231,14 +1235,18 @@ unsigned long mmap_region(struct file *file, unsigned 
 
 
 long addr,
 munmap_back:
 	vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
 	if (vma && vma->vm_start < addr + len) {
-		if (do_munmap(mm, addr, len))
+		if (do_munmap(mm, addr, len)) {
+			printk("DEBUG find_vma_prepare ENOMEM\n");
 			return -ENOMEM;
+		}
 		goto munmap_back;
 	}
 
 	/* Check against address space limit. */
-	if (!may_expand_vm(mm, len >> PAGE_SHIFT))
+	if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
+		printk("DEBUG may_expand_vm ENOMEM\n");
 		return -ENOMEM;
+	}
mm/mmap.c +4 -1
 	/*
 	 * Set 'VM_NORESERVE' if we should not account for the
@@ -1259,8 +1267,10 @@ munmap_back:
 	 */
 	if (accountable_mapping(file, vm_flags)) {
 		charged = len >> PAGE_SHIFT;
-		if (security_vm_enough_memory(charged))
+		if (security_vm_enough_memory(charged)) {
+			printk("DEBUG accountable_mapping ENOMEM\n");
 			return -ENOMEM;
+		}
 		vm_flags |= VM_ACCOUNT;
 	}
 
@@ -1278,6 +1288,7 @@ munmap_back:
 	 */
 	vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
 	if (!vma) {
+		printk("DEBUG kmem_cache_zalloc ENOMEM\n");
 		error = -ENOMEM;
 		goto unacct_error;
 	}
#1 lore raw
Quoted 4 lines · Jan Beulich
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines · Charles Arnold
Quoted 1 line · Charles Arnold

Attached is the messages file with the printk output.

Quoted 8 lines

Hmm, a failure due to may_expand_vm() is really odd. Something must be explicitly setting a non-infinite RLIMIT_AS on qemu-dm (or one of its parents), as the default is "infinite" (as reaching "infinity"
- being ~0UL - is simply impossible, and unduly large lengths should be caught by get_unmapped_area() already).

/proc/<pid>/limits would at least tell us what the limit is.

Knowing this would be very interesting.

Quoted 3 lines

And certainly qemu-dm needs to be prepared to have a non-infinite address space limit set on it.

Currently the number of buckets and the bucket size in the mapcache are statically defined depending on x86_32/x86_64.
It shouldn't be difficult to make them dynamic depending on RLIMIT_AS.

#2 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line

On 07.01.11 at 12:18, Stefano Stabellini <[email protected]>

Quoted 12 lines · wrote:
Quoted 2 lines · Jan Beulich
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines · Charles Arnold
Quoted 1 line

On 1/6/2011 at 10:14 AM, in message <[email protected]>,

Quoted 8 lines · Charles Arnold
Quoted 1 line

Attached is the messages file with the printk output.

Hmm, a failure due to may_expand_vm() is really odd. Something must be explicitly setting a non-infinite RLIMIT_AS on qemu-dm (or one of its parents), as the default is "infinite" (as reaching "infinity"
- being ~0UL - is simply impossible, and unduly large lengths should be caught by get_unmapped_area() already).

Quoted 4 lines
Quoted 2 lines

/proc/<pid>/limits would at least tell us what the limit is.

Knowing this would be very interesting.

I just found that on SLE11 this gets set to 80% (admin controllable) of the sum of physical (not accounting for the balloon) and swap memory. That's (at least on large systems using a relatively low dom0_mem= value) likely awfully low for qemu-dm serving large guests.

However, it's only rlim_cur that gets set this low by default, and hence it would seem reasonable to me to have qemu-dm bump it to whatever getrlimit() returns in rlimit_max.

Quoted 7 lines
Quoted 3 lines

And certainly qemu-dm needs to be prepared to have a non-infinite address space limit set on it.

Currently the number of buckets and the bucket size in the mapcache are statically defined depending on x86_32/x86_64.
It shouldn't be difficult to make them dynamic depending on RLIMIT_AS.

That still wouldn't help if RLIMIT_AS gets changed when it's already running. The only proper way to deal with the situation as a whole (including but not limited to rlim_max being relatively low) is to get proper error handling implemented, either causing guest I/O to be throttled when mmap() fails, or no longer used mappings cleared (if that isn't being done already).

Jan

#3 lore raw
Quoted 10 lines · Jan Beulich

I just found that on SLE11 this gets set to 80% (admin controllable) of the sum of physical (not accounting for the balloon) and swap memory. That's (at least on large systems using a relatively low dom0_mem= value) likely awfully low for qemu-dm serving large guests.

However, it's only rlim_cur that gets set this low by default, and hence it would seem reasonable to me to have qemu-dm bump it to whatever getrlimit() returns in rlimit_max.

It seems reasonable to me too.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

And certainly qemu-dm needs to be prepared to have a non-infinite address space limit set on it.

Currently the number of buckets and the bucket size in the mapcache are statically defined depending on x86_32/x86_64.
It shouldn't be difficult to make them dynamic depending on RLIMIT_AS.

Quoted 7 lines

That still wouldn't help if RLIMIT_AS gets changed when it's already running. The only proper way to deal with the situation as a whole (including but not limited to rlim_max being relatively low) is to get proper error handling implemented, either causing guest I/O to be throttled when mmap() fails, or no longer used mappings cleared (if that isn't being done already).

I am not sure that handling RLIMIT_AS dynamic changes while qemu is running is worth the effort; but for sure we have to deal with RLIMIT_AS being lower than expect at qemu startup time.

#4 lore raw
In reply to Stefano Stabellini
Quoted 1 line
Quoted 1 line
Quoted 1 line

On 1/7/2011 at 04:18 AM, in message

<alpine.DEB.2.00.1101071115280.2390@kaball-desktop>, Stefano Stabellini

Quoted 12 lines · <[email protected]> wrote:
Quoted 2 lines · Jan Beulich
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines · Charles Arnold
Quoted 1 line

On 1/6/2011 at 10:14 AM, in message <[email protected]>,

Quoted 8 lines · Charles Arnold
Quoted 1 line

Attached is the messages file with the printk output.

Hmm, a failure due to may_expand_vm() is really odd. Something must be explicitly setting a non-infinite RLIMIT_AS on qemu-dm (or one of its parents), as the default is "infinite" (as reaching "infinity"
- being ~0UL - is simply impossible, and unduly large lengths should be caught by get_unmapped_area() already).

Quoted 6 lines
Quoted 2 lines

/proc/<pid>/limits would at least tell us what the limit is.

Knowing this would be very interesting.

From the qemu-dm process handling the win2k8r2 guest.

Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            unlimited            unlimited            bytes
Max core file size        1024                 unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             15207                15207                processes
Max open files            1024                 8192                 files
Max locked memory         unlimited            unlimited            bytes
Max address space         3454238720           unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       15207                15207                signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us
Quoted 1 line

From the xend parent process

Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        1024                 unlimited            bytes
Max resident set          1838370816           unlimited            bytes
Max processes             15207                15207                processes
Max open files            1024                 8192                 files
Max locked memory         65536                262144               bytes
Max address space         3454238720           unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       15207                15207                signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us

- Charles