aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/ia64/kernel/perfmon.c3
-rw-r--r--fs/proc/task_mmu.c7
-rw-r--r--include/linux/mm.h13
-rw-r--r--include/linux/mm_types.h2
-rw-r--r--kernel/fork.c5
-rw-r--r--mm/debug.c4
-rw-r--r--mm/mmap.c63
-rw-r--r--mm/mprotect.c8
-rw-r--r--mm/mremap.c7
9 files changed, 54 insertions, 58 deletions
diff --git a/arch/ia64/kernel/perfmon.c b/arch/ia64/kernel/perfmon.c
index 60e02f7747ff..9cd607b06964 100644
--- a/arch/ia64/kernel/perfmon.c
+++ b/arch/ia64/kernel/perfmon.c
@@ -2332,8 +2332,7 @@ pfm_smpl_buffer_alloc(struct task_struct *task, struct file *filp, pfm_context_t
2332 */ 2332 */
2333 insert_vm_struct(mm, vma); 2333 insert_vm_struct(mm, vma);
2334 2334
2335 vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file, 2335 vm_stat_account(vma->vm_mm, vma->vm_flags, vma_pages(vma));
2336 vma_pages(vma));
2337 up_write(&task->mm->mmap_sem); 2336 up_write(&task->mm->mmap_sem);
2338 2337
2339 /* 2338 /*
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 46d9619d0aea..a353b4c6e86e 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -23,7 +23,7 @@
23 23
24void task_mem(struct seq_file *m, struct mm_struct *mm) 24void task_mem(struct seq_file *m, struct mm_struct *mm)
25{ 25{
26 unsigned long data, text, lib, swap, ptes, pmds, anon, file, shmem; 26 unsigned long text, lib, swap, ptes, pmds, anon, file, shmem;
27 unsigned long hiwater_vm, total_vm, hiwater_rss, total_rss; 27 unsigned long hiwater_vm, total_vm, hiwater_rss, total_rss;
28 28
29 anon = get_mm_counter(mm, MM_ANONPAGES); 29 anon = get_mm_counter(mm, MM_ANONPAGES);
@@ -44,7 +44,6 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
44 if (hiwater_rss < mm->hiwater_rss) 44 if (hiwater_rss < mm->hiwater_rss)
45 hiwater_rss = mm->hiwater_rss; 45 hiwater_rss = mm->hiwater_rss;
46 46
47 data = mm->total_vm - mm->shared_vm - mm->stack_vm;
48 text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) >> 10; 47 text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) >> 10;
49 lib = (mm->exec_vm << (PAGE_SHIFT-10)) - text; 48 lib = (mm->exec_vm << (PAGE_SHIFT-10)) - text;
50 swap = get_mm_counter(mm, MM_SWAPENTS); 49 swap = get_mm_counter(mm, MM_SWAPENTS);
@@ -76,7 +75,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
76 anon << (PAGE_SHIFT-10), 75 anon << (PAGE_SHIFT-10),
77 file << (PAGE_SHIFT-10), 76 file << (PAGE_SHIFT-10),
78 shmem << (PAGE_SHIFT-10), 77 shmem << (PAGE_SHIFT-10),
79 data << (PAGE_SHIFT-10), 78 mm->data_vm << (PAGE_SHIFT-10),
80 mm->stack_vm << (PAGE_SHIFT-10), text, lib, 79 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
81 ptes >> 10, 80 ptes >> 10,
82 pmds >> 10, 81 pmds >> 10,
@@ -97,7 +96,7 @@ unsigned long task_statm(struct mm_struct *mm,
97 get_mm_counter(mm, MM_SHMEMPAGES); 96 get_mm_counter(mm, MM_SHMEMPAGES);
98 *text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) 97 *text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK))
99 >> PAGE_SHIFT; 98 >> PAGE_SHIFT;
100 *data = mm->total_vm - mm->shared_vm; 99 *data = mm->data_vm + mm->stack_vm;
101 *resident = *shared + get_mm_counter(mm, MM_ANONPAGES); 100 *resident = *shared + get_mm_counter(mm, MM_ANONPAGES);
102 return mm->total_vm; 101 return mm->total_vm;
103} 102}
diff --git a/include/linux/mm.h b/include/linux/mm.h
index ec9d4559514d..839d9e9a1c38 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1929,7 +1929,9 @@ extern void mm_drop_all_locks(struct mm_struct *mm);
1929extern void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file); 1929extern void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file);
1930extern struct file *get_mm_exe_file(struct mm_struct *mm); 1930extern struct file *get_mm_exe_file(struct mm_struct *mm);
1931 1931
1932extern int may_expand_vm(struct mm_struct *mm, unsigned long npages); 1932extern bool may_expand_vm(struct mm_struct *, vm_flags_t, unsigned long npages);
1933extern void vm_stat_account(struct mm_struct *, vm_flags_t, long npages);
1934
1933extern struct vm_area_struct *_install_special_mapping(struct mm_struct *mm, 1935extern struct vm_area_struct *_install_special_mapping(struct mm_struct *mm,
1934 unsigned long addr, unsigned long len, 1936 unsigned long addr, unsigned long len,
1935 unsigned long flags, 1937 unsigned long flags,
@@ -2147,15 +2149,6 @@ typedef int (*pte_fn_t)(pte_t *pte, pgtable_t token, unsigned long addr,
2147extern int apply_to_page_range(struct mm_struct *mm, unsigned long address, 2149extern int apply_to_page_range(struct mm_struct *mm, unsigned long address,
2148 unsigned long size, pte_fn_t fn, void *data); 2150 unsigned long size, pte_fn_t fn, void *data);
2149 2151
2150#ifdef CONFIG_PROC_FS
2151void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
2152#else
2153static inline void vm_stat_account(struct mm_struct *mm,
2154 unsigned long flags, struct file *file, long pages)
2155{
2156 mm->total_vm += pages;
2157}
2158#endif /* CONFIG_PROC_FS */
2159 2152
2160#ifdef CONFIG_DEBUG_PAGEALLOC 2153#ifdef CONFIG_DEBUG_PAGEALLOC
2161extern bool _debug_pagealloc_enabled; 2154extern bool _debug_pagealloc_enabled;
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 207890be93c8..6bc9a0ce2253 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -427,7 +427,7 @@ struct mm_struct {
427 unsigned long total_vm; /* Total pages mapped */ 427 unsigned long total_vm; /* Total pages mapped */
428 unsigned long locked_vm; /* Pages that have PG_mlocked set */ 428 unsigned long locked_vm; /* Pages that have PG_mlocked set */
429 unsigned long pinned_vm; /* Refcount permanently increased */ 429 unsigned long pinned_vm; /* Refcount permanently increased */
430 unsigned long shared_vm; /* Shared pages (files) */ 430 unsigned long data_vm; /* VM_WRITE & ~VM_SHARED/GROWSDOWN */
431 unsigned long exec_vm; /* VM_EXEC & ~VM_WRITE */ 431 unsigned long exec_vm; /* VM_EXEC & ~VM_WRITE */
432 unsigned long stack_vm; /* VM_GROWSUP/DOWN */ 432 unsigned long stack_vm; /* VM_GROWSUP/DOWN */
433 unsigned long def_flags; 433 unsigned long def_flags;
diff --git a/kernel/fork.c b/kernel/fork.c
index 51915842f1c0..2e391c754ae7 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -414,7 +414,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
414 RCU_INIT_POINTER(mm->exe_file, get_mm_exe_file(oldmm)); 414 RCU_INIT_POINTER(mm->exe_file, get_mm_exe_file(oldmm));
415 415
416 mm->total_vm = oldmm->total_vm; 416 mm->total_vm = oldmm->total_vm;
417 mm->shared_vm = oldmm->shared_vm; 417 mm->data_vm = oldmm->data_vm;
418 mm->exec_vm = oldmm->exec_vm; 418 mm->exec_vm = oldmm->exec_vm;
419 mm->stack_vm = oldmm->stack_vm; 419 mm->stack_vm = oldmm->stack_vm;
420 420
@@ -433,8 +433,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
433 struct file *file; 433 struct file *file;
434 434
435 if (mpnt->vm_flags & VM_DONTCOPY) { 435 if (mpnt->vm_flags & VM_DONTCOPY) {
436 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file, 436 vm_stat_account(mm, mpnt->vm_flags, -vma_pages(mpnt));
437 -vma_pages(mpnt));
438 continue; 437 continue;
439 } 438 }
440 charge = 0; 439 charge = 0;
diff --git a/mm/debug.c b/mm/debug.c
index 668aa35191ca..5d2072ed8d5e 100644
--- a/mm/debug.c
+++ b/mm/debug.c
@@ -175,7 +175,7 @@ void dump_mm(const struct mm_struct *mm)
175 "mmap_base %lu mmap_legacy_base %lu highest_vm_end %lu\n" 175 "mmap_base %lu mmap_legacy_base %lu highest_vm_end %lu\n"
176 "pgd %p mm_users %d mm_count %d nr_ptes %lu nr_pmds %lu map_count %d\n" 176 "pgd %p mm_users %d mm_count %d nr_ptes %lu nr_pmds %lu map_count %d\n"
177 "hiwater_rss %lx hiwater_vm %lx total_vm %lx locked_vm %lx\n" 177 "hiwater_rss %lx hiwater_vm %lx total_vm %lx locked_vm %lx\n"
178 "pinned_vm %lx shared_vm %lx exec_vm %lx stack_vm %lx\n" 178 "pinned_vm %lx data_vm %lx exec_vm %lx stack_vm %lx\n"
179 "start_code %lx end_code %lx start_data %lx end_data %lx\n" 179 "start_code %lx end_code %lx start_data %lx end_data %lx\n"
180 "start_brk %lx brk %lx start_stack %lx\n" 180 "start_brk %lx brk %lx start_stack %lx\n"
181 "arg_start %lx arg_end %lx env_start %lx env_end %lx\n" 181 "arg_start %lx arg_end %lx env_start %lx env_end %lx\n"
@@ -209,7 +209,7 @@ void dump_mm(const struct mm_struct *mm)
209 mm_nr_pmds((struct mm_struct *)mm), 209 mm_nr_pmds((struct mm_struct *)mm),
210 mm->map_count, 210 mm->map_count,
211 mm->hiwater_rss, mm->hiwater_vm, mm->total_vm, mm->locked_vm, 211 mm->hiwater_rss, mm->hiwater_vm, mm->total_vm, mm->locked_vm,
212 mm->pinned_vm, mm->shared_vm, mm->exec_vm, mm->stack_vm, 212 mm->pinned_vm, mm->data_vm, mm->exec_vm, mm->stack_vm,
213 mm->start_code, mm->end_code, mm->start_data, mm->end_data, 213 mm->start_code, mm->end_code, mm->start_data, mm->end_data,
214 mm->start_brk, mm->brk, mm->start_stack, 214 mm->start_brk, mm->brk, mm->start_stack,
215 mm->arg_start, mm->arg_end, mm->env_start, mm->env_end, 215 mm->arg_start, mm->arg_end, mm->env_start, mm->env_end,
diff --git a/mm/mmap.c b/mm/mmap.c
index f32b84ad621a..b3f00b616b81 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1220,24 +1220,6 @@ none:
1220 return NULL; 1220 return NULL;
1221} 1221}
1222 1222
1223#ifdef CONFIG_PROC_FS
1224void vm_stat_account(struct mm_struct *mm, unsigned long flags,
1225 struct file *file, long pages)
1226{
1227 const unsigned long stack_flags
1228 = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
1229
1230 mm->total_vm += pages;
1231
1232 if (file) {
1233 mm->shared_vm += pages;
1234 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
1235 mm->exec_vm += pages;
1236 } else if (flags & stack_flags)
1237 mm->stack_vm += pages;
1238}
1239#endif /* CONFIG_PROC_FS */
1240
1241/* 1223/*
1242 * If a hint addr is less than mmap_min_addr change hint to be as 1224 * If a hint addr is less than mmap_min_addr change hint to be as
1243 * low as possible but still greater than mmap_min_addr 1225 * low as possible but still greater than mmap_min_addr
@@ -1556,7 +1538,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
1556 unsigned long charged = 0; 1538 unsigned long charged = 0;
1557 1539
1558 /* Check against address space limit. */ 1540 /* Check against address space limit. */
1559 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) { 1541 if (!may_expand_vm(mm, vm_flags, len >> PAGE_SHIFT)) {
1560 unsigned long nr_pages; 1542 unsigned long nr_pages;
1561 1543
1562 /* 1544 /*
@@ -1565,7 +1547,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
1565 */ 1547 */
1566 nr_pages = count_vma_pages_range(mm, addr, addr + len); 1548 nr_pages = count_vma_pages_range(mm, addr, addr + len);
1567 1549
1568 if (!may_expand_vm(mm, (len >> PAGE_SHIFT) - nr_pages)) 1550 if (!may_expand_vm(mm, vm_flags,
1551 (len >> PAGE_SHIFT) - nr_pages))
1569 return -ENOMEM; 1552 return -ENOMEM;
1570 } 1553 }
1571 1554
@@ -1664,7 +1647,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
1664out: 1647out:
1665 perf_event_mmap(vma); 1648 perf_event_mmap(vma);
1666 1649
1667 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT); 1650 vm_stat_account(mm, vm_flags, len >> PAGE_SHIFT);
1668 if (vm_flags & VM_LOCKED) { 1651 if (vm_flags & VM_LOCKED) {
1669 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) || 1652 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
1670 vma == get_gate_vma(current->mm))) 1653 vma == get_gate_vma(current->mm)))
@@ -2111,7 +2094,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
2111 unsigned long new_start, actual_size; 2094 unsigned long new_start, actual_size;
2112 2095
2113 /* address space limit tests */ 2096 /* address space limit tests */
2114 if (!may_expand_vm(mm, grow)) 2097 if (!may_expand_vm(mm, vma->vm_flags, grow))
2115 return -ENOMEM; 2098 return -ENOMEM;
2116 2099
2117 /* Stack limit test */ 2100 /* Stack limit test */
@@ -2208,8 +2191,7 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
2208 spin_lock(&mm->page_table_lock); 2191 spin_lock(&mm->page_table_lock);
2209 if (vma->vm_flags & VM_LOCKED) 2192 if (vma->vm_flags & VM_LOCKED)
2210 mm->locked_vm += grow; 2193 mm->locked_vm += grow;
2211 vm_stat_account(mm, vma->vm_flags, 2194 vm_stat_account(mm, vma->vm_flags, grow);
2212 vma->vm_file, grow);
2213 anon_vma_interval_tree_pre_update_vma(vma); 2195 anon_vma_interval_tree_pre_update_vma(vma);
2214 vma->vm_end = address; 2196 vma->vm_end = address;
2215 anon_vma_interval_tree_post_update_vma(vma); 2197 anon_vma_interval_tree_post_update_vma(vma);
@@ -2284,8 +2266,7 @@ int expand_downwards(struct vm_area_struct *vma,
2284 spin_lock(&mm->page_table_lock); 2266 spin_lock(&mm->page_table_lock);
2285 if (vma->vm_flags & VM_LOCKED) 2267 if (vma->vm_flags & VM_LOCKED)
2286 mm->locked_vm += grow; 2268 mm->locked_vm += grow;
2287 vm_stat_account(mm, vma->vm_flags, 2269 vm_stat_account(mm, vma->vm_flags, grow);
2288 vma->vm_file, grow);
2289 anon_vma_interval_tree_pre_update_vma(vma); 2270 anon_vma_interval_tree_pre_update_vma(vma);
2290 vma->vm_start = address; 2271 vma->vm_start = address;
2291 vma->vm_pgoff -= grow; 2272 vma->vm_pgoff -= grow;
@@ -2399,7 +2380,7 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
2399 2380
2400 if (vma->vm_flags & VM_ACCOUNT) 2381 if (vma->vm_flags & VM_ACCOUNT)
2401 nr_accounted += nrpages; 2382 nr_accounted += nrpages;
2402 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages); 2383 vm_stat_account(mm, vma->vm_flags, -nrpages);
2403 vma = remove_vma(vma); 2384 vma = remove_vma(vma);
2404 } while (vma); 2385 } while (vma);
2405 vm_unacct_memory(nr_accounted); 2386 vm_unacct_memory(nr_accounted);
@@ -2769,7 +2750,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
2769 } 2750 }
2770 2751
2771 /* Check against address space limits *after* clearing old maps... */ 2752 /* Check against address space limits *after* clearing old maps... */
2772 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) 2753 if (!may_expand_vm(mm, flags, len >> PAGE_SHIFT))
2773 return -ENOMEM; 2754 return -ENOMEM;
2774 2755
2775 if (mm->map_count > sysctl_max_map_count) 2756 if (mm->map_count > sysctl_max_map_count)
@@ -2804,6 +2785,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
2804out: 2785out:
2805 perf_event_mmap(vma); 2786 perf_event_mmap(vma);
2806 mm->total_vm += len >> PAGE_SHIFT; 2787 mm->total_vm += len >> PAGE_SHIFT;
2788 mm->data_vm += len >> PAGE_SHIFT;
2807 if (flags & VM_LOCKED) 2789 if (flags & VM_LOCKED)
2808 mm->locked_vm += (len >> PAGE_SHIFT); 2790 mm->locked_vm += (len >> PAGE_SHIFT);
2809 vma->vm_flags |= VM_SOFTDIRTY; 2791 vma->vm_flags |= VM_SOFTDIRTY;
@@ -2995,9 +2977,28 @@ out:
2995 * Return true if the calling process may expand its vm space by the passed 2977 * Return true if the calling process may expand its vm space by the passed
2996 * number of pages 2978 * number of pages
2997 */ 2979 */
2998int may_expand_vm(struct mm_struct *mm, unsigned long npages) 2980bool may_expand_vm(struct mm_struct *mm, vm_flags_t flags, unsigned long npages)
2999{ 2981{
3000 return mm->total_vm + npages <= rlimit(RLIMIT_AS) >> PAGE_SHIFT; 2982 if (mm->total_vm + npages > rlimit(RLIMIT_AS) >> PAGE_SHIFT)
2983 return false;
2984
2985 if ((flags & (VM_WRITE | VM_SHARED | (VM_STACK_FLAGS &
2986 (VM_GROWSUP | VM_GROWSDOWN)))) == VM_WRITE)
2987 return mm->data_vm + npages <= rlimit(RLIMIT_DATA);
2988
2989 return true;
2990}
2991
2992void vm_stat_account(struct mm_struct *mm, vm_flags_t flags, long npages)
2993{
2994 mm->total_vm += npages;
2995
2996 if ((flags & (VM_EXEC | VM_WRITE)) == VM_EXEC)
2997 mm->exec_vm += npages;
2998 else if (flags & (VM_STACK_FLAGS & (VM_GROWSUP | VM_GROWSDOWN)))
2999 mm->stack_vm += npages;
3000 else if ((flags & (VM_WRITE | VM_SHARED)) == VM_WRITE)
3001 mm->data_vm += npages;
3001} 3002}
3002 3003
3003static int special_mapping_fault(struct vm_area_struct *vma, 3004static int special_mapping_fault(struct vm_area_struct *vma,
@@ -3079,7 +3080,7 @@ static struct vm_area_struct *__install_special_mapping(
3079 if (ret) 3080 if (ret)
3080 goto out; 3081 goto out;
3081 3082
3082 mm->total_vm += len >> PAGE_SHIFT; 3083 vm_stat_account(mm, vma->vm_flags, len >> PAGE_SHIFT);
3083 3084
3084 perf_event_mmap(vma); 3085 perf_event_mmap(vma);
3085 3086
diff --git a/mm/mprotect.c b/mm/mprotect.c
index ef5be8eaab00..c764402c464f 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -278,6 +278,10 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
278 * even if read-only so there is no need to account for them here 278 * even if read-only so there is no need to account for them here
279 */ 279 */
280 if (newflags & VM_WRITE) { 280 if (newflags & VM_WRITE) {
281 /* Check space limits when area turns into data. */
282 if (!may_expand_vm(mm, newflags, nrpages) &&
283 may_expand_vm(mm, oldflags, nrpages))
284 return -ENOMEM;
281 if (!(oldflags & (VM_ACCOUNT|VM_WRITE|VM_HUGETLB| 285 if (!(oldflags & (VM_ACCOUNT|VM_WRITE|VM_HUGETLB|
282 VM_SHARED|VM_NORESERVE))) { 286 VM_SHARED|VM_NORESERVE))) {
283 charged = nrpages; 287 charged = nrpages;
@@ -334,8 +338,8 @@ success:
334 populate_vma_page_range(vma, start, end, NULL); 338 populate_vma_page_range(vma, start, end, NULL);
335 } 339 }
336 340
337 vm_stat_account(mm, oldflags, vma->vm_file, -nrpages); 341 vm_stat_account(mm, oldflags, -nrpages);
338 vm_stat_account(mm, newflags, vma->vm_file, nrpages); 342 vm_stat_account(mm, newflags, nrpages);
339 perf_event_mmap(vma); 343 perf_event_mmap(vma);
340 return 0; 344 return 0;
341 345
diff --git a/mm/mremap.c b/mm/mremap.c
index de824e72c3e8..e55b157865d5 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -317,7 +317,7 @@ static unsigned long move_vma(struct vm_area_struct *vma,
317 * If this were a serious issue, we'd add a flag to do_munmap(). 317 * If this were a serious issue, we'd add a flag to do_munmap().
318 */ 318 */
319 hiwater_vm = mm->hiwater_vm; 319 hiwater_vm = mm->hiwater_vm;
320 vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT); 320 vm_stat_account(mm, vma->vm_flags, new_len >> PAGE_SHIFT);
321 321
322 /* Tell pfnmap has moved from this vma */ 322 /* Tell pfnmap has moved from this vma */
323 if (unlikely(vma->vm_flags & VM_PFNMAP)) 323 if (unlikely(vma->vm_flags & VM_PFNMAP))
@@ -383,7 +383,8 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
383 return ERR_PTR(-EAGAIN); 383 return ERR_PTR(-EAGAIN);
384 } 384 }
385 385
386 if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) 386 if (!may_expand_vm(mm, vma->vm_flags,
387 (new_len - old_len) >> PAGE_SHIFT))
387 return ERR_PTR(-ENOMEM); 388 return ERR_PTR(-ENOMEM);
388 389
389 if (vma->vm_flags & VM_ACCOUNT) { 390 if (vma->vm_flags & VM_ACCOUNT) {
@@ -545,7 +546,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
545 goto out; 546 goto out;
546 } 547 }
547 548
548 vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages); 549 vm_stat_account(mm, vma->vm_flags, pages);
549 if (vma->vm_flags & VM_LOCKED) { 550 if (vma->vm_flags & VM_LOCKED) {
550 mm->locked_vm += pages; 551 mm->locked_vm += pages;
551 locked = true; 552 locked = true;