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

Re: anon map and datasize



third time's a charm.  there was an accounting mismatch in previous diff, 
where sometimes an mmap wouldn't be counted if the map entry could be 
merged.  this produced funny results for Xorg, or any program which made 
enough mmap/munmap calls over a long time.  thanks testers.

if you are already running the previous diff, the only portion you need to 
merge in is uvm_map.c:
@@ -849,6 +850,8 @@
                prev_entry->end += size;
                uvm_rb_fixup(map, prev_entry);
                map->size += size;
+               if (p && uobj == NULL)
+                       p->p_vmspace->vm_dused += btoc(size);

                uvm_tree_sanity(map, "map leave 2");



Index: arch/i386/i386/locore.s
===================================================================
RCS file: /cvs/src/sys/arch/i386/i386/locore.s,v
retrieving revision 1.83
diff -u -r1.83 locore.s
--- arch/i386/i386/locore.s	17 Apr 2005 07:33:13 -0000	1.83
+++ arch/i386/i386/locore.s	22 May 2005 21:34:13 -0000
@@ -1613,6 +1613,8 @@
 	addl	$1,_C_LABEL(pctr_idlcnt)
 	adcl	$0,_C_LABEL(pctr_idlcnt)+4
 #else
+	cmpl	$0,_C_LABEL(whichqs)
+	jnz	_C_LABEL(idle_exit)
 	hlt
 #endif
 	jmp	_C_LABEL(idle_loop)
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 21:34:14 -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 21:34:14 -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)
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 21:34:15 -0000
@@ -395,6 +395,7 @@
 	segsz_t vm_swrss;	/* resident set size before last swap */
 	segsz_t vm_tsize;	/* text size (pages) XXX */
 	segsz_t vm_dsize;	/* data size (pages) XXX */
+	segsz_t vm_dused;	/* data segment length (pages) XXX */
 	segsz_t vm_ssize;	/* stack size (pages) */
 	caddr_t	vm_taddr;	/* user virtual address of text XXX */
 	caddr_t	vm_daddr;	/* user virtual address of data XXX */
@@ -517,9 +518,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 +549,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 21:34:15 -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 21:34:15 -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_map.c
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_map.c,v
retrieving revision 1.70
diff -u -r1.70 uvm_map.c
--- uvm_map.c	30 Dec 2004 08:28:39 -0000	1.70
+++ uvm_map.c	23 May 2005 19:58:52 -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 =
@@ -849,6 +850,8 @@
 		prev_entry->end += size;
 		uvm_rb_fixup(map, prev_entry);
 		map->size += size;
+		if (p && uobj == NULL)
+			p->p_vmspace->vm_dused += btoc(size);
 
 		uvm_tree_sanity(map, "map leave 2");
 
@@ -914,6 +917,9 @@
 	uvm_map_entry_link(map, prev_entry, new_entry);
 
 	map->size += size;
+	if (p && uobj == NULL)
+		p->p_vmspace->vm_dused += btoc(size);
+
 
 	/*
 	 *      Update the free space hint
@@ -1363,10 +1369,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;
@@ -1430,6 +1437,8 @@
 		UVM_MAP_CLIP_END(map, entry, end); 
 		next = entry->next;
 		len = entry->end - entry->start;
+		if (p && entry->object.uvm_obj == NULL)
+			p->p_vmspace->vm_dused -= btoc(len);
 
 		/*
 		 * unwire before removing addresses from the pmap; otherwise
@@ -3333,7 +3342,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, NULL);
 			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 21:34:15 -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 21:34:15 -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 21:34:15 -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 21:34:15 -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: kern/kern_sysctl.c
===================================================================
RCS file: /cvs/src/sys/kern/kern_sysctl.c,v
retrieving revision 1.124
diff -u -r1.124 kern_sysctl.c
--- kern/kern_sysctl.c	10 Mar 2005 17:26:10 -0000	1.124
+++ kern/kern_sysctl.c	22 May 2005 21:36:49 -0000
@@ -1165,7 +1165,7 @@
 		PHOLD(p);	/* need for pstats */
 		ep->e_vm.vm_rssize = vm_resident_count(vm);
 		ep->e_vm.vm_tsize = vm->vm_tsize;
-		ep->e_vm.vm_dsize = vm->vm_dsize;
+		ep->e_vm.vm_dsize = vm->vm_dused;
 		ep->e_vm.vm_ssize = vm->vm_ssize;
 		ep->e_pstats = *p->p_stats;
 		ep->e_pstats_valid = 1;
@@ -1297,7 +1297,7 @@
 
 		ki->p_vm_rssize = vm_resident_count(vm);
 		ki->p_vm_tsize = vm->vm_tsize;
-		ki->p_vm_dsize = vm->vm_dsize;
+		ki->p_vm_dsize = vm->vm_dused;
 		ki->p_vm_ssize = vm->vm_ssize;
 
 		ki->p_forw = PTRTOINT64(p->p_forw);

-- 
quit whining you haven't done anything wrong
because frankly you haven't done much of anything