Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 2 Jun 2013 16:18:03 +0000 (UTC)
From:      Alan Cox <alc@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r251257 - head/sys/kern
Message-ID:  <201306021618.r52GI33I042677@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201306021618.r52GI33I042677>