Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 Jan 2011 13:50:37 +0000 (UTC)
From:      Konstantin Belousov <kib@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: r217008 - stable/8/sys/vm
Message-ID:  <201101051350.p05Dobcb080130@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Wed Jan  5 13:50:37 2011
New Revision: 217008
URL: http://svn.freebsd.org/changeset/base/217008

Log:
  MFC r216799:
  Move the increment of vm object generation count into
  vm_object_set_writeable_dirty(). Merge two loops in
  vm_object_page_clean(), doing the removal of write permission and
  cleaning in the same loop. Clear the OBJ_MIGHTBEDIRTY flag after the
  cleaning loop, not before.

Modified:
  stable/8/sys/vm/vm_object.c
  stable/8/sys/vm/vm_page.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)

Modified: stable/8/sys/vm/vm_object.c
==============================================================================
--- stable/8/sys/vm/vm_object.c	Wed Jan  5 13:40:40 2011	(r217007)
+++ stable/8/sys/vm/vm_object.c	Wed Jan  5 13:50:37 2011	(r217008)
@@ -105,7 +105,9 @@ SYSCTL_INT(_vm, OID_AUTO, old_msync, CTL
     "Use old (insecure) msync behavior");
 
 static int	vm_object_page_collect_flush(vm_object_t object, vm_page_t p,
-		    int pagerflags);
+		    int pagerflags, int flags, int *clearobjflags);
+static boolean_t vm_object_page_remove_write(vm_page_t p, int flags,
+		    int *clearobjflags);
 static void	vm_object_qcollapse(vm_object_t object);
 static void	vm_object_vndeallocate(vm_object_t object);
 
@@ -739,6 +741,24 @@ vm_object_terminate(vm_object_t object)
 	vm_object_destroy(object);
 }
 
+static boolean_t
+vm_object_page_remove_write(vm_page_t p, int flags, int *clearobjflags)
+{
+
+	/*
+	 * If we have been asked to skip nosync pages and this is a
+	 * nosync page, skip it.  Note that the object flags were not
+	 * cleared in this case so we do not have to set them.
+	 */
+	if ((flags & OBJPC_NOSYNC) != 0 && (p->oflags & VPO_NOSYNC) != 0) {
+		*clearobjflags = 0;
+		return (FALSE);
+	} else {
+		pmap_remove_write(p);
+		return (p->dirty != 0);
+	}
+}
+
 /*
  *	vm_object_page_clean
  *
@@ -786,17 +806,6 @@ vm_object_page_clean(vm_object_t object,
 	 * object flags.
 	 */
 	clearobjflags = 1;
-	for (p = vm_page_find_least(object, start);
-	    p != NULL && p->pindex < tend; p = TAILQ_NEXT(p, listq)) {
-		if ((flags & OBJPC_NOSYNC) != 0 &&
-		    (p->oflags & VPO_NOSYNC) != 0)
-			clearobjflags = 0;
-		else
-			pmap_remove_write(p);
-	}
-
-	if (clearobjflags && (start == 0) && (tend == object->size))
-		vm_object_clear_flag(object, OBJ_MIGHTBEDIRTY);
 
 rescan:
 	curgeneration = object->generation;
@@ -815,20 +824,11 @@ rescan:
 			np = vm_page_find_least(object, pi);
 			continue;
 		}
-		vm_page_test_dirty(p);
-		if (p->dirty == 0)
+		if (!vm_object_page_remove_write(p, flags, &clearobjflags))
 			continue;
 
-		/*
-		 * If we have been asked to skip nosync pages and this is a
-		 * nosync page, skip it.  Note that the object flags were
-		 * not cleared in this case so we do not have to set them.
-		 */
-		if ((flags & OBJPC_NOSYNC) != 0 &&
-		    (p->oflags & VPO_NOSYNC) != 0)
-			continue;
-
-		n = vm_object_page_collect_flush(object, p, pagerflags);
+		n = vm_object_page_collect_flush(object, p, pagerflags,
+		    flags, &clearobjflags);
 		if (object->generation != curgeneration)
 			goto rescan;
 		np = vm_page_find_least(object, pi + n);
@@ -839,10 +839,13 @@ rescan:
 #endif
 
 	vm_object_clear_flag(object, OBJ_CLEANING);
+	if (clearobjflags && start == 0 && tend == object->size)
+		vm_object_clear_flag(object, OBJ_MIGHTBEDIRTY);
 }
 
 static int
-vm_object_page_collect_flush(vm_object_t object, vm_page_t p, int pagerflags)
+vm_object_page_collect_flush(vm_object_t object, vm_page_t p, int pagerflags,
+    int flags, int *clearobjflags)
 {
 	vm_page_t ma[vm_pageout_page_count], p_first, tp;
 	int count, i, mreq, runlen;
@@ -856,8 +859,7 @@ vm_object_page_collect_flush(vm_object_t
 		tp = vm_page_next(tp);
 		if (tp == NULL || tp->busy != 0 || (tp->oflags & VPO_BUSY) != 0)
 			break;
-		vm_page_test_dirty(tp);
-		if (tp->dirty == 0)
+		if (!vm_object_page_remove_write(tp, flags, clearobjflags))
 			break;
 	}
 
@@ -865,8 +867,7 @@ vm_object_page_collect_flush(vm_object_t
 		tp = vm_page_prev(p_first);
 		if (tp == NULL || tp->busy != 0 || (tp->oflags & VPO_BUSY) != 0)
 			break;
-		vm_page_test_dirty(tp);
-		if (tp->dirty == 0)
+		if (!vm_object_page_remove_write(tp, flags, clearobjflags))
 			break;
 		p_first = tp;
 		mreq++;
@@ -1964,8 +1965,10 @@ vm_object_set_writeable_dirty(vm_object_
 {
 
 	VM_OBJECT_LOCK_ASSERT(object, MA_OWNED);
-	if (object->type != OBJT_VNODE ||
-	    (object->flags & OBJ_MIGHTBEDIRTY) != 0)
+	if (object->type != OBJT_VNODE)
+		return;
+	object->generation++;
+	if ((object->flags & OBJ_MIGHTBEDIRTY) != 0)
 		return;
 	vm_object_set_flag(object, OBJ_MIGHTBEDIRTY);
 }

Modified: stable/8/sys/vm/vm_page.c
==============================================================================
--- stable/8/sys/vm/vm_page.c	Wed Jan  5 13:40:40 2011	(r217007)
+++ stable/8/sys/vm/vm_page.c	Wed Jan  5 13:50:37 2011	(r217008)
@@ -687,7 +687,6 @@ vm_page_insert(vm_page_t m, vm_object_t 
 		}
 	}
 	object->root = m;
-	object->generation++;
 
 	/*
 	 * show that the object has one more resident page.



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