Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Rename buf_syncwait() to vfs_syncwait(), and have it wai...



details:   https://anonhg.NetBSD.org/src/rev/d8d70e8eda6c
branches:  trunk
changeset: 1009334:d8d70e8eda6c
user:      ad <ad%NetBSD.org@localhost>
date:      Mon Apr 20 21:39:05 2020 +0000

description:
Rename buf_syncwait() to vfs_syncwait(), and have it wait on v_numoutput
rather than BC_BUSY.  Removes the dependency on bufhash.

diffstat:

 sys/kern/kern_pmf.c                 |   6 +-
 sys/kern/vfs_bio.c                  |  55 +----------------------------
 sys/kern/vfs_mount.c                |   6 +-
 sys/kern/vfs_syscalls.c             |  70 +++++++++++++++++++++++++++++++++++-
 sys/rump/librump/rumpvfs/rump_vfs.c |   6 +-
 sys/sys/buf.h                       |   3 +-
 sys/sys/vfs_syscalls.h              |   3 +-
 7 files changed, 82 insertions(+), 67 deletions(-)

diffs (282 lines):

diff -r 6cc0072493a6 -r d8d70e8eda6c sys/kern/kern_pmf.c
--- a/sys/kern/kern_pmf.c       Mon Apr 20 20:03:21 2020 +0000
+++ b/sys/kern/kern_pmf.c       Mon Apr 20 21:39:05 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_pmf.c,v 1.41 2020/02/23 20:08:35 ad Exp $ */
+/* $NetBSD: kern_pmf.c,v 1.42 2020/04/20 21:39:05 ad Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_pmf.c,v 1.41 2020/02/23 20:08:35 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_pmf.c,v 1.42 2020/04/20 21:39:05 ad Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -317,7 +317,7 @@
        if (doing_shutdown == 0 && panicstr == NULL) {
                printf("Flushing disk caches: ");
                do_sys_sync(&lwp0);
-               if (buf_syncwait() != 0)
+               if (vfs_syncwait() != 0)
                        printf("giving up\n");
                else
                        printf("done\n");
diff -r 6cc0072493a6 -r d8d70e8eda6c sys/kern/vfs_bio.c
--- a/sys/kern/vfs_bio.c        Mon Apr 20 20:03:21 2020 +0000
+++ b/sys/kern/vfs_bio.c        Mon Apr 20 21:39:05 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_bio.c,v 1.293 2020/04/11 14:48:19 jdolecek Exp $   */
+/*     $NetBSD: vfs_bio.c,v 1.294 2020/04/20 21:39:05 ad Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008, 2009, 2019, 2020 The NetBSD Foundation, Inc.
@@ -123,7 +123,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.293 2020/04/11 14:48:19 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.294 2020/04/20 21:39:05 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_bufcache.h"
@@ -1708,57 +1708,6 @@
        splx(s);
 }
 
-/*
- * Wait for all buffers to complete I/O
- * Return the number of "stuck" buffers.
- */
-int
-buf_syncwait(void)
-{
-       buf_t *bp;
-       int iter, nbusy, nbusy_prev = 0, ihash;
-
-       BIOHIST_FUNC(__func__); BIOHIST_CALLED(biohist);
-
-       for (iter = 0; iter < 20;) {
-               mutex_enter(&bufcache_lock);
-               nbusy = 0;
-               for (ihash = 0; ihash < bufhash+1; ihash++) {
-                   LIST_FOREACH(bp, &bufhashtbl[ihash], b_hash) {
-                       if ((bp->b_cflags & (BC_BUSY|BC_INVAL)) == BC_BUSY)
-                               nbusy += ((bp->b_flags & B_READ) == 0);
-                   }
-               }
-               mutex_exit(&bufcache_lock);
-
-               if (nbusy == 0)
-                       break;
-               if (nbusy_prev == 0)
-                       nbusy_prev = nbusy;
-               printf("%d ", nbusy);
-               kpause("bflush", false, MAX(1, hz / 25 * iter), NULL);
-               if (nbusy >= nbusy_prev) /* we didn't flush anything */
-                       iter++;
-               else
-                       nbusy_prev = nbusy;
-       }
-
-       if (nbusy) {
-#if defined(DEBUG) || defined(DEBUG_HALT_BUSY)
-               printf("giving up\nPrinting vnodes for busy buffers\n");
-               for (ihash = 0; ihash < bufhash+1; ihash++) {
-                   LIST_FOREACH(bp, &bufhashtbl[ihash], b_hash) {
-                       if ((bp->b_cflags & (BC_BUSY|BC_INVAL)) == BC_BUSY &&
-                           (bp->b_flags & B_READ) == 0)
-                               vprint(NULL, bp->b_vp);
-                   }
-               }
-#endif
-       }
-
-       return nbusy;
-}
-
 static void
 sysctl_fillbuf(const buf_t *i, struct buf_sysctl *o)
 {
diff -r 6cc0072493a6 -r d8d70e8eda6c sys/kern/vfs_mount.c
--- a/sys/kern/vfs_mount.c      Mon Apr 20 20:03:21 2020 +0000
+++ b/sys/kern/vfs_mount.c      Mon Apr 20 21:39:05 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_mount.c,v 1.79 2020/04/19 13:26:17 hannken Exp $   */
+/*     $NetBSD: vfs_mount.c,v 1.80 2020/04/20 21:39:05 ad Exp $        */
 
 /*-
  * Copyright (c) 1997-2020 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.79 2020/04/19 13:26:17 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.80 2020/04/20 21:39:05 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -1093,7 +1093,7 @@
        do_sys_sync(l);
 
        /* Wait for sync to finish. */
-       if (buf_syncwait() != 0) {
+       if (vfs_syncwait() != 0) {
 #if defined(DDB) && defined(DEBUG_HALT_BUSY)
                Debugger();
 #endif
diff -r 6cc0072493a6 -r d8d70e8eda6c sys/kern/vfs_syscalls.c
--- a/sys/kern/vfs_syscalls.c   Mon Apr 20 20:03:21 2020 +0000
+++ b/sys/kern/vfs_syscalls.c   Mon Apr 20 21:39:05 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_syscalls.c,v 1.545 2020/04/04 20:49:30 ad Exp $    */
+/*     $NetBSD: vfs_syscalls.c,v 1.546 2020/04/20 21:39:05 ad Exp $    */
 
 /*-
  * Copyright (c) 2008, 2009, 2019, 2020 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.545 2020/04/04 20:49:30 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.546 2020/04/20 21:39:05 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_fileassoc.h"
@@ -672,6 +672,72 @@
 #endif /* DEBUG */
 }
 
+static bool
+sync_vnode_filter(void *cookie, vnode_t *vp)
+{
+
+       if (vp->v_numoutput > 0) {
+               ++*(int *)cookie;
+       }
+       return false;
+}
+
+int
+vfs_syncwait(void)
+{
+       int nbusy, nbusy_prev, iter;
+       struct vnode_iterator *vniter;
+       mount_iterator_t *mpiter;
+       struct mount *mp;
+
+       for (nbusy_prev = 0, iter = 0; iter < 20;) {
+               nbusy = 0;
+               mountlist_iterator_init(&mpiter);
+               while ((mp = mountlist_iterator_next(mpiter)) != NULL) {
+                       vnode_t *vp __diagused;
+                       vfs_vnode_iterator_init(mp, &vniter);
+                       vp = vfs_vnode_iterator_next(vniter,
+                           sync_vnode_filter, &nbusy);
+                       KASSERT(vp == NULL);
+                       vfs_vnode_iterator_destroy(vniter);
+               }
+               mountlist_iterator_destroy(mpiter);
+
+               if (nbusy == 0)
+                       break;
+               if (nbusy_prev == 0)
+                       nbusy_prev = nbusy;
+               printf("%d ", nbusy);
+               kpause("syncwait", false, MAX(1, hz / 25 * iter), NULL);
+               if (nbusy >= nbusy_prev) /* we didn't flush anything */
+                       iter++;
+               else
+                       nbusy_prev = nbusy;
+       }
+
+       if (nbusy) {
+#if defined(DEBUG) || defined(DEBUG_HALT_BUSY)
+               printf("giving up\nPrinting vnodes for busy buffers\n");
+               mountlist_iterator_init(&mpiter);
+               while ((mp = mountlist_iterator_next(mpiter)) != NULL) {
+                       vnode_t *vp;
+                       vfs_vnode_iterator_init(mp, &vniter);
+                       vp = vfs_vnode_iterator_next(vniter,
+                           NULL, NULL);
+                       mutex_enter(vp->v_interlock);
+                       if (vp->v_numoutput > 0)
+                               vprint(NULL, vp);
+                       mutex_exit(vp->v_interlock);
+                       vrele(vp);
+                       vfs_vnode_iterator_destroy(vniter);
+               }
+               mountlist_iterator_destroy(mpiter);
+#endif
+       }
+
+       return nbusy;
+}
+
 /* ARGSUSED */
 int
 sys_sync(struct lwp *l, const void *v, register_t *retval)
diff -r 6cc0072493a6 -r d8d70e8eda6c sys/rump/librump/rumpvfs/rump_vfs.c
--- a/sys/rump/librump/rumpvfs/rump_vfs.c       Mon Apr 20 20:03:21 2020 +0000
+++ b/sys/rump/librump/rumpvfs/rump_vfs.c       Mon Apr 20 21:39:05 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rump_vfs.c,v 1.91 2020/04/13 19:23:20 ad Exp $ */
+/*     $NetBSD: rump_vfs.c,v 1.92 2020/04/20 21:39:05 ad Exp $ */
 
 /*
  * Copyright (c) 2008 Antti Kantee.  All Rights Reserved.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rump_vfs.c,v 1.91 2020/04/13 19:23:20 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rump_vfs.c,v 1.92 2020/04/20 21:39:05 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/buf.h>
@@ -470,7 +470,7 @@
 {
        int n;
 
-       n = buf_syncwait();
+       n = vfs_syncwait();
        if (n)
                printf("syncwait: unsynced buffers: %d\n", n);
 }
diff -r 6cc0072493a6 -r d8d70e8eda6c sys/sys/buf.h
--- a/sys/sys/buf.h     Mon Apr 20 20:03:21 2020 +0000
+++ b/sys/sys/buf.h     Mon Apr 20 21:39:05 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: buf.h,v 1.132 2020/04/10 17:18:04 ad Exp $ */
+/*     $NetBSD: buf.h,v 1.133 2020/04/20 21:39:05 ad Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2007, 2008 The NetBSD Foundation, Inc.
@@ -299,7 +299,6 @@
 void   brelvp(buf_t *);
 void   reassignbuf(buf_t *, struct vnode *);
 void   bgetvp(struct vnode *, buf_t *);
-int    buf_syncwait(void);
 u_long buf_memcalc(void);
 int    buf_drain(int);
 int    buf_setvalimit(vsize_t);
diff -r 6cc0072493a6 -r d8d70e8eda6c sys/sys/vfs_syscalls.h
--- a/sys/sys/vfs_syscalls.h    Mon Apr 20 20:03:21 2020 +0000
+++ b/sys/sys/vfs_syscalls.h    Mon Apr 20 21:39:05 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_syscalls.h,v 1.27 2020/02/23 22:14:04 ad Exp $        */
+/*     $NetBSD: vfs_syscalls.h,v 1.28 2020/04/20 21:39:05 ad Exp $        */
 
 /*
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -80,6 +80,7 @@
 int    do_sys_symlink(const char *, const char *, enum uio_seg);
 int    do_sys_quotactl(const char *, const struct quotactl_args *);
 void   do_sys_sync(struct lwp *);
+int    vfs_syncwait(void);
 
 int    chdir_lookup(const char *, int, struct vnode **, struct lwp *);
 void   change_root(struct vnode *);



Home | Main Index | Thread Index | Old Index