Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Nov 2010 17:29:23 +0000 (UTC)
From:      Alan Cox <alc@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r215430 - in stable/8/sys: kern vm
Message-ID:  <201011171729.oAHHTNKk098773@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: alc
Date: Wed Nov 17 17:29:22 2010
New Revision: 215430
URL: http://svn.freebsd.org/changeset/base/215430

Log:
  MFC r209407, r209648, r209650
    Introduce and use vm_page_next() and vm_page_prev().  They provide both
    a simpler and faster interface for iterating over the pages of an object.

Modified:
  stable/8/sys/kern/kern_exec.c
  stable/8/sys/vm/vm_fault.c
  stable/8/sys/vm/vm_page.c
  stable/8/sys/vm/vm_page.h
  stable/8/sys/vm/vm_pageout.c
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)
  stable/8/sys/dev/xen/xenpci/   (props changed)

Modified: stable/8/sys/kern/kern_exec.c
==============================================================================
--- stable/8/sys/kern/kern_exec.c	Wed Nov 17 17:12:41 2010	(r215429)
+++ stable/8/sys/kern/kern_exec.c	Wed Nov 17 17:29:22 2010	(r215430)
@@ -935,7 +935,7 @@ exec_map_first_page(imgp)
 		if (initial_pagein > object->size)
 			initial_pagein = object->size;
 		for (i = 1; i < initial_pagein; i++) {
-			if ((ma[i] = vm_page_lookup(object, i)) != NULL) {
+			if ((ma[i] = vm_page_next(ma[i - 1])) != NULL) {
 				if (ma[i]->valid)
 					break;
 				if ((ma[i]->oflags & VPO_BUSY) || ma[i]->busy)

Modified: stable/8/sys/vm/vm_fault.c
==============================================================================
--- stable/8/sys/vm/vm_fault.c	Wed Nov 17 17:12:41 2010	(r215429)
+++ stable/8/sys/vm/vm_fault.c	Wed Nov 17 17:29:22 2010	(r215430)
@@ -215,7 +215,7 @@ vm_fault(vm_map_t map, vm_offset_t vaddr
 	boolean_t are_queues_locked, growstack, wired;
 	int map_generation;
 	vm_object_t next_object;
-	vm_page_t marray[VM_FAULT_READ];
+	vm_page_t marray[VM_FAULT_READ], mt, mt_prev;
 	int hardfault;
 	int faultcount, ahead, behind, alloc_req;
 	struct faultstate fs;
@@ -486,12 +486,18 @@ readrest:
 			    fs.first_object->type != OBJT_DEVICE &&
 			    fs.first_object->type != OBJT_PHYS &&
 			    fs.first_object->type != OBJT_SG) {
-				vm_pindex_t firstpindex, tmppindex;
+				vm_pindex_t firstpindex;
 
 				if (fs.first_pindex < 2 * VM_FAULT_READ)
 					firstpindex = 0;
 				else
 					firstpindex = fs.first_pindex - 2 * VM_FAULT_READ;
+				mt = fs.first_object != fs.object ?
+				    fs.first_m : fs.m;
+				KASSERT(mt != NULL, ("vm_fault: missing mt"));
+				KASSERT((mt->oflags & VPO_BUSY) != 0,
+				    ("vm_fault: mt %p not busy", mt));
+				mt_prev = vm_page_prev(mt);
 
 				are_queues_locked = FALSE;
 				/*
@@ -499,14 +505,10 @@ readrest:
 				 * included in the lookahead - NFS piecemeal
 				 * writes will barf on it badly.
 				 */
-				for (tmppindex = fs.first_pindex - 1;
-					tmppindex >= firstpindex;
-					--tmppindex) {
-					vm_page_t mt;
-
-					mt = vm_page_lookup(fs.first_object, tmppindex);
-					if (mt == NULL || (mt->valid != VM_PAGE_BITS_ALL))
-						break;
+				while ((mt = mt_prev) != NULL &&
+				    mt->pindex >= firstpindex &&
+				    mt->valid == VM_PAGE_BITS_ALL) {
+					mt_prev = vm_page_prev(mt);
 					if (mt->busy ||
 					    (mt->oflags & VPO_BUSY))
 						continue;

Modified: stable/8/sys/vm/vm_page.c
==============================================================================
--- stable/8/sys/vm/vm_page.c	Wed Nov 17 17:12:41 2010	(r215429)
+++ stable/8/sys/vm/vm_page.c	Wed Nov 17 17:29:22 2010	(r215430)
@@ -811,6 +811,42 @@ vm_page_find_least(vm_object_t object, v
 }
 
 /*
+ * Returns the given page's successor (by pindex) within the object if it is
+ * resident; if none is found, NULL is returned.
+ *
+ * The object must be locked.
+ */
+vm_page_t
+vm_page_next(vm_page_t m)
+{
+	vm_page_t next;
+
+	VM_OBJECT_LOCK_ASSERT(m->object, MA_OWNED);
+	if ((next = TAILQ_NEXT(m, listq)) != NULL &&
+	    next->pindex != m->pindex + 1)
+		next = NULL;
+	return (next);
+}
+
+/*
+ * Returns the given page's predecessor (by pindex) within the object if it is
+ * resident; if none is found, NULL is returned.
+ *
+ * The object must be locked.
+ */
+vm_page_t
+vm_page_prev(vm_page_t m)
+{
+	vm_page_t prev;
+
+	VM_OBJECT_LOCK_ASSERT(m->object, MA_OWNED);
+	if ((prev = TAILQ_PREV(m, pglist, listq)) != NULL &&
+	    prev->pindex != m->pindex - 1)
+		prev = NULL;
+	return (prev);
+}
+
+/*
  *	vm_page_rename:
  *
  *	Move the given memory entry from its

Modified: stable/8/sys/vm/vm_page.h
==============================================================================
--- stable/8/sys/vm/vm_page.h	Wed Nov 17 17:12:41 2010	(r215429)
+++ stable/8/sys/vm/vm_page.h	Wed Nov 17 17:29:22 2010	(r215430)
@@ -315,6 +315,8 @@ void vm_page_deactivate (vm_page_t);
 vm_page_t vm_page_find_least(vm_object_t, vm_pindex_t);
 void vm_page_insert (vm_page_t, vm_object_t, vm_pindex_t);
 vm_page_t vm_page_lookup (vm_object_t, vm_pindex_t);
+vm_page_t vm_page_next(vm_page_t m);
+vm_page_t vm_page_prev(vm_page_t m);
 void vm_page_remove (vm_page_t);
 void vm_page_rename (vm_page_t, vm_object_t, vm_pindex_t);
 void vm_page_requeue(vm_page_t m);

Modified: stable/8/sys/vm/vm_pageout.c
==============================================================================
--- stable/8/sys/vm/vm_pageout.c	Wed Nov 17 17:12:41 2010	(r215429)
+++ stable/8/sys/vm/vm_pageout.c	Wed Nov 17 17:29:22 2010	(r215430)
@@ -279,7 +279,7 @@ vm_pageout_clean(m)
 	vm_page_t m;
 {
 	vm_object_t object;
-	vm_page_t mc[2*vm_pageout_page_count];
+	vm_page_t mc[2*vm_pageout_page_count], pb, ps;
 	int pageout_count;
 	int ib, is, page_base;
 	vm_pindex_t pindex = m->pindex;
@@ -304,7 +304,7 @@ vm_pageout_clean(m)
 		return 0;
 	}
 
-	mc[vm_pageout_page_count] = m;
+	mc[vm_pageout_page_count] = pb = ps = m;
 	pageout_count = 1;
 	page_base = vm_pageout_page_count;
 	ib = 1;
@@ -339,11 +339,8 @@ more:
 			break;
 		}
 
-		if ((p = vm_page_lookup(object, pindex - ib)) == NULL) {
-			ib = 0;
-			break;
-		}
-		if ((p->oflags & VPO_BUSY) || p->busy) {
+		if ((p = vm_page_prev(pb)) == NULL ||
+		    (p->oflags & VPO_BUSY) != 0 || p->busy != 0) {
 			ib = 0;
 			break;
 		}
@@ -354,7 +351,7 @@ more:
 			ib = 0;
 			break;
 		}
-		mc[--page_base] = p;
+		mc[--page_base] = pb = p;
 		++pageout_count;
 		++ib;
 		/*
@@ -369,18 +366,16 @@ more:
 	    pindex + is < object->size) {
 		vm_page_t p;
 
-		if ((p = vm_page_lookup(object, pindex + is)) == NULL)
+		if ((p = vm_page_next(ps)) == NULL ||
+		    (p->oflags & VPO_BUSY) != 0 || p->busy != 0)
 			break;
-		if ((p->oflags & VPO_BUSY) || p->busy) {
-			break;
-		}
 		vm_page_test_dirty(p);
 		if (p->dirty == 0 ||
 		    p->queue != PQ_INACTIVE ||
 		    p->hold_count != 0) {	/* may be undergoing I/O */
 			break;
 		}
-		mc[page_base + pageout_count] = p;
+		mc[page_base + pageout_count] = ps = p;
 		++pageout_count;
 		++is;
 	}



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