Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 Oct 2011 17:37:00 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 200834 for review
Message-ID:  <201110271737.p9RHb0IG054758@skunkworks.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@200834?ac=10

Change 200834 by jhb@jhb_jhbbsd on 2011/10/27 17:36:23

	Optimize vm page locking ala vm_unhold_pages().
	
	Requested by:	kib

Affected files ...

.. //depot/projects/fadvise/sys/vm/vm_object.c#4 edit

Differences ...

==== //depot/projects/fadvise/sys/vm/vm_object.c#4 (text+ko) ====

@@ -1881,6 +1881,7 @@
 void
 vm_object_page_cache(vm_object_t object, vm_pindex_t start, vm_pindex_t end)
 {
+	struct mtx *mtx, *new_mtx;
 	vm_page_t p, next;
 
 	VM_OBJECT_LOCK_ASSERT(object, MA_OWNED);
@@ -1895,13 +1896,24 @@
 	 * Here, the variable "p" is either (1) the page with the least pindex
 	 * greater than or equal to the parameter "start" or (2) NULL. 
 	 */
+	mtx = NULL;
 	for (; p != NULL && (p->pindex < end || end == 0); p = next) {
 		next = TAILQ_NEXT(p, listq);
 
-		vm_page_lock(p);
+		/*
+		 * Avoid releasing and reacquiring the same page lock.
+		 */
+		new_mtx = vm_page_lockptr(p);
+		if (mtx != new_mtx) {
+			if (mtx != NULL)
+				mtx_unlock(mtx);
+			mtx = new_mtx;
+			mtx_lock(mtx);
+		}
 		vm_page_try_to_cache(p);
-		vm_page_unlock(p);
 	}
+	if (mtx != NULL)
+		mtx_unlock(mtx);
 }
 
 /*



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