]> err.no Git - linux-2.6/blobdiff - mm/mremap.c
Merge by hand (conflicts in sd.c)
[linux-2.6] / mm / mremap.c
index 0d1c1b9c7a0a37fa6e91d370d43db496eeedbf4a..fc45dc9a617b013f4db5aea5fe7898bf6cd677b6 100644 (file)
@@ -224,6 +224,13 @@ static unsigned long move_vma(struct vm_area_struct *vma,
                        split = 1;
        }
 
+       /*
+        * if we failed to move page tables we still do total_vm increment
+        * since do_munmap() will decrement it by old_len == new_len
+        */
+       mm->total_vm += new_len >> PAGE_SHIFT;
+       __vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
+
        if (do_munmap(mm, old_addr, old_len) < 0) {
                /* OOM: unable to split vma, just get accounts right */
                vm_unacct_memory(excess >> PAGE_SHIFT);
@@ -237,8 +244,6 @@ static unsigned long move_vma(struct vm_area_struct *vma,
                        vma->vm_next->vm_flags |= VM_ACCOUNT;
        }
 
-       mm->total_vm += new_len >> PAGE_SHIFT;
-       __vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
        if (vm_flags & VM_LOCKED) {
                mm->locked_vm += new_len >> PAGE_SHIFT;
                if (new_len > old_len)
@@ -347,10 +352,10 @@ unsigned long do_mremap(unsigned long addr,
                if (locked > lock_limit && !capable(CAP_IPC_LOCK))
                        goto out;
        }
-       ret = -ENOMEM;
-       if ((current->mm->total_vm << PAGE_SHIFT) + (new_len - old_len)
-           > current->signal->rlim[RLIMIT_AS].rlim_cur)
+       if (!may_expand_vm(current->mm, (new_len - old_len) >> PAGE_SHIFT)) {
+               ret = -ENOMEM;
                goto out;
+       }
 
        if (vma->vm_flags & VM_ACCOUNT) {
                charged = (new_len - old_len) >> PAGE_SHIFT;