Skip to content

Commit 44de9d0

Browse files
zyziitorvalds
authored andcommitted
mm: account the total_vm in the vm_stat_account()
vm_stat_account() accounts the shared_vm, stack_vm and reserved_vm now. But we can also account for total_vm in the vm_stat_account() which makes the code tidy. Even for mprotect_fixup(), we can get the right result in the end. Signed-off-by: Huang Shijie <shijie8@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent df858fa commit 44de9d0

File tree

5 files changed

+4
-9
lines changed

5 files changed

+4
-9
lines changed

arch/ia64/kernel/perfmon.c

-1
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,6 @@ pfm_smpl_buffer_alloc(struct task_struct *task, struct file *filp, pfm_context_t
23532353
*/
23542354
insert_vm_struct(mm, vma);
23552355

2356-
mm->total_vm += size >> PAGE_SHIFT;
23572356
vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file,
23582357
vma_pages(vma));
23592358
up_write(&task->mm->mmap_sem);

include/linux/mm.h

+1
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,7 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
15281528
static inline void vm_stat_account(struct mm_struct *mm,
15291529
unsigned long flags, struct file *file, long pages)
15301530
{
1531+
mm->total_vm += pages;
15311532
}
15321533
#endif /* CONFIG_PROC_FS */
15331534

kernel/fork.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
381381
struct file *file;
382382

383383
if (mpnt->vm_flags & VM_DONTCOPY) {
384-
long pages = vma_pages(mpnt);
385-
mm->total_vm -= pages;
386384
vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
387-
-pages);
385+
-vma_pages(mpnt));
388386
continue;
389387
}
390388
charge = 0;

mm/mmap.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,8 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
943943
const unsigned long stack_flags
944944
= VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
945945

946+
mm->total_vm += pages;
947+
946948
if (file) {
947949
mm->shared_vm += pages;
948950
if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
@@ -1347,7 +1349,6 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
13471349
out:
13481350
perf_event_mmap(vma);
13491351

1350-
mm->total_vm += len >> PAGE_SHIFT;
13511352
vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
13521353
if (vm_flags & VM_LOCKED) {
13531354
if (!mlock_vma_pages_range(vma, addr, addr + len))
@@ -1707,7 +1708,6 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
17071708
return -ENOMEM;
17081709

17091710
/* Ok, everything looks good - let it rip */
1710-
mm->total_vm += grow;
17111711
if (vma->vm_flags & VM_LOCKED)
17121712
mm->locked_vm += grow;
17131713
vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
@@ -1889,7 +1889,6 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
18891889

18901890
if (vma->vm_flags & VM_ACCOUNT)
18911891
nr_accounted += nrpages;
1892-
mm->total_vm -= nrpages;
18931892
vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
18941893
vma = remove_vma(vma);
18951894
} while (vma);

mm/mremap.c

-2
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ static unsigned long move_vma(struct vm_area_struct *vma,
260260
* If this were a serious issue, we'd add a flag to do_munmap().
261261
*/
262262
hiwater_vm = mm->hiwater_vm;
263-
mm->total_vm += new_len >> PAGE_SHIFT;
264263
vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
265264

266265
if (do_munmap(mm, old_addr, old_len) < 0) {
@@ -497,7 +496,6 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
497496
goto out;
498497
}
499498

500-
mm->total_vm += pages;
501499
vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
502500
if (vma->vm_flags & VM_LOCKED) {
503501
mm->locked_vm += pages;

0 commit comments

Comments
 (0)