Subject: kern/15232: ffs_sync writes out read-only pages to disk
To: None <gnats-bugs@gnats.netbsd.org>
From: None <dbj@netbsd.org>
List: netbsd-bugs
Date: 01/13/2002 05:42:08
>Number:         15232
>Category:       kern
>Synopsis:       ffs_sync writes out read-only pages to disk
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sun Jan 13 02:49:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Darrin B. Jewell
>Release:        NetBSD 1.5ZA 20020105T2358Z
>Organization:
>Environment:
System: NetBSD quiteria 1.5ZA NetBSD 1.5ZA (WORK) #133: Sun Jan 13 05:04:10 EST 2002 dbj@quiteria:/usr/src/sys/arch/macppc/compile/WORK macppc
Architecture: powerpc
Machine: macppc
>Description:

        I spent some time trying to figure out why my ibook's disk
would not spin down when idle after I had been using the system for a
while.  Eventually, I discovered that our ffs_sync routine flushes out
a vnode if vp->v_uobj.uo_pages is non-zero.  Since this is true when
an executable is mapped read-only, i found that my executables and
shared libraries were constantly being written out to disk.

>How-To-Repeat:
        Watch iostat on a machine with several idle processes,
and disks mounted with the noatime and nodevtime options.

>Fix:
I first instrumented ufs_strategy to print out the first vnode that
was being written out to disk after a significant (~17 seconds --
enough to avoid noise when not quiescent) delay.  I observed that
the vnode being written was usually an executable or shared
library, which seemed incorrect.

Upon inspection, I noticed that our current implementation of
uvn_attach ignores its accessprot argument, and therefore cannot keep
track of whether a vnode is backing read-only pages or not.  However,
I did notice that both locations where we ever call uvn_attach with an
argument of VM_PROT_WRITE (sys_fhopen and vn_open), we immediately
increment the v_writecount vnode field.  Therefore, I changed ffs_sync
to also examine the v_writecount field of a vnode when determining
whether a vnode needed to be flushed out to disk.

Now my ibook spins its disk down when idle.

This fix should be reviewed by someone knowledgable with the uvm
system.

Index: ffs_vfsops.c
===================================================================
RCS file: /cvsroot/syssrc/sys/ufs/ffs/ffs_vfsops.c,v
retrieving revision 1.91
diff -u -r1.91 ffs_vfsops.c
--- ffs_vfsops.c	2001/12/30 15:46:53	1.91
+++ ffs_vfsops.c	2002/01/13 10:28:00
@@ -1010,7 +1010,7 @@
 		    ((ip->i_flag &
 		      (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFIED | IN_ACCESSED)) == 0 &&
 		     LIST_EMPTY(&vp->v_dirtyblkhd) &&
-		     vp->v_uobj.uo_npages == 0))
+		     ((vp->v_uobj.uo_npages == 0) || (vp->v_writecount == 0))))
 		{
 			simple_unlock(&vp->v_interlock);
 			continue;
>Release-Note:
>Audit-Trail:
>Unformatted: