svn commit: r218966 - head/sys/vm

Bruce Cran brucec at FreeBSD.org
Wed Feb 23 10:28:37 UTC 2011


Author: brucec
Date: Wed Feb 23 10:28:37 2011
New Revision: 218966
URL: http://svn.freebsd.org/changeset/base/218966

Log:
  Calculate and return the count in vmspace_swap_count as a vm_offset_t
  instead of an int to avoid overflow.
  
  While here, clean up some style(9) issues.
  
  PR:		kern/152200
  Reviewed by:	kib
  MFC after:	2 weeks

Modified:
  head/sys/vm/swap_pager.c
  head/sys/vm/vm_map.h

Modified: head/sys/vm/swap_pager.c
==============================================================================
--- head/sys/vm/swap_pager.c	Wed Feb 23 09:22:33 2011	(r218965)
+++ head/sys/vm/swap_pager.c	Wed Feb 23 10:28:37 2011	(r218966)
@@ -2420,23 +2420,24 @@ SYSCTL_NODE(_vm, OID_AUTO, swap_info, CT
  *	if the VM object has any swap use at all the associated map entries
  *	count for at least 1 swap page.
  */
-int
+vm_offset_t
 vmspace_swap_count(struct vmspace *vmspace)
 {
-	vm_map_t map = &vmspace->vm_map;
+	vm_map_t map;
 	vm_map_entry_t cur;
-	int count = 0;
+	vm_object_t object;
+	vm_offset_t count, n;
 
-	for (cur = map->header.next; cur != &map->header; cur = cur->next) {
-		vm_object_t object;
+	map = &vmspace->vm_map;
+	count = 0;
 
+	for (cur = map->header.next; cur != &map->header; cur = cur->next) {
 		if ((cur->eflags & MAP_ENTRY_IS_SUB_MAP) == 0 &&
 		    (object = cur->object.vm_object) != NULL) {
 			VM_OBJECT_LOCK(object);
 			if (object->type == OBJT_SWAP &&
 			    object->un_pager.swp.swp_bcount != 0) {
-				int n = (cur->end - cur->start) / PAGE_SIZE;
-
+				n = (cur->end - cur->start) / PAGE_SIZE;
 				count += object->un_pager.swp.swp_bcount *
 				    SWAP_META_PAGES * n / object->size + 1;
 			}

Modified: head/sys/vm/vm_map.h
==============================================================================
--- head/sys/vm/vm_map.h	Wed Feb 23 09:22:33 2011	(r218965)
+++ head/sys/vm/vm_map.h	Wed Feb 23 10:28:37 2011	(r218966)
@@ -380,6 +380,6 @@ int vm_map_unwire(vm_map_t map, vm_offse
     int flags);
 int vm_map_wire(vm_map_t map, vm_offset_t start, vm_offset_t end,
     int flags);
-int vmspace_swap_count (struct vmspace *vmspace);
+vm_offset_t vmspace_swap_count(struct vmspace *vmspace);
 #endif				/* _KERNEL */
 #endif				/* _VM_MAP_ */


More information about the svn-src-head mailing list