svn commit: r251257 - head/sys/kern

Alan Cox alc at FreeBSD.org
Sun Jun 2 16:18:04 UTC 2013


Author: alc
Date: Sun Jun  2 16:18:03 2013
New Revision: 251257
URL: http://svnweb.freebsd.org/changeset/base/251257

Log:
  Reduce the scope of the VM object locking in brelse().  In my tests, this
  change reduced the total number of VM object lock acquisitions by brelse()
  by 74%.
  
  Sponsored by:	EMC / Isilon Storage Division

Modified:
  head/sys/kern/vfs_bio.c

Modified: head/sys/kern/vfs_bio.c
==============================================================================
--- head/sys/kern/vfs_bio.c	Sun Jun  2 15:47:22 2013	(r251256)
+++ head/sys/kern/vfs_bio.c	Sun Jun  2 16:18:03 2013	(r251257)
@@ -1522,7 +1522,6 @@ brelse(struct buf *bp)
 		 */
 		resid = bp->b_bufsize;
 		foff = bp->b_offset;
-		VM_OBJECT_WLOCK(obj);
 		for (i = 0; i < bp->b_npages; i++) {
 			int had_bogus = 0;
 
@@ -1536,6 +1535,7 @@ brelse(struct buf *bp)
 				poff = OFF_TO_IDX(bp->b_offset);
 				had_bogus = 1;
 
+				VM_OBJECT_RLOCK(obj);
 				for (j = i; j < bp->b_npages; j++) {
 					vm_page_t mtmp;
 					mtmp = bp->b_pages[j];
@@ -1547,6 +1547,7 @@ brelse(struct buf *bp)
 						bp->b_pages[j] = mtmp;
 					}
 				}
+				VM_OBJECT_RUNLOCK(obj);
 
 				if ((bp->b_flags & (B_INVAL | B_UNMAPPED)) == 0) {
 					BUF_CHECK_MAPPED(bp);
@@ -1564,14 +1565,15 @@ brelse(struct buf *bp)
 					(PAGE_SIZE - poffset) : resid;
 
 				KASSERT(presid >= 0, ("brelse: extra page"));
+				VM_OBJECT_WLOCK(obj);
 				vm_page_set_invalid(m, poffset, presid);
+				VM_OBJECT_WUNLOCK(obj);
 				if (had_bogus)
 					printf("avoided corruption bug in bogus_page/brelse code\n");
 			}
 			resid -= PAGE_SIZE - (foff & PAGE_MASK);
 			foff = (foff + PAGE_SIZE) & ~(off_t)PAGE_MASK;
 		}
-		VM_OBJECT_WUNLOCK(obj);
 		if (bp->b_flags & (B_INVAL | B_RELBUF))
 			vfs_vmio_release(bp);
 


More information about the svn-src-all mailing list