[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

anon map and datasize



this diff changes uvm so that anonymous memory mappings are counted 
towards a process's data size.  it should not drastically alter anything, 
but limit enforcement should work better and top should be more accurate.

looking for testers.

Index: uvm/uvm_extern.h
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_extern.h,v
retrieving revision 1.55
diff -u -r1.55 uvm_extern.h
--- uvm/uvm_extern.h	21 Apr 2005 04:39:34 -0000	1.55
+++ uvm/uvm_extern.h	22 May 2005 08:20:00 -0000
@@ -517,9 +517,10 @@
 void			uvm_km_putpage(void *);
 
 /* uvm_map.c */
-int			uvm_map(vm_map_t, vaddr_t *, vsize_t,
+#define	uvm_map(_m, _a, _sz, _u, _f, _al, _fl) uvm_map_p(_m, _a, _sz, _u, _f, _al, _fl, 0)
+int			uvm_map_p(vm_map_t, vaddr_t *, vsize_t,
 				struct uvm_object *, voff_t, vsize_t,
-				uvm_flag_t);
+				uvm_flag_t, struct proc *);
 int			uvm_map_pageable(vm_map_t, vaddr_t, 
 				vaddr_t, boolean_t, int);
 int			uvm_map_pageable_all(vm_map_t, int, vsize_t);
@@ -547,7 +548,7 @@
 /* uvm_mmap.c */
 int			uvm_mmap(vm_map_t, vaddr_t *, vsize_t,
 				vm_prot_t, vm_prot_t, int, 
-				caddr_t, voff_t, vsize_t);
+				caddr_t, voff_t, vsize_t, struct proc *);
 
 /* uvm_page.c */
 struct vm_page		*uvm_pagealloc_strat(struct uvm_object *,
Index: uvm/uvm_io.c
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_io.c,v
retrieving revision 1.14
diff -u -r1.14 uvm_io.c
--- uvm/uvm_io.c	29 Oct 2002 18:30:21 -0000	1.14
+++ uvm/uvm_io.c	22 May 2005 08:20:00 -0000
@@ -139,7 +139,7 @@
 
 		vm_map_lock(kernel_map);
 		uvm_unmap_remove(kernel_map, kva, kva+chunksz,
-		    &dead_entries);
+		    &dead_entries, NULL);
 		vm_map_unlock(kernel_map);
 
 		if (dead_entries != NULL)
Index: uvm/uvm_km.c
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_km.c,v
retrieving revision 1.45
diff -u -r1.45 uvm_km.c
--- uvm/uvm_km.c	30 Dec 2004 08:28:39 -0000	1.45
+++ uvm/uvm_km.c	22 May 2005 08:20:00 -0000
@@ -604,7 +604,7 @@
 
 	vm_map_lock(map);
 	uvm_unmap_remove(map, trunc_page(addr), round_page(addr+size), 
-			 &dead_entries);
+			 &dead_entries, NULL);
 	wakeup(map);
 	vm_map_unlock(map);
 
Index: uvm/uvm_map.c
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_map.c,v
retrieving revision 1.70
diff -u -r1.70 uvm_map.c
--- uvm/uvm_map.c	30 Dec 2004 08:28:39 -0000	1.70
+++ uvm/uvm_map.c	22 May 2005 08:20:00 -0000
@@ -695,7 +695,7 @@
  */
 
 int
-uvm_map(map, startp, size, uobj, uoffset, align, flags)
+uvm_map_p(map, startp, size, uobj, uoffset, align, flags, p)
 	vm_map_t map;
 	vaddr_t *startp;	/* IN/OUT */
 	vsize_t size;
@@ -703,6 +703,7 @@
 	voff_t uoffset;
 	vsize_t align;
 	uvm_flag_t flags;
+	struct proc *p;
 {
 	vm_map_entry_t prev_entry, new_entry;
 	vm_prot_t prot = UVM_PROTECTION(flags), maxprot =
@@ -914,6 +915,9 @@
 	uvm_map_entry_link(map, prev_entry, new_entry);
 
 	map->size += size;
+	if (p && uobj == NULL)
+		p->p_vmspace->vm_dsize += size;
+
 
 	/*
 	 *      Update the free space hint
@@ -1363,10 +1367,11 @@
  */
 
 void
-uvm_unmap_remove(map, start, end, entry_list)
+uvm_unmap_remove(map, start, end, entry_list, p)
 	vm_map_t map;
 	vaddr_t start,end;
 	vm_map_entry_t *entry_list;	/* OUT */
+	struct proc *p;
 {
 	vm_map_entry_t entry, first_entry, next;
 	vaddr_t len;
@@ -1439,6 +1444,9 @@
 		if (VM_MAPENT_ISWIRED(entry))
 			uvm_map_entry_unwire(map, entry);
 
+		if (p && entry->object.uvm_obj == NULL)
+			p->p_vmspace->vm_dsize -= len;
+
 		/*
 		 * special case: handle mappings to anonymous kernel objects.
 		 * we want to free these pages right away...
@@ -3333,7 +3341,7 @@
 		if (vm->vm_map.nentries) {
 			uvm_unmap_remove(&vm->vm_map,
 			    vm->vm_map.min_offset, vm->vm_map.max_offset,
-			    &dead_entries);
+			    &dead_entries, 0);
 			if (dead_entries != NULL)
 				uvm_unmap_detach(dead_entries, 0);
 		}
Index: uvm/uvm_map.h
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_map.h,v
retrieving revision 1.31
diff -u -r1.31 uvm_map.h
--- uvm/uvm_map.h	1 Mar 2005 01:28:39 -0000	1.31
+++ uvm/uvm_map.h	22 May 2005 08:20:00 -0000
@@ -354,11 +354,12 @@
 			vaddr_t *);
 void		uvm_map_setup(vm_map_t, vaddr_t, vaddr_t, int);
 int		uvm_map_submap(vm_map_t, vaddr_t, vaddr_t, vm_map_t);
+#define		uvm_unmap(_m, _s, _e) uvm_unmap_p(_m, _s, _e, 0)
 MAP_INLINE
-void		uvm_unmap(vm_map_t, vaddr_t, vaddr_t);
+void		uvm_unmap_p(vm_map_t, vaddr_t, vaddr_t, struct proc *);
 void		uvm_unmap_detach(vm_map_entry_t,int);
 void		uvm_unmap_remove(vm_map_t, vaddr_t, vaddr_t,
-				      vm_map_entry_t *);
+				      vm_map_entry_t *, struct proc *);
 
 #endif /* _KERNEL */
 
Index: uvm/uvm_map_i.h
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_map_i.h,v
retrieving revision 1.16
diff -u -r1.16 uvm_map_i.h
--- uvm/uvm_map_i.h	29 Oct 2002 18:30:21 -0000	1.16
+++ uvm/uvm_map_i.h	22 May 2005 08:20:00 -0000
@@ -161,9 +161,10 @@
  */
 
 MAP_INLINE void
-uvm_unmap(map, start, end)
+uvm_unmap_p(map, start, end, p)
 	vm_map_t map;
 	vaddr_t start,end;
+	struct proc *p;
 {
 	vm_map_entry_t dead_entries;
 	UVMHIST_FUNC("uvm_unmap"); UVMHIST_CALLED(maphist);
@@ -175,7 +176,7 @@
 	 * detach from the dead entries...
 	 */
 	vm_map_lock(map);
-	uvm_unmap_remove(map, start, end, &dead_entries);
+	uvm_unmap_remove(map, start, end, &dead_entries, p);
 	vm_map_unlock(map);
 
 	if (dead_entries != NULL)
Index: uvm/uvm_mmap.c
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_mmap.c,v
retrieving revision 1.55
diff -u -r1.55 uvm_mmap.c
--- uvm/uvm_mmap.c	15 Jan 2005 06:54:51 -0000	1.55
+++ uvm/uvm_mmap.c	22 May 2005 08:20:01 -0000
@@ -605,7 +605,7 @@
 	 */
 
 	error = uvm_mmap(&p->p_vmspace->vm_map, &addr, size, prot, maxprot,
-	    flags, handle, pos, p->p_rlimit[RLIMIT_MEMLOCK].rlim_cur);
+	    flags, handle, pos, p->p_rlimit[RLIMIT_MEMLOCK].rlim_cur, p);
 
 	if (error == 0)
 		/* remember to add offset */
@@ -787,7 +787,7 @@
 	/*
 	 * doit!
 	 */
-	uvm_unmap_remove(map, addr, addr + size, &dead_entries);
+	uvm_unmap_remove(map, addr, addr + size, &dead_entries, p);
 
 	vm_map_unlock(map);	/* and unlock */
 
@@ -1164,7 +1164,7 @@
  */
 
 int
-uvm_mmap(map, addr, size, prot, maxprot, flags, handle, foff, locklimit)
+uvm_mmap(map, addr, size, prot, maxprot, flags, handle, foff, locklimit, p)
 	vm_map_t map;
 	vaddr_t *addr;
 	vsize_t size;
@@ -1173,6 +1173,7 @@
 	caddr_t handle;		/* XXX: VNODE? */
 	voff_t foff;
 	vsize_t locklimit;
+	struct proc *p;
 {
 	struct uvm_object *uobj;
 	struct vnode *vp;
@@ -1301,7 +1302,7 @@
 	 * do it!
 	 */
 
-	retval = uvm_map(map, addr, size, uobj, foff, align, uvmflag);
+	retval = uvm_map_p(map, addr, size, uobj, foff, align, uvmflag, p);
 
 	if (retval == KERN_SUCCESS) {
 		/*
Index: uvm/uvm_pager.c
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_pager.c,v
retrieving revision 1.35
diff -u -r1.35 uvm_pager.c
--- uvm/uvm_pager.c	23 Feb 2004 06:19:32 -0000	1.35
+++ uvm/uvm_pager.c	22 May 2005 08:20:01 -0000
@@ -227,7 +227,7 @@
 	}
 
 	vm_map_lock(pager_map);
-	uvm_unmap_remove(pager_map, kva, kva + size, &entries);
+	uvm_unmap_remove(pager_map, kva, kva + size, &entries, NULL);
 	simple_lock(&pager_map_wanted_lock);
 	if (pager_map_wanted) {
 		pager_map_wanted = FALSE;
Index: arch/i386/i386/pmap.c
===================================================================
RCS file: /cvs/src/sys/arch/i386/i386/pmap.c,v
retrieving revision 1.80
diff -u -r1.80 pmap.c
--- arch/i386/i386/pmap.c	25 Dec 2004 23:02:24 -0000	1.80
+++ arch/i386/i386/pmap.c	22 May 2005 08:22:10 -0000
@@ -1630,7 +1630,7 @@
 		/* unmap the page */
 		dead_entries = NULL;
 		uvm_unmap_remove(map, (vaddr_t)pvp, ((vaddr_t)pvp) + PAGE_SIZE,
-		    &dead_entries);
+		    &dead_entries, NULL);
 		vm_map_unlock(map);
 
 		if (dead_entries != NULL)
Index: arch/amd64/amd64/pmap.c
===================================================================
RCS file: /cvs/src/sys/arch/amd64/amd64/pmap.c,v
retrieving revision 1.7
diff -u -r1.7 pmap.c
--- arch/amd64/amd64/pmap.c	22 Jul 2004 15:50:18 -0000	1.7
+++ arch/amd64/amd64/pmap.c	22 May 2005 08:22:10 -0000
@@ -1586,7 +1586,7 @@
 		/* unmap the page */
 		dead_entries = NULL;
 		uvm_unmap_remove(map, (vaddr_t)pvp, ((vaddr_t)pvp) + PAGE_SIZE,
-		    &dead_entries);
+		    &dead_entries, NULL);
 		vm_map_unlock(map);
 
 		if (dead_entries != NULL)

-- 
so what do you want
you want to be famous and rich and happy
but you're terrified you have nothing to offer this world