svn commit: r245787 - stable/9/sys/vm

Andrey Zonov zont at FreeBSD.org
Tue Jan 22 12:05:55 UTC 2013


Author: zont
Date: Tue Jan 22 12:05:53 2013
New Revision: 245787
URL: http://svnweb.freebsd.org/changeset/base/245787

Log:
  MFC r240145:
  - Simplify VM code by using vmspace_wired_count() for counting wired
  memory of a process.
  
  MFC r245255:
  - Reduce kernel size by removing unnecessary pointer indirections.
  
  GENERIC kernel size reduced in 16 bytes and RACCT kernel in 336 bytes.
  
  MFC r245296:
  - Improve readability of sys_obreak().
  
  MFC r245421:
  - Get rid of unused function vmspace_wired_count().

Modified:
  stable/9/sys/vm/vm_map.c
  stable/9/sys/vm/vm_map.h
  stable/9/sys/vm/vm_mmap.c
  stable/9/sys/vm/vm_unix.c
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/vm/vm_map.c
==============================================================================
--- stable/9/sys/vm/vm_map.c	Tue Jan 22 11:43:00 2013	(r245786)
+++ stable/9/sys/vm/vm_map.c	Tue Jan 22 12:05:53 2013	(r245787)
@@ -726,12 +726,6 @@ vmspace_resident_count(struct vmspace *v
 	return pmap_resident_count(vmspace_pmap(vmspace));
 }
 
-long
-vmspace_wired_count(struct vmspace *vmspace)
-{
-	return pmap_wired_count(vmspace_pmap(vmspace));
-}
-
 /*
  *	vm_map_create:
  *
@@ -3281,8 +3275,7 @@ vm_map_stack(vm_map_t map, vm_offset_t a
 	}
 
 	if (!old_mlock && map->flags & MAP_WIREFUTURE) {
-		if (ptoa(vmspace_wired_count(curproc->p_vmspace)) +
-		    init_ssize > lmemlim) {
+		if (ptoa(pmap_wired_count(map->pmap)) + init_ssize > lmemlim) {
 			vm_map_unlock(map);
 			return (KERN_NO_SPACE);
 		}
@@ -3505,8 +3498,7 @@ Retry:
 		grow_amount = limit - ctob(vm->vm_ssize);
 #endif
 	if (!old_mlock && map->flags & MAP_WIREFUTURE) {
-		if (ptoa(vmspace_wired_count(p->p_vmspace)) + grow_amount >
-		    lmemlim) {
+		if (ptoa(pmap_wired_count(map->pmap)) + grow_amount > lmemlim) {
 			vm_map_unlock_read(map);
 			rv = KERN_NO_SPACE;
 			goto out;
@@ -3514,7 +3506,7 @@ Retry:
 #ifdef RACCT
 		PROC_LOCK(p);
 		if (racct_set(p, RACCT_MEMLOCK,
-		    ptoa(vmspace_wired_count(p->p_vmspace)) + grow_amount)) {
+		    ptoa(pmap_wired_count(map->pmap)) + grow_amount)) {
 			PROC_UNLOCK(p);
 			vm_map_unlock_read(map);
 			rv = KERN_NO_SPACE;
@@ -3645,7 +3637,7 @@ out:
 		KASSERT(error == 0, ("decreasing RACCT_VMEM failed"));
 		if (!old_mlock) {
 			error = racct_set(p, RACCT_MEMLOCK,
-			    ptoa(vmspace_wired_count(p->p_vmspace)));
+			    ptoa(pmap_wired_count(map->pmap)));
 			KASSERT(error == 0, ("decreasing RACCT_MEMLOCK failed"));
 		}
 	    	error = racct_set(p, RACCT_STACK, ctob(vm->vm_ssize));

Modified: stable/9/sys/vm/vm_map.h
==============================================================================
--- stable/9/sys/vm/vm_map.h	Tue Jan 22 11:43:00 2013	(r245786)
+++ stable/9/sys/vm/vm_map.h	Tue Jan 22 12:05:53 2013	(r245787)
@@ -298,7 +298,6 @@ void vm_map_wait_busy(vm_map_t map);
 			_vm_map_lock_downgrade(map, LOCK_FILE, LOCK_LINE)
 
 long vmspace_resident_count(struct vmspace *vmspace);
-long vmspace_wired_count(struct vmspace *vmspace);
 #endif	/* _KERNEL */
 
 

Modified: stable/9/sys/vm/vm_mmap.c
==============================================================================
--- stable/9/sys/vm/vm_mmap.c	Tue Jan 22 11:43:00 2013	(r245786)
+++ stable/9/sys/vm/vm_mmap.c	Tue Jan 22 12:05:53 2013	(r245787)
@@ -1041,6 +1041,7 @@ sys_mlock(td, uap)
 	struct proc *proc;
 	vm_offset_t addr, end, last, start;
 	vm_size_t npages, size;
+	vm_map_t map;
 	unsigned long nsize;
 	int error;
 
@@ -1058,9 +1059,9 @@ sys_mlock(td, uap)
 	if (npages > vm_page_max_wired)
 		return (ENOMEM);
 	proc = td->td_proc;
+	map = &proc->p_vmspace->vm_map;
 	PROC_LOCK(proc);
-	nsize = ptoa(npages +
-	    pmap_wired_count(vm_map_pmap(&proc->p_vmspace->vm_map)));
+	nsize = ptoa(npages + pmap_wired_count(map->pmap));
 	if (nsize > lim_cur(proc, RLIMIT_MEMLOCK)) {
 		PROC_UNLOCK(proc);
 		return (ENOMEM);
@@ -1075,13 +1076,13 @@ sys_mlock(td, uap)
 	if (error != 0)
 		return (ENOMEM);
 #endif
-	error = vm_map_wire(&proc->p_vmspace->vm_map, start, end,
+	error = vm_map_wire(map, start, end,
 	    VM_MAP_WIRE_USER | VM_MAP_WIRE_NOHOLES);
 #ifdef RACCT
 	if (error != KERN_SUCCESS) {
 		PROC_LOCK(proc);
 		racct_set(proc, RACCT_MEMLOCK,
-		    ptoa(pmap_wired_count(vm_map_pmap(&proc->p_vmspace->vm_map))));
+		    ptoa(pmap_wired_count(map->pmap)));
 		PROC_UNLOCK(proc);
 	}
 #endif
@@ -1155,7 +1156,7 @@ sys_mlockall(td, uap)
 	if (error != KERN_SUCCESS) {
 		PROC_LOCK(td->td_proc);
 		racct_set(td->td_proc, RACCT_MEMLOCK,
-		    ptoa(pmap_wired_count(vm_map_pmap(&td->td_proc->p_vmspace->vm_map))));
+		    ptoa(pmap_wired_count(map->pmap)));
 		PROC_UNLOCK(td->td_proc);
 	}
 #endif
@@ -1488,16 +1489,15 @@ vm_mmap(vm_map_t map, vm_offset_t *addr,
 	if (td->td_proc->p_vmspace->vm_map.size + size >
 	    lim_cur(td->td_proc, RLIMIT_VMEM)) {
 		if (!old_mlock && map->flags & MAP_WIREFUTURE) {
-			if (ptoa(vmspace_wired_count(td->td_proc->p_vmspace)) +
-			    size > lim_cur(td->td_proc, RLIMIT_MEMLOCK)) {
+			if (ptoa(pmap_wired_count(map->pmap)) + size >
+			    lim_cur(td->td_proc, RLIMIT_MEMLOCK)) {
 				racct_set_force(td->td_proc, RACCT_VMEM,
 				    map->size);
 				PROC_UNLOCK(td->td_proc);
 				return (ENOMEM);
 			}
 			error = racct_set(td->td_proc, RACCT_MEMLOCK,
-			    ptoa(vmspace_wired_count(td->td_proc->p_vmspace)) +
-			    size);
+			    ptoa(pmap_wired_count(map->pmap)) + size);
 			if (error != 0) {
 				racct_set_force(td->td_proc, RACCT_VMEM,
 				    map->size);

Modified: stable/9/sys/vm/vm_unix.c
==============================================================================
--- stable/9/sys/vm/vm_unix.c	Tue Jan 22 11:43:00 2013	(r245786)
+++ stable/9/sys/vm/vm_unix.c	Tue Jan 22 12:05:53 2013	(r245787)
@@ -76,6 +76,7 @@ sys_obreak(td, uap)
 	struct obreak_args *uap;
 {
 	struct vmspace *vm = td->td_proc->p_vmspace;
+	vm_map_t map = &vm->vm_map;
 	vm_offset_t new, old, base;
 	rlim_t datalim, lmemlim, vmemlim;
 	int prot, rv;
@@ -90,7 +91,7 @@ sys_obreak(td, uap)
 
 	do_map_wirefuture = FALSE;
 	new = round_page((vm_offset_t)uap->nsize);
-	vm_map_lock(&vm->vm_map);
+	vm_map_lock(map);
 
 	base = round_page((vm_offset_t) vm->vm_daddr);
 	old = base + ctob(vm->vm_dsize);
@@ -103,7 +104,7 @@ sys_obreak(td, uap)
 			error = ENOMEM;
 			goto done;
 		}
-		if (new > vm_map_max(&vm->vm_map)) {
+		if (new > vm_map_max(map)) {
 			error = ENOMEM;
 			goto done;
 		}
@@ -117,14 +118,14 @@ sys_obreak(td, uap)
 		goto done;
 	}
 	if (new > old) {
-		if (!old_mlock && vm->vm_map.flags & MAP_WIREFUTURE) {
-			if (ptoa(vmspace_wired_count(td->td_proc->p_vmspace)) +
+		if (!old_mlock && map->flags & MAP_WIREFUTURE) {
+			if (ptoa(pmap_wired_count(map->pmap)) +
 			    (new - old) > lmemlim) {
 				error = ENOMEM;
 				goto done;
 			}
 		}
-		if (vm->vm_map.size + (new - old) > vmemlim) {
+		if (map->size + (new - old) > vmemlim) {
 			error = ENOMEM;
 			goto done;
 		}
@@ -137,22 +138,21 @@ sys_obreak(td, uap)
 			goto done;
 		}
 		error = racct_set(td->td_proc, RACCT_VMEM,
-		    vm->vm_map.size + (new - old));
+		    map->size + (new - old));
 		if (error != 0) {
 			racct_set_force(td->td_proc, RACCT_DATA, old - base);
 			PROC_UNLOCK(td->td_proc);
 			error = ENOMEM;
 			goto done;
 		}
-		if (!old_mlock && vm->vm_map.flags & MAP_WIREFUTURE) {
+		if (!old_mlock && map->flags & MAP_WIREFUTURE) {
 			error = racct_set(td->td_proc, RACCT_MEMLOCK,
-			    ptoa(vmspace_wired_count(td->td_proc->p_vmspace)) +
-			    (new - old));
+			    ptoa(pmap_wired_count(map->pmap)) + (new - old));
 			if (error != 0) {
 				racct_set_force(td->td_proc, RACCT_DATA,
 				    old - base);
 				racct_set_force(td->td_proc, RACCT_VMEM,
-				    vm->vm_map.size);
+				    map->size);
 				PROC_UNLOCK(td->td_proc);
 				error = ENOMEM;
 				goto done;
@@ -167,17 +167,15 @@ sys_obreak(td, uap)
 			prot |= VM_PROT_EXECUTE;
 #endif
 #endif
-		rv = vm_map_insert(&vm->vm_map, NULL, 0, old, new,
-		    prot, VM_PROT_ALL, 0);
+		rv = vm_map_insert(map, NULL, 0, old, new, prot, VM_PROT_ALL, 0);
 		if (rv != KERN_SUCCESS) {
 #ifdef RACCT
 			PROC_LOCK(td->td_proc);
 			racct_set_force(td->td_proc, RACCT_DATA, old - base);
-			racct_set_force(td->td_proc, RACCT_VMEM, vm->vm_map.size);
-			if (!old_mlock && vm->vm_map.flags & MAP_WIREFUTURE) {
+			racct_set_force(td->td_proc, RACCT_VMEM, map->size);
+			if (!old_mlock && map->flags & MAP_WIREFUTURE) {
 				racct_set_force(td->td_proc, RACCT_MEMLOCK,
-				    ptoa(vmspace_wired_count(
-				    td->td_proc->p_vmspace)));
+				    ptoa(pmap_wired_count(map->pmap)));
 			}
 			PROC_UNLOCK(td->td_proc);
 #endif
@@ -194,13 +192,13 @@ sys_obreak(td, uap)
 		 *
 		 * XXX If the pages cannot be wired, no error is returned.
 		 */
-		if ((vm->vm_map.flags & MAP_WIREFUTURE) == MAP_WIREFUTURE) {
+		if ((map->flags & MAP_WIREFUTURE) == MAP_WIREFUTURE) {
 			if (bootverbose)
 				printf("obreak: MAP_WIREFUTURE set\n");
 			do_map_wirefuture = TRUE;
 		}
 	} else if (new < old) {
-		rv = vm_map_delete(&vm->vm_map, new, old);
+		rv = vm_map_delete(map, new, old);
 		if (rv != KERN_SUCCESS) {
 			error = ENOMEM;
 			goto done;
@@ -209,19 +207,19 @@ sys_obreak(td, uap)
 #ifdef RACCT
 		PROC_LOCK(td->td_proc);
 		racct_set_force(td->td_proc, RACCT_DATA, new - base);
-		racct_set_force(td->td_proc, RACCT_VMEM, vm->vm_map.size);
-		if (!old_mlock && vm->vm_map.flags & MAP_WIREFUTURE) {
+		racct_set_force(td->td_proc, RACCT_VMEM, map->size);
+		if (!old_mlock && map->flags & MAP_WIREFUTURE) {
 			racct_set_force(td->td_proc, RACCT_MEMLOCK,
-			    ptoa(vmspace_wired_count(td->td_proc->p_vmspace)));
+			    ptoa(pmap_wired_count(map->pmap)));
 		}
 		PROC_UNLOCK(td->td_proc);
 #endif
 	}
 done:
-	vm_map_unlock(&vm->vm_map);
+	vm_map_unlock(map);
 
 	if (do_map_wirefuture)
-		(void) vm_map_wire(&vm->vm_map, old, new,
+		(void) vm_map_wire(map, old, new,
 		    VM_MAP_WIRE_USER|VM_MAP_WIRE_NOHOLES);
 
 	return (error);


More information about the svn-src-stable-9 mailing list