Module Name: src Committed By: hannken Date: Wed Dec 14 15:46:57 UTC 2016
Modified Files: src/sys/kern: init_sysctl.c vfs_mount.c vfs_vnode.c src/sys/sys: vnode.h vnode_impl.h Log Message: Remove the "target" argment from vfs_drainvnodes() as it is always equal to "desiredvnodes" and move its definition from sys/vnode.h to sys/vnode_impl.h. Extend vfs_drainvnodes() to also wait for deferred vrele to flush and replace the call to vrele_flush() with a call to vfs_drainvnodes(). To generate a diff of this commit: cvs rdiff -u -r1.211 -r1.212 src/sys/kern/init_sysctl.c cvs rdiff -u -r1.41 -r1.42 src/sys/kern/vfs_mount.c cvs rdiff -u -r1.60 -r1.61 src/sys/kern/vfs_vnode.c cvs rdiff -u -r1.265 -r1.266 src/sys/sys/vnode.h cvs rdiff -u -r1.2 -r1.3 src/sys/sys/vnode_impl.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/init_sysctl.c diff -u src/sys/kern/init_sysctl.c:1.211 src/sys/kern/init_sysctl.c:1.212 --- src/sys/kern/init_sysctl.c:1.211 Tue May 31 05:44:19 2016 +++ src/sys/kern/init_sysctl.c Wed Dec 14 15:46:57 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: init_sysctl.c,v 1.211 2016/05/31 05:44:19 pgoyette Exp $ */ +/* $NetBSD: init_sysctl.c,v 1.212 2016/12/14 15:46:57 hannken Exp $ */ /*- * Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.211 2016/05/31 05:44:19 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.212 2016/12/14 15:46:57 hannken Exp $"); #include "opt_sysv.h" #include "opt_compat_netbsd.h" @@ -47,7 +47,7 @@ __KERNEL_RCSID(0, "$NetBSD: init_sysctl. #include <sys/unistd.h> #include <sys/disklabel.h> #include <sys/cprng.h> -#include <sys/vnode.h> +#include <sys/vnode_impl.h> /* For vfs_drainvnodes(). */ #include <sys/mount.h> #include <sys/namei.h> #include <dev/cons.h> @@ -756,7 +756,7 @@ sysctl_kern_maxvnodes(SYSCTLFN_ARGS) old_vnodes = desiredvnodes; desiredvnodes = new_vnodes; - error = vfs_drainvnodes(new_vnodes); + error = vfs_drainvnodes(); if (error) { desiredvnodes = old_vnodes; return (error); Index: src/sys/kern/vfs_mount.c diff -u src/sys/kern/vfs_mount.c:1.41 src/sys/kern/vfs_mount.c:1.42 --- src/sys/kern/vfs_mount.c:1.41 Thu Nov 3 11:03:31 2016 +++ src/sys/kern/vfs_mount.c Wed Dec 14 15:46:57 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_mount.c,v 1.41 2016/11/03 11:03:31 hannken Exp $ */ +/* $NetBSD: vfs_mount.c,v 1.42 2016/12/14 15:46:57 hannken Exp $ */ /*- * Copyright (c) 1997-2011 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.41 2016/11/03 11:03:31 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.42 2016/12/14 15:46:57 hannken Exp $"); #include <sys/param.h> #include <sys/kernel.h> @@ -509,8 +509,8 @@ vflush(struct mount *mp, vnode_t *skipvp int error, busy = 0, when = 0; struct vflush_ctx ctx; - /* First, flush out any vnode references from vrele_list. */ - vrele_flush(); + /* First, flush out any vnode references from deferred vrele list. */ + vfs_drainvnodes(); vfs_vnode_iterator_init(mp, &marker); Index: src/sys/kern/vfs_vnode.c diff -u src/sys/kern/vfs_vnode.c:1.60 src/sys/kern/vfs_vnode.c:1.61 --- src/sys/kern/vfs_vnode.c:1.60 Thu Dec 1 14:49:03 2016 +++ src/sys/kern/vfs_vnode.c Wed Dec 14 15:46:57 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_vnode.c,v 1.60 2016/12/01 14:49:03 hannken Exp $ */ +/* $NetBSD: vfs_vnode.c,v 1.61 2016/12/14 15:46:57 hannken Exp $ */ /*- * Copyright (c) 1997-2011 The NetBSD Foundation, Inc. @@ -156,7 +156,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.60 2016/12/01 14:49:03 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.61 2016/12/14 15:46:57 hannken Exp $"); #include <sys/param.h> #include <sys/kernel.h> @@ -208,6 +208,7 @@ SLIST_HEAD(hashhead, vnode_impl); static struct { kmutex_t lock; kcondvar_t cv; + u_int hashsize; u_long hashmask; struct hashhead *hashtab; pool_cache_t pool; @@ -857,20 +858,6 @@ vrele_thread(void *cookie) } } -void -vrele_flush(void) -{ - int gen; - - mutex_enter(&vrele_lock); - gen = vrele_gen; - while (vrele_pending && gen == vrele_gen) { - cv_broadcast(&vrele_cv); - cv_wait(&vrele_cv, &vrele_lock); - } - mutex_exit(&vrele_lock); -} - /* * Vnode reference, where a reference is already held by some other * object (for example, a file structure). @@ -1040,6 +1027,7 @@ vcache_init(void) KASSERT(vcache.pool != NULL); mutex_init(&vcache.lock, MUTEX_DEFAULT, IPL_NONE); cv_init(&vcache.cv, "vcache"); + vcache.hashsize = desiredvnodes; vcache.hashtab = hashinit(desiredvnodes, HASH_SLIST, true, &vcache.hashmask); } @@ -1057,6 +1045,7 @@ vcache_reinit(void) mutex_enter(&vcache.lock); oldtab = vcache.hashtab; oldmask = vcache.hashmask; + vcache.hashsize = desiredvnodes; vcache.hashtab = newtab; vcache.hashmask = newmask; for (i = 0; i <= oldmask; i++) { @@ -1601,13 +1590,21 @@ vdead_check(struct vnode *vp, int flags) } int -vfs_drainvnodes(long target) +vfs_drainvnodes(void) { - int error; + int error, gen; + + mutex_enter(&vrele_lock); + gen = vrele_gen; + while (vrele_pending && gen == vrele_gen) { + cv_broadcast(&vrele_cv); + cv_wait(&vrele_cv, &vrele_lock); + } + mutex_exit(&vrele_lock); mutex_enter(&vnode_free_list_lock); - while (numvnodes > target) { + while (numvnodes > desiredvnodes) { error = cleanvnode(); if (error != 0) return error; @@ -1616,7 +1613,8 @@ vfs_drainvnodes(long target) mutex_exit(&vnode_free_list_lock); - vcache_reinit(); + if (vcache.hashsize != desiredvnodes) + vcache_reinit(); return 0; } Index: src/sys/sys/vnode.h diff -u src/sys/sys/vnode.h:1.265 src/sys/sys/vnode.h:1.266 --- src/sys/sys/vnode.h:1.265 Thu Nov 3 11:03:31 2016 +++ src/sys/sys/vnode.h Wed Dec 14 15:46:57 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: vnode.h,v 1.265 2016/11/03 11:03:31 hannken Exp $ */ +/* $NetBSD: vnode.h,v 1.266 2016/12/14 15:46:57 hannken Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -530,7 +530,6 @@ void vput(struct vnode *); bool vrecycle(struct vnode *); void vrele(struct vnode *); void vrele_async(struct vnode *); -void vrele_flush(void); int vtruncbuf(struct vnode *, daddr_t, bool, int); void vwakeup(struct buf *); int vdead_check(struct vnode *, int); @@ -581,7 +580,6 @@ uint8_t vtype2dt(enum vtype); /* see vfssubr(9) */ void vfs_getnewfsid(struct mount *); -int vfs_drainvnodes(long); void vfs_timestamp(struct timespec *); #if defined(DDB) || defined(DEBUGPRINT) void vfs_vnode_print(struct vnode *, int, void (*)(const char *, ...) Index: src/sys/sys/vnode_impl.h diff -u src/sys/sys/vnode_impl.h:1.2 src/sys/sys/vnode_impl.h:1.3 --- src/sys/sys/vnode_impl.h:1.2 Thu Nov 3 11:04:21 2016 +++ src/sys/sys/vnode_impl.h Wed Dec 14 15:46:57 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: vnode_impl.h,v 1.2 2016/11/03 11:04:21 hannken Exp $ */ +/* $NetBSD: vnode_impl.h,v 1.3 2016/12/14 15:46:57 hannken Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -67,5 +67,6 @@ vnode_t * vnalloc_marker(struct mount *); void vnfree_marker(vnode_t *); bool vnis_marker(vnode_t *); +int vfs_drainvnodes(void); #endif /* !_SYS_VNODE_IMPL_H_ */