Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 6 Jan 2012 11:06:15 +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-9@freebsd.org
Subject:   svn commit: r229695 - stable/9/sys/vm
Message-ID:  <201201061106.q06B6FIZ086849@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Fri Jan  6 11:06:15 2012
New Revision: 229695
URL: http://svn.freebsd.org/changeset/base/229695

Log:
  MFC r228838:
  Optimize the common case of msyncing the whole file mapping with
  MS_SYNC flag.

Modified:
  stable/9/sys/vm/vm_object.c
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/vm/vm_object.c
==============================================================================
--- stable/9/sys/vm/vm_object.c	Fri Jan  6 10:12:59 2012	(r229694)
+++ stable/9/sys/vm/vm_object.c	Fri Jan  6 11:06:15 2012	(r229695)
@@ -937,7 +937,7 @@ vm_object_sync(vm_object_t object, vm_oo
 	vm_object_t backing_object;
 	struct vnode *vp;
 	struct mount *mp;
-	int flags;
+	int flags, fsync_after;
 
 	if (object == NULL)
 		return;
@@ -970,11 +970,26 @@ vm_object_sync(vm_object_t object, vm_oo
 		(void) vn_start_write(vp, &mp, V_WAIT);
 		vfslocked = VFS_LOCK_GIANT(vp->v_mount);
 		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
-		flags = (syncio || invalidate) ? OBJPC_SYNC : 0;
-		flags |= invalidate ? OBJPC_INVAL : 0;
+		if (syncio && !invalidate && offset == 0 &&
+		    OFF_TO_IDX(size) == object->size) {
+			/*
+			 * If syncing the whole mapping of the file,
+			 * it is faster to schedule all the writes in
+			 * async mode, also allowing the clustering,
+			 * and then wait for i/o to complete.
+			 */
+			flags = 0;
+			fsync_after = TRUE;
+		} else {
+			flags = (syncio || invalidate) ? OBJPC_SYNC : 0;
+			flags |= invalidate ? (OBJPC_SYNC | OBJPC_INVAL) : 0;
+			fsync_after = FALSE;
+		}
 		VM_OBJECT_LOCK(object);
 		vm_object_page_clean(object, offset, offset + size, flags);
 		VM_OBJECT_UNLOCK(object);
+		if (fsync_after)
+			(void) VOP_FSYNC(vp, MNT_WAIT, curthread);
 		VOP_UNLOCK(vp, 0);
 		VFS_UNLOCK_GIANT(vfslocked);
 		vn_finished_write(mp);



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