svn commit: r248709 - user/attilio/vmobj-readlock/sys/vm

Attilio Rao attilio at FreeBSD.org
Mon Mar 25 22:40:39 UTC 2013


Author: attilio
Date: Mon Mar 25 22:40:38 2013
New Revision: 248709
URL: http://svnweb.freebsd.org/changeset/base/248709

Log:
  Make the obj->bcount protected by the swhash_mtx mutex.
  This way few swapper specific functions can now get object lock in
  read mode.
  Where the most notable case is swap_pager_freespace().
  
  Sponsored by:	EMC / Isilon storage division

Modified:
  user/attilio/vmobj-readlock/sys/vm/swap_pager.c

Modified: user/attilio/vmobj-readlock/sys/vm/swap_pager.c
==============================================================================
--- user/attilio/vmobj-readlock/sys/vm/swap_pager.c	Mon Mar 25 20:38:09 2013	(r248708)
+++ user/attilio/vmobj-readlock/sys/vm/swap_pager.c	Mon Mar 25 22:40:38 2013	(r248709)
@@ -827,7 +827,7 @@ void
 swap_pager_freespace(vm_object_t object, vm_pindex_t start, vm_size_t size)
 {
 
-	VM_OBJECT_ASSERT_WLOCKED(object);
+	VM_OBJECT_ASSERT_LOCKED(object);
 	swp_pager_meta_free(object, start, size);
 }
 
@@ -999,7 +999,7 @@ swap_pager_haspage(vm_object_t object, v
 {
 	daddr_t blk0;
 
-	VM_OBJECT_ASSERT_WLOCKED(object);
+	VM_OBJECT_ASSERT_LOCKED(object);
 	/*
 	 * do we have good backing store at the requested index ?
 	 */
@@ -1070,7 +1070,7 @@ static void
 swap_pager_unswapped(vm_page_t m)
 {
 
-	VM_OBJECT_ASSERT_WLOCKED(m->object);
+	VM_OBJECT_ASSERT_LOCKED(m->object);
 	swp_pager_meta_ctl(m->object, m->pindex, SWM_FREE);
 }
 
@@ -1924,7 +1924,7 @@ static void
 swp_pager_meta_free(vm_object_t object, vm_pindex_t index, daddr_t count)
 {
 
-	VM_OBJECT_ASSERT_WLOCKED(object);
+	VM_OBJECT_ASSERT_LOCKED(object);
 	if (object->type != OBJT_SWAP)
 		return;
 
@@ -1970,15 +1970,15 @@ swp_pager_meta_free_all(vm_object_t obje
 {
 	daddr_t index = 0;
 
-	VM_OBJECT_ASSERT_WLOCKED(object);
+	VM_OBJECT_ASSERT_LOCKED(object);
 	if (object->type != OBJT_SWAP)
 		return;
 
+	mtx_lock(&swhash_mtx);
 	while (object->un_pager.swp.swp_bcount) {
 		struct swblock **pswap;
 		struct swblock *swap;
 
-		mtx_lock(&swhash_mtx);
 		pswap = swp_pager_hash(object, index);
 		if ((swap = *pswap) != NULL) {
 			int i;
@@ -1996,9 +1996,9 @@ swp_pager_meta_free_all(vm_object_t obje
 			uma_zfree(swap_zone, swap);
 			--object->un_pager.swp.swp_bcount;
 		}
-		mtx_unlock(&swhash_mtx);
 		index += SWAP_META_PAGES;
 	}
+	mtx_unlock(&swhash_mtx);
 }
 
 /*
@@ -2029,7 +2029,7 @@ swp_pager_meta_ctl(vm_object_t object, v
 	daddr_t r1;
 	int idx;
 
-	VM_OBJECT_ASSERT_WLOCKED(object);
+	VM_OBJECT_ASSERT_LOCKED(object);
 	/*
 	 * The meta data only exists of the object is OBJT_SWAP
 	 * and even then might not be allocated yet.
@@ -2484,14 +2484,16 @@ vmspace_swap_count(struct vmspace *vmspa
 	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_WLOCK(object);
+			VM_OBJECT_RLOCK(object);
+			mtx_lock(&swhash_mtx);
 			if (object->type == OBJT_SWAP &&
 			    object->un_pager.swp.swp_bcount != 0) {
 				n = (cur->end - cur->start) / PAGE_SIZE;
 				count += object->un_pager.swp.swp_bcount *
 				    SWAP_META_PAGES * n / object->size + 1;
 			}
-			VM_OBJECT_WUNLOCK(object);
+			mtx_unlock(&swhash_mtx);
+			VM_OBJECT_RUNLOCK(object);
 		}
 	}
 	return (count);


More information about the svn-src-user mailing list