Mon Apr 20 21:39:05 2020 UTC ()
Rename buf_syncwait() to vfs_syncwait(), and have it wait on v_numoutput
rather than BC_BUSY. Removes the dependency on bufhash.
(ad)
diff -r1.41 -r1.42 src/sys/kern/kern_pmf.c
diff -r1.293 -r1.294 src/sys/kern/vfs_bio.c
diff -r1.79 -r1.80 src/sys/kern/vfs_mount.c
diff -r1.545 -r1.546 src/sys/kern/vfs_syscalls.c
diff -r1.91 -r1.92 src/sys/rump/librump/rumpvfs/rump_vfs.c
diff -r1.132 -r1.133 src/sys/sys/buf.h
diff -r1.27 -r1.28 src/sys/sys/vfs_syscalls.h
--- src/sys/kern/kern_pmf.c 2020/02/23 20:08:35 1.41
+++ src/sys/kern/kern_pmf.c 2020/04/20 21:39:05 1.42
@@ -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>
@@ -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");
--- src/sys/kern/vfs_bio.c 2020/04/11 14:48:19 1.293
+++ src/sys/kern/vfs_bio.c 2020/04/20 21:39:05 1.294
@@ -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"
@@ -1706,57 +1706,6 @@
s = splvm();
}
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
--- src/sys/kern/vfs_mount.c 2020/04/19 13:26:17 1.79
+++ src/sys/kern/vfs_mount.c 2020/04/20 21:39:05 1.80
@@ -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
--- src/sys/kern/vfs_syscalls.c 2020/04/04 20:49:30 1.545
+++ src/sys/kern/vfs_syscalls.c 2020/04/20 21:39:05 1.546
@@ -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"
@@ -670,6 +670,72 @@
if (syncprt)
vfs_bufstats();
#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 */
--- src/sys/rump/librump/rumpvfs/rump_vfs.c 2020/04/13 19:23:20 1.91
+++ src/sys/rump/librump/rumpvfs/rump_vfs.c 2020/04/20 21:39:05 1.92
@@ -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);
}
--- src/sys/sys/buf.h 2020/04/10 17:18:04 1.132
+++ src/sys/sys/buf.h 2020/04/20 21:39:05 1.133
@@ -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);
--- src/sys/sys/vfs_syscalls.h 2020/02/23 22:14:04 1.27
+++ src/sys/sys/vfs_syscalls.h 2020/04/20 21:39:05 1.28
@@ -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 *);