]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - mm/mprotect.c
mm: rework virtual memory accounting
[karo-tx-linux.git] / mm / mprotect.c
index ef5be8eaab001792b469fac1bd5b43cb139d1b0b..c764402c464f10471d4b267fa26911f46e87e149 100644 (file)
@@ -278,6 +278,10 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
         * even if read-only so there is no need to account for them here
         */
        if (newflags & VM_WRITE) {
+               /* Check space limits when area turns into data. */
+               if (!may_expand_vm(mm, newflags, nrpages) &&
+                               may_expand_vm(mm, oldflags, nrpages))
+                       return -ENOMEM;
                if (!(oldflags & (VM_ACCOUNT|VM_WRITE|VM_HUGETLB|
                                                VM_SHARED|VM_NORESERVE))) {
                        charged = nrpages;
@@ -334,8 +338,8 @@ success:
                populate_vma_page_range(vma, start, end, NULL);
        }
 
-       vm_stat_account(mm, oldflags, vma->vm_file, -nrpages);
-       vm_stat_account(mm, newflags, vma->vm_file, nrpages);
+       vm_stat_account(mm, oldflags, -nrpages);
+       vm_stat_account(mm, newflags, nrpages);
        perf_event_mmap(vma);
        return 0;