From nobody@FreeBSD.org  Fri Feb 15 13:43:14 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115])
	by hub.freebsd.org (Postfix) with ESMTP id 0C16C12E
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 15 Feb 2013 13:43:14 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id E85F1C1F
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 15 Feb 2013 13:43:13 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id r1FDhD8p018890
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 15 Feb 2013 13:43:13 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id r1FDhDAQ018889;
	Fri, 15 Feb 2013 13:43:13 GMT
	(envelope-from nobody)
Message-Id: <201302151343.r1FDhDAQ018889@red.freebsd.org>
Date: Fri, 15 Feb 2013 13:43:13 GMT
From: Norbert Koch <nkoch@demig.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: system unresponsive for 1min after mounting flash read-only
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         176169
>Category:       kern
>Synopsis:       [vfs] [patch] system unresponsive for 1min after mounting flash read-only
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Feb 15 13:50:03 UTC 2013
>Closed-Date:    
>Last-Modified:  Fri Feb 15 21:56:55 UTC 2013
>Originator:     Norbert Koch
>Release:        FreeBSD 9.1
>Organization:
>Environment:
FreeBSD 9.1 RELEASE
>Description:
This problem has already been reported and fixed(?) in pfsense's bug tracking
system by adding the sysctl vfs.forcesync.
The author of the fix is Ermal Lui ( http://redmine.pfsense.org/users/6 ).

http://redmine.pfsense.org/projects/pfsense-tools/repository/revisions/008742971cb44d8c0f81929504ab7330442c4ba4/entry/patches/RELENG_8_3/vfs_subr_mount_RO.diff

I tried this under FreeBSD 9.1 and it seems to work.

mount -ow / ; time mount -orf /
 : 65s without patch

With patch time is <1s.

As I am no vfs expert I do not know what potential negative consequences
this change may have.

The original patch uses CTLFLAG_RD for forcesync. I do not see why
this should not be CTLFLAG_RW.
>How-To-Repeat:

>Fix:
diff -r 89885db951fb src/sys/kern/vfs_subr.c
--- a/src/sys/kern/vfs_subr.c	Mon Feb 04 14:45:48 2013 +0100
+++ b/src/sys/kern/vfs_subr.c	Fri Feb 15 14:32:09 2013 +0100
@@ -121,6 +121,11 @@
 SYSCTL_ULONG(_vfs, OID_AUTO, numvnodes, CTLFLAG_RD, &numvnodes, 0,
     "Number of vnodes in existence");
 
+static int forcesync;
+
+SYSCTL_INT(_vfs, OID_AUTO, forcesync, CTLFLAG_RW, &forcesync, 0,
+    "Do full checks when switching to RO mount of FS");
+
 /*
  * Conversion tables for conversion from vnode types to inode formats
  * and back.
@@ -2581,6 +2586,7 @@
 		 * vnodes open for writing.
 		 */
 		if (flags & WRITECLOSE) {
+                        if (forcesync) {
 			if (vp->v_object != NULL) {
 				VM_OBJECT_LOCK(vp->v_object);
 				vm_object_page_clean(vp->v_object, 0, 0, 0);
@@ -2593,6 +2599,7 @@
 				MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
 				return (error);
 			}
+                        }
 			error = VOP_GETATTR(vp, &vattr, td->td_ucred);
 			VI_LOCK(vp);
 


>Release-Note:
>Audit-Trail:
>Unformatted:
