Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 Sep 2020 19:59:25 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r365275 - head/sys/vm
Message-ID:  <202009021959.082JxP5X068124@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Wed Sep  2 19:59:25 2020
New Revision: 365275
URL: https://svnweb.freebsd.org/changeset/base/365275

Log:
  Avoid unnecessary object locking in vm_page_grab_pages_unlocked().
  
  We were needlessly acquiring the object lock to call
  vm_page_grab_pages() even when all of the requested pages were looked up
  locklessly.  Fix that, stop testing for count == 0 in
  vm_page_grab_pages(), and add assertions to help catch this kind of
  mistake.
  
  Reported by:	cem
  Reviewed by:	alc, cem, dougm, jeff
  Differential Revision:	https://reviews.freebsd.org/D26304

Modified:
  head/sys/vm/vm_page.c

Modified: head/sys/vm/vm_page.c
==============================================================================
--- head/sys/vm/vm_page.c	Wed Sep  2 19:37:47 2020	(r365274)
+++ head/sys/vm/vm_page.c	Wed Sep  2 19:59:25 2020	(r365275)
@@ -4724,12 +4724,11 @@ vm_page_grab_pages(vm_object_t object, vm_pindex_t pin
 	VM_OBJECT_ASSERT_WLOCKED(object);
 	KASSERT(((u_int)allocflags >> VM_ALLOC_COUNT_SHIFT) == 0,
 	    ("vm_page_grap_pages: VM_ALLOC_COUNT() is not allowed"));
+	KASSERT(count > 0,
+	    ("vm_page_grab_pages: invalid page count %d", count));
 	vm_page_grab_check(allocflags);
 
 	pflags = vm_page_grab_pflags(allocflags);
-	if (count == 0)
-		return (0);
-
 	i = 0;
 retrylookup:
 	m = vm_radix_lookup_le(&object->rtree, pindex + i);
@@ -4783,6 +4782,8 @@ vm_page_grab_pages_unlocked(vm_object_t object, vm_pin
 	int flags;
 	int i;
 
+	KASSERT(count > 0,
+	    ("vm_page_grab_pages_unlocked: invalid page count %d", count));
 	vm_page_grab_check(allocflags);
 
 	/*
@@ -4805,7 +4806,7 @@ vm_page_grab_pages_unlocked(vm_object_t object, vm_pin
 		vm_page_grab_release(m, allocflags);
 		pred = ma[i] = m;
 	}
-	if ((allocflags & VM_ALLOC_NOCREAT) != 0)
+	if (i == count || (allocflags & VM_ALLOC_NOCREAT) != 0)
 		return (i);
 	count -= i;
 	VM_OBJECT_WLOCK(object);



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