Subject: kern/15232: ffs_sync writes out read-only pages to disk
To: None <email@example.com>
From: None <firstname.lastname@example.org>
Date: 01/13/2002 05:42:08
>Synopsis: ffs_sync writes out read-only pages to disk
>Arrival-Date: Sun Jan 13 02:49:00 PST 2002
>Originator: Darrin B. Jewell
>Release: NetBSD 1.5ZA 20020105T2358Z
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
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.
Watch iostat on a machine with several idle processes,
and disks mounted with the noatime and nodevtime options.
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
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 @@
(IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFIED | IN_ACCESSED)) == 0 &&
- vp->v_uobj.uo_npages == 0))
+ ((vp->v_uobj.uo_npages == 0) || (vp->v_writecount == 0))))