[PATCH 1/3] statm: __vm_stat_accounting

From: Hugh Dickins
Date: Sun Oct 24 2004 - 11:04:11 EST


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 <hugh@xxxxxxxxxxx>
---
mm/mmap.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletion(-)

--- 2.6.10-rc1/mm/mmap.c 2004-10-23 12:44:13.000000000 +0100
+++ linux/mm/mmap.c 2004-10-23 20:43:24.000000000 +0100
@@ -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:

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/