From: Hugh Dickins The procfs shared_vm accounting in do_mmap_pgoff didn't balance with munmap in the case of shared anonymous: because file comes in NULL, whereas vm_file gets set at the end by shmem_zero_setup. Update file; and update vm_flags (a driver is likely to add VM_IO or VM_RESERVED, modifying reserved_vm); and update pgoff (doesn't affect procfs accounting, but could affect vma_merge - though at present all drivers which modify vm_pgoff set a VM_SPECIAL which prevents merging). And do that __vm_stat_account before advancing to make_pages_present. Signed-off-by: Hugh Dickins Signed-off-by: Andrew Morton --- 25-akpm/mm/mmap.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletion(-) diff -puN mm/mmap.c~statm-__vm_stat_accounting mm/mmap.c --- 25/mm/mmap.c~statm-__vm_stat_accounting 2004-10-24 23:13:38.394125392 -0700 +++ 25-akpm/mm/mmap.c 2004-10-24 23:13:38.398124784 -0700 @@ -988,9 +988,12 @@ munmap_back: * f_op->mmap method. -DaveM */ addr = vma->vm_start; + pgoff = vma->vm_pgoff; + vm_flags = vma->vm_flags; if (!file || !vma_merge(mm, prev, addr, vma->vm_end, vma->vm_flags, NULL, file, pgoff, vma_policy(vma))) { + file = vma->vm_file; vma_link(mm, vma, prev, rb_link, rb_parent); if (correct_wcount) atomic_inc(&inode->i_writecount); @@ -1005,6 +1008,7 @@ munmap_back: } out: mm->total_vm += len >> PAGE_SHIFT; + __vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT); if (vm_flags & VM_LOCKED) { mm->locked_vm += len >> PAGE_SHIFT; make_pages_present(addr, addr + len); @@ -1015,7 +1019,6 @@ out: pgoff, flags & MAP_NONBLOCK); down_write(&mm->mmap_sem); } - __vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT); return addr; unmap_and_free_vma: _