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().diff -r1.211 -r1.212 src/sys/kern/init_sysctl.c
(hannken)
--- src/sys/kern/init_sysctl.c 2016/05/31 05:44:19 1.211
+++ src/sys/kern/init_sysctl.c 2016/12/14 15:46:57 1.212
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: init_sysctl.c,v 1.211 2016/05/31 05:44:19 pgoyette Exp $ */ | 1 | /* $NetBSD: init_sysctl.c,v 1.212 2016/12/14 15:46:57 hannken Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Andrew Brown, and by Andrew Doran. | 8 | * by Andrew Brown, and by Andrew Doran. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -20,44 +20,44 @@ | @@ -20,44 +20,44 @@ | |||
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | __KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.211 2016/05/31 05:44:19 pgoyette Exp $"); | 33 | __KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.212 2016/12/14 15:46:57 hannken Exp $"); | |
34 | 34 | |||
35 | #include "opt_sysv.h" | 35 | #include "opt_sysv.h" | |
36 | #include "opt_compat_netbsd.h" | 36 | #include "opt_compat_netbsd.h" | |
37 | #include "opt_modular.h" | 37 | #include "opt_modular.h" | |
38 | #include "pty.h" | 38 | #include "pty.h" | |
39 | 39 | |||
40 | #include <sys/types.h> | 40 | #include <sys/types.h> | |
41 | #include <sys/param.h> | 41 | #include <sys/param.h> | |
42 | #include <sys/sysctl.h> | 42 | #include <sys/sysctl.h> | |
43 | #include <sys/cpu.h> | 43 | #include <sys/cpu.h> | |
44 | #include <sys/errno.h> | 44 | #include <sys/errno.h> | |
45 | #include <sys/systm.h> | 45 | #include <sys/systm.h> | |
46 | #include <sys/kernel.h> | 46 | #include <sys/kernel.h> | |
47 | #include <sys/unistd.h> | 47 | #include <sys/unistd.h> | |
48 | #include <sys/disklabel.h> | 48 | #include <sys/disklabel.h> | |
49 | #include <sys/cprng.h> | 49 | #include <sys/cprng.h> | |
50 | #include <sys/vnode.h> | 50 | #include <sys/vnode_impl.h> /* For vfs_drainvnodes(). */ | |
51 | #include <sys/mount.h> | 51 | #include <sys/mount.h> | |
52 | #include <sys/namei.h> | 52 | #include <sys/namei.h> | |
53 | #include <dev/cons.h> | 53 | #include <dev/cons.h> | |
54 | #include <sys/socketvar.h> | 54 | #include <sys/socketvar.h> | |
55 | #include <sys/file.h> | 55 | #include <sys/file.h> | |
56 | #include <sys/filedesc.h> | 56 | #include <sys/filedesc.h> | |
57 | #include <sys/tty.h> | 57 | #include <sys/tty.h> | |
58 | #include <sys/kmem.h> | 58 | #include <sys/kmem.h> | |
59 | #include <sys/reboot.h> | 59 | #include <sys/reboot.h> | |
60 | #include <sys/resource.h> | 60 | #include <sys/resource.h> | |
61 | #include <sys/resourcevar.h> | 61 | #include <sys/resourcevar.h> | |
62 | #include <sys/exec.h> | 62 | #include <sys/exec.h> | |
63 | #include <sys/conf.h> | 63 | #include <sys/conf.h> | |
@@ -746,27 +746,27 @@ sysctl_kern_maxvnodes(SYSCTLFN_ARGS) | @@ -746,27 +746,27 @@ sysctl_kern_maxvnodes(SYSCTLFN_ARGS) | |||
746 | * to be positive | 746 | * to be positive | |
747 | */ | 747 | */ | |
748 | if (new_vnodes <= 0) | 748 | if (new_vnodes <= 0) | |
749 | return (EINVAL); | 749 | return (EINVAL); | |
750 | 750 | |||
751 | /* Limits: 75% of kmem and physical memory. */ | 751 | /* Limits: 75% of kmem and physical memory. */ | |
752 | new_max = calc_cache_size(vmem_size(kmem_arena, VMEM_FREE|VMEM_ALLOC), | 752 | new_max = calc_cache_size(vmem_size(kmem_arena, VMEM_FREE|VMEM_ALLOC), | |
753 | 75, 75) / VNODE_COST; | 753 | 75, 75) / VNODE_COST; | |
754 | if (new_vnodes > new_max) | 754 | if (new_vnodes > new_max) | |
755 | new_vnodes = new_max; | 755 | new_vnodes = new_max; | |
756 | 756 | |||
757 | old_vnodes = desiredvnodes; | 757 | old_vnodes = desiredvnodes; | |
758 | desiredvnodes = new_vnodes; | 758 | desiredvnodes = new_vnodes; | |
759 | error = vfs_drainvnodes(new_vnodes); | 759 | error = vfs_drainvnodes(); | |
760 | if (error) { | 760 | if (error) { | |
761 | desiredvnodes = old_vnodes; | 761 | desiredvnodes = old_vnodes; | |
762 | return (error); | 762 | return (error); | |
763 | } | 763 | } | |
764 | vfs_reinit(); | 764 | vfs_reinit(); | |
765 | nchreinit(); | 765 | nchreinit(); | |
766 | 766 | |||
767 | return (0); | 767 | return (0); | |
768 | } | 768 | } | |
769 | 769 | |||
770 | /* | 770 | /* | |
771 | * sysctl helper routine for kern.messages. | 771 | * sysctl helper routine for kern.messages. | |
772 | * Alters boothowto to display kernel messages in increasing verbosity | 772 | * Alters boothowto to display kernel messages in increasing verbosity |
--- src/sys/kern/vfs_mount.c 2016/11/03 11:03:31 1.41
+++ src/sys/kern/vfs_mount.c 2016/12/14 15:46:57 1.42
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: vfs_mount.c,v 1.41 2016/11/03 11:03:31 hannken Exp $ */ | 1 | /* $NetBSD: vfs_mount.c,v 1.42 2016/12/14 15:46:57 hannken Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1997-2011 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1997-2011 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | 8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | |
9 | * NASA Ames Research Center, by Charles M. Hannum, and by Andrew Doran. | 9 | * NASA Ames Research Center, by Charles M. Hannum, and by Andrew Doran. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -57,27 +57,27 @@ | @@ -57,27 +57,27 @@ | |||
57 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 57 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
58 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 58 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
59 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 59 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
60 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 60 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
61 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 61 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
62 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 62 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
63 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 63 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
64 | * SUCH DAMAGE. | 64 | * SUCH DAMAGE. | |
65 | * | 65 | * | |
66 | * @(#)vfs_subr.c 8.13 (Berkeley) 4/18/94 | 66 | * @(#)vfs_subr.c 8.13 (Berkeley) 4/18/94 | |
67 | */ | 67 | */ | |
68 | 68 | |||
69 | #include <sys/cdefs.h> | 69 | #include <sys/cdefs.h> | |
70 | __KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.41 2016/11/03 11:03:31 hannken Exp $"); | 70 | __KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.42 2016/12/14 15:46:57 hannken Exp $"); | |
71 | 71 | |||
72 | #include <sys/param.h> | 72 | #include <sys/param.h> | |
73 | #include <sys/kernel.h> | 73 | #include <sys/kernel.h> | |
74 | 74 | |||
75 | #include <sys/atomic.h> | 75 | #include <sys/atomic.h> | |
76 | #include <sys/buf.h> | 76 | #include <sys/buf.h> | |
77 | #include <sys/conf.h> | 77 | #include <sys/conf.h> | |
78 | #include <sys/fcntl.h> | 78 | #include <sys/fcntl.h> | |
79 | #include <sys/filedesc.h> | 79 | #include <sys/filedesc.h> | |
80 | #include <sys/device.h> | 80 | #include <sys/device.h> | |
81 | #include <sys/kauth.h> | 81 | #include <sys/kauth.h> | |
82 | #include <sys/kmem.h> | 82 | #include <sys/kmem.h> | |
83 | #include <sys/module.h> | 83 | #include <sys/module.h> | |
@@ -499,28 +499,28 @@ vflushnext(struct vnode_iterator *marker | @@ -499,28 +499,28 @@ vflushnext(struct vnode_iterator *marker | |||
499 | } | 499 | } | |
500 | return vfs_vnode_iterator_next(marker, vflush_selector, ctx); | 500 | return vfs_vnode_iterator_next(marker, vflush_selector, ctx); | |
501 | } | 501 | } | |
502 | 502 | |||
503 | 503 | |||
504 | int | 504 | int | |
505 | vflush(struct mount *mp, vnode_t *skipvp, int flags) | 505 | vflush(struct mount *mp, vnode_t *skipvp, int flags) | |
506 | { | 506 | { | |
507 | vnode_t *vp; | 507 | vnode_t *vp; | |
508 | struct vnode_iterator *marker; | 508 | struct vnode_iterator *marker; | |
509 | int error, busy = 0, when = 0; | 509 | int error, busy = 0, when = 0; | |
510 | struct vflush_ctx ctx; | 510 | struct vflush_ctx ctx; | |
511 | 511 | |||
512 | /* First, flush out any vnode references from vrele_list. */ | 512 | /* First, flush out any vnode references from deferred vrele list. */ | |
513 | vrele_flush(); | 513 | vfs_drainvnodes(); | |
514 | 514 | |||
515 | vfs_vnode_iterator_init(mp, &marker); | 515 | vfs_vnode_iterator_init(mp, &marker); | |
516 | 516 | |||
517 | ctx.skipvp = skipvp; | 517 | ctx.skipvp = skipvp; | |
518 | ctx.flags = flags; | 518 | ctx.flags = flags; | |
519 | while ((vp = vflushnext(marker, &ctx, &when)) != NULL) { | 519 | while ((vp = vflushnext(marker, &ctx, &when)) != NULL) { | |
520 | /* | 520 | /* | |
521 | * First try to recycle the vnode. | 521 | * First try to recycle the vnode. | |
522 | */ | 522 | */ | |
523 | if (vrecycle(vp)) | 523 | if (vrecycle(vp)) | |
524 | continue; | 524 | continue; | |
525 | /* | 525 | /* | |
526 | * If FORCECLOSE is set, forcibly close the vnode. | 526 | * If FORCECLOSE is set, forcibly close the vnode. |
--- src/sys/kern/vfs_vnode.c 2016/12/01 14:49:03 1.60
+++ src/sys/kern/vfs_vnode.c 2016/12/14 15:46:57 1.61
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: vfs_vnode.c,v 1.60 2016/12/01 14:49:03 hannken Exp $ */ | 1 | /* $NetBSD: vfs_vnode.c,v 1.61 2016/12/14 15:46:57 hannken Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1997-2011 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1997-2011 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | 8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | |
9 | * NASA Ames Research Center, by Charles M. Hannum, and by Andrew Doran. | 9 | * NASA Ames Research Center, by Charles M. Hannum, and by Andrew Doran. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -146,27 +146,27 @@ | @@ -146,27 +146,27 @@ | |||
146 | * Note on v_usecount and its locking | 146 | * Note on v_usecount and its locking | |
147 | * | 147 | * | |
148 | * At nearly all points it is known that v_usecount could be zero, | 148 | * At nearly all points it is known that v_usecount could be zero, | |
149 | * the vnode_t::v_interlock will be held. To change v_usecount away | 149 | * the vnode_t::v_interlock will be held. To change v_usecount away | |
150 | * from zero, the interlock must be held. To change from a non-zero | 150 | * from zero, the interlock must be held. To change from a non-zero | |
151 | * value to zero, again the interlock must be held. | 151 | * value to zero, again the interlock must be held. | |
152 | * | 152 | * | |
153 | * Changing the usecount from a non-zero value to a non-zero value can | 153 | * Changing the usecount from a non-zero value to a non-zero value can | |
154 | * safely be done using atomic operations, without the interlock held. | 154 | * safely be done using atomic operations, without the interlock held. | |
155 | * | 155 | * | |
156 | */ | 156 | */ | |
157 | 157 | |||
158 | #include <sys/cdefs.h> | 158 | #include <sys/cdefs.h> | |
159 | __KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.60 2016/12/01 14:49:03 hannken Exp $"); | 159 | __KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.61 2016/12/14 15:46:57 hannken Exp $"); | |
160 | 160 | |||
161 | #include <sys/param.h> | 161 | #include <sys/param.h> | |
162 | #include <sys/kernel.h> | 162 | #include <sys/kernel.h> | |
163 | 163 | |||
164 | #include <sys/atomic.h> | 164 | #include <sys/atomic.h> | |
165 | #include <sys/buf.h> | 165 | #include <sys/buf.h> | |
166 | #include <sys/conf.h> | 166 | #include <sys/conf.h> | |
167 | #include <sys/device.h> | 167 | #include <sys/device.h> | |
168 | #include <sys/hash.h> | 168 | #include <sys/hash.h> | |
169 | #include <sys/kauth.h> | 169 | #include <sys/kauth.h> | |
170 | #include <sys/kmem.h> | 170 | #include <sys/kmem.h> | |
171 | #include <sys/kthread.h> | 171 | #include <sys/kthread.h> | |
172 | #include <sys/module.h> | 172 | #include <sys/module.h> | |
@@ -198,26 +198,27 @@ static vnodelst_t vnode_hold_list __cac | @@ -198,26 +198,27 @@ static vnodelst_t vnode_hold_list __cac | |||
198 | static kcondvar_t vdrain_cv __cacheline_aligned; | 198 | static kcondvar_t vdrain_cv __cacheline_aligned; | |
199 | 199 | |||
200 | static vnodelst_t vrele_list __cacheline_aligned; | 200 | static vnodelst_t vrele_list __cacheline_aligned; | |
201 | static kmutex_t vrele_lock __cacheline_aligned; | 201 | static kmutex_t vrele_lock __cacheline_aligned; | |
202 | static kcondvar_t vrele_cv __cacheline_aligned; | 202 | static kcondvar_t vrele_cv __cacheline_aligned; | |
203 | static lwp_t * vrele_lwp __cacheline_aligned; | 203 | static lwp_t * vrele_lwp __cacheline_aligned; | |
204 | static int vrele_pending __cacheline_aligned; | 204 | static int vrele_pending __cacheline_aligned; | |
205 | static int vrele_gen __cacheline_aligned; | 205 | static int vrele_gen __cacheline_aligned; | |
206 | 206 | |||
207 | SLIST_HEAD(hashhead, vnode_impl); | 207 | SLIST_HEAD(hashhead, vnode_impl); | |
208 | static struct { | 208 | static struct { | |
209 | kmutex_t lock; | 209 | kmutex_t lock; | |
210 | kcondvar_t cv; | 210 | kcondvar_t cv; | |
211 | u_int hashsize; | |||
211 | u_long hashmask; | 212 | u_long hashmask; | |
212 | struct hashhead *hashtab; | 213 | struct hashhead *hashtab; | |
213 | pool_cache_t pool; | 214 | pool_cache_t pool; | |
214 | } vcache __cacheline_aligned; | 215 | } vcache __cacheline_aligned; | |
215 | 216 | |||
216 | static int cleanvnode(void); | 217 | static int cleanvnode(void); | |
217 | static vnode_impl_t *vcache_alloc(void); | 218 | static vnode_impl_t *vcache_alloc(void); | |
218 | static void vcache_free(vnode_impl_t *); | 219 | static void vcache_free(vnode_impl_t *); | |
219 | static void vcache_init(void); | 220 | static void vcache_init(void); | |
220 | static void vcache_reinit(void); | 221 | static void vcache_reinit(void); | |
221 | static void vcache_reclaim(vnode_t *); | 222 | static void vcache_reclaim(vnode_t *); | |
222 | static void vrelel(vnode_t *, int); | 223 | static void vrelel(vnode_t *, int); | |
223 | static void vdrain_thread(void *); | 224 | static void vdrain_thread(void *); | |
@@ -847,40 +848,26 @@ vrele_thread(void *cookie) | @@ -847,40 +848,26 @@ vrele_thread(void *cookie) | |||
847 | mutex_exit(&vrele_lock); | 848 | mutex_exit(&vrele_lock); | |
848 | 849 | |||
849 | /* | 850 | /* | |
850 | * If not the last reference, then ignore the vnode | 851 | * If not the last reference, then ignore the vnode | |
851 | * and look for more work. | 852 | * and look for more work. | |
852 | */ | 853 | */ | |
853 | mutex_enter(vp->v_interlock); | 854 | mutex_enter(vp->v_interlock); | |
854 | vrelel(vp, 0); | 855 | vrelel(vp, 0); | |
855 | fstrans_done(mp); | 856 | fstrans_done(mp); | |
856 | mutex_enter(&vrele_lock); | 857 | mutex_enter(&vrele_lock); | |
857 | } | 858 | } | |
858 | } | 859 | } | |
859 | 860 | |||
860 | void | |||
861 | vrele_flush(void) | |||
862 | { | |||
863 | int gen; | |||
864 | ||||
865 | mutex_enter(&vrele_lock); | |||
866 | gen = vrele_gen; | |||
867 | while (vrele_pending && gen == vrele_gen) { | |||
868 | cv_broadcast(&vrele_cv); | |||
869 | cv_wait(&vrele_cv, &vrele_lock); | |||
870 | } | |||
871 | mutex_exit(&vrele_lock); | |||
872 | } | |||
873 | ||||
874 | /* | 861 | /* | |
875 | * Vnode reference, where a reference is already held by some other | 862 | * Vnode reference, where a reference is already held by some other | |
876 | * object (for example, a file structure). | 863 | * object (for example, a file structure). | |
877 | */ | 864 | */ | |
878 | void | 865 | void | |
879 | vref(vnode_t *vp) | 866 | vref(vnode_t *vp) | |
880 | { | 867 | { | |
881 | 868 | |||
882 | KASSERT(vp->v_usecount != 0); | 869 | KASSERT(vp->v_usecount != 0); | |
883 | 870 | |||
884 | atomic_inc_uint(&vp->v_usecount); | 871 | atomic_inc_uint(&vp->v_usecount); | |
885 | } | 872 | } | |
886 | 873 | |||
@@ -1030,43 +1017,45 @@ vcache_hash(const struct vcache_key *key | @@ -1030,43 +1017,45 @@ vcache_hash(const struct vcache_key *key | |||
1030 | hash = hash32_buf(key->vk_key, key->vk_key_len, hash); | 1017 | hash = hash32_buf(key->vk_key, key->vk_key_len, hash); | |
1031 | return hash; | 1018 | return hash; | |
1032 | } | 1019 | } | |
1033 | 1020 | |||
1034 | static void | 1021 | static void | |
1035 | vcache_init(void) | 1022 | vcache_init(void) | |
1036 | { | 1023 | { | |
1037 | 1024 | |||
1038 | vcache.pool = pool_cache_init(sizeof(vnode_impl_t), 0, 0, 0, | 1025 | vcache.pool = pool_cache_init(sizeof(vnode_impl_t), 0, 0, 0, | |
1039 | "vcachepl", NULL, IPL_NONE, NULL, NULL, NULL); | 1026 | "vcachepl", NULL, IPL_NONE, NULL, NULL, NULL); | |
1040 | KASSERT(vcache.pool != NULL); | 1027 | KASSERT(vcache.pool != NULL); | |
1041 | mutex_init(&vcache.lock, MUTEX_DEFAULT, IPL_NONE); | 1028 | mutex_init(&vcache.lock, MUTEX_DEFAULT, IPL_NONE); | |
1042 | cv_init(&vcache.cv, "vcache"); | 1029 | cv_init(&vcache.cv, "vcache"); | |
1030 | vcache.hashsize = desiredvnodes; | |||
1043 | vcache.hashtab = hashinit(desiredvnodes, HASH_SLIST, true, | 1031 | vcache.hashtab = hashinit(desiredvnodes, HASH_SLIST, true, | |
1044 | &vcache.hashmask); | 1032 | &vcache.hashmask); | |
1045 | } | 1033 | } | |
1046 | 1034 | |||
1047 | static void | 1035 | static void | |
1048 | vcache_reinit(void) | 1036 | vcache_reinit(void) | |
1049 | { | 1037 | { | |
1050 | int i; | 1038 | int i; | |
1051 | uint32_t hash; | 1039 | uint32_t hash; | |
1052 | u_long oldmask, newmask; | 1040 | u_long oldmask, newmask; | |
1053 | struct hashhead *oldtab, *newtab; | 1041 | struct hashhead *oldtab, *newtab; | |
1054 | vnode_impl_t *node; | 1042 | vnode_impl_t *node; | |
1055 | 1043 | |||
1056 | newtab = hashinit(desiredvnodes, HASH_SLIST, true, &newmask); | 1044 | newtab = hashinit(desiredvnodes, HASH_SLIST, true, &newmask); | |
1057 | mutex_enter(&vcache.lock); | 1045 | mutex_enter(&vcache.lock); | |
1058 | oldtab = vcache.hashtab; | 1046 | oldtab = vcache.hashtab; | |
1059 | oldmask = vcache.hashmask; | 1047 | oldmask = vcache.hashmask; | |
1048 | vcache.hashsize = desiredvnodes; | |||
1060 | vcache.hashtab = newtab; | 1049 | vcache.hashtab = newtab; | |
1061 | vcache.hashmask = newmask; | 1050 | vcache.hashmask = newmask; | |
1062 | for (i = 0; i <= oldmask; i++) { | 1051 | for (i = 0; i <= oldmask; i++) { | |
1063 | while ((node = SLIST_FIRST(&oldtab[i])) != NULL) { | 1052 | while ((node = SLIST_FIRST(&oldtab[i])) != NULL) { | |
1064 | SLIST_REMOVE(&oldtab[i], node, vnode_impl, vi_hash); | 1053 | SLIST_REMOVE(&oldtab[i], node, vnode_impl, vi_hash); | |
1065 | hash = vcache_hash(&node->vi_key); | 1054 | hash = vcache_hash(&node->vi_key); | |
1066 | SLIST_INSERT_HEAD(&newtab[hash & vcache.hashmask], | 1055 | SLIST_INSERT_HEAD(&newtab[hash & vcache.hashmask], | |
1067 | node, vi_hash); | 1056 | node, vi_hash); | |
1068 | } | 1057 | } | |
1069 | } | 1058 | } | |
1070 | mutex_exit(&vcache.lock); | 1059 | mutex_exit(&vcache.lock); | |
1071 | hashdone(oldtab, HASH_SLIST, oldmask); | 1060 | hashdone(oldtab, HASH_SLIST, oldmask); | |
1072 | } | 1061 | } | |
@@ -1591,42 +1580,51 @@ vdead_check(struct vnode *vp, int flags) | @@ -1591,42 +1580,51 @@ vdead_check(struct vnode *vp, int flags) | |||
1591 | VSTATE_WAIT_STABLE(vp); | 1580 | VSTATE_WAIT_STABLE(vp); | |
1592 | 1581 | |||
1593 | if (VSTATE_GET(vp) == VS_RECLAIMING) { | 1582 | if (VSTATE_GET(vp) == VS_RECLAIMING) { | |
1594 | KASSERT(ISSET(flags, VDEAD_NOWAIT)); | 1583 | KASSERT(ISSET(flags, VDEAD_NOWAIT)); | |
1595 | return EBUSY; | 1584 | return EBUSY; | |
1596 | } else if (VSTATE_GET(vp) == VS_RECLAIMED) { | 1585 | } else if (VSTATE_GET(vp) == VS_RECLAIMED) { | |
1597 | return ENOENT; | 1586 | return ENOENT; | |
1598 | } | 1587 | } | |
1599 | 1588 | |||
1600 | return 0; | 1589 | return 0; | |
1601 | } | 1590 | } | |
1602 | 1591 | |||
1603 | int | 1592 | int | |
1604 | vfs_drainvnodes(long target) | 1593 | vfs_drainvnodes(void) | |
1605 | { | 1594 | { | |
1606 | int error; | 1595 | int error, gen; | |
1596 | ||||
1597 | mutex_enter(&vrele_lock); | |||
1598 | gen = vrele_gen; | |||
1599 | while (vrele_pending && gen == vrele_gen) { | |||
1600 | cv_broadcast(&vrele_cv); | |||
1601 | cv_wait(&vrele_cv, &vrele_lock); | |||
1602 | } | |||
1603 | mutex_exit(&vrele_lock); | |||
1607 | 1604 | |||
1608 | mutex_enter(&vnode_free_list_lock); | 1605 | mutex_enter(&vnode_free_list_lock); | |
1609 | 1606 | |||
1610 | while (numvnodes > target) { | 1607 | while (numvnodes > desiredvnodes) { | |
1611 | error = cleanvnode(); | 1608 | error = cleanvnode(); | |
1612 | if (error != 0) | 1609 | if (error != 0) | |
1613 | return error; | 1610 | return error; | |
1614 | mutex_enter(&vnode_free_list_lock); | 1611 | mutex_enter(&vnode_free_list_lock); | |
1615 | } | 1612 | } | |
1616 | 1613 | |||
1617 | mutex_exit(&vnode_free_list_lock); | 1614 | mutex_exit(&vnode_free_list_lock); | |
1618 | 1615 | |||
1619 | vcache_reinit(); | 1616 | if (vcache.hashsize != desiredvnodes) | |
1617 | vcache_reinit(); | |||
1620 | 1618 | |||
1621 | return 0; | 1619 | return 0; | |
1622 | } | 1620 | } | |
1623 | 1621 | |||
1624 | void | 1622 | void | |
1625 | vnpanic(vnode_t *vp, const char *fmt, ...) | 1623 | vnpanic(vnode_t *vp, const char *fmt, ...) | |
1626 | { | 1624 | { | |
1627 | va_list ap; | 1625 | va_list ap; | |
1628 | 1626 | |||
1629 | #ifdef DIAGNOSTIC | 1627 | #ifdef DIAGNOSTIC | |
1630 | vprint(NULL, vp); | 1628 | vprint(NULL, vp); | |
1631 | #endif | 1629 | #endif | |
1632 | va_start(ap, fmt); | 1630 | va_start(ap, fmt); |
--- src/sys/sys/vnode.h 2016/11/03 11:03:31 1.265
+++ src/sys/sys/vnode.h 2016/12/14 15:46:57 1.266
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: vnode.h,v 1.265 2016/11/03 11:03:31 hannken Exp $ */ | 1 | /* $NetBSD: vnode.h,v 1.266 2016/12/14 15:46:57 hannken Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -520,27 +520,26 @@ int vaccess(enum vtype, mode_t, uid_t, g | @@ -520,27 +520,26 @@ int vaccess(enum vtype, mode_t, uid_t, g | |||
520 | void vattr_null(struct vattr *); | 520 | void vattr_null(struct vattr *); | |
521 | void vdevgone(int, int, int, enum vtype); | 521 | void vdevgone(int, int, int, enum vtype); | |
522 | int vfinddev(dev_t, enum vtype, struct vnode **); | 522 | int vfinddev(dev_t, enum vtype, struct vnode **); | |
523 | int vflush(struct mount *, struct vnode *, int); | 523 | int vflush(struct mount *, struct vnode *, int); | |
524 | int vflushbuf(struct vnode *, int); | 524 | int vflushbuf(struct vnode *, int); | |
525 | int vget(struct vnode *, int, bool); | 525 | int vget(struct vnode *, int, bool); | |
526 | void vgone(struct vnode *); | 526 | void vgone(struct vnode *); | |
527 | int vinvalbuf(struct vnode *, int, kauth_cred_t, struct lwp *, bool, int); | 527 | int vinvalbuf(struct vnode *, int, kauth_cred_t, struct lwp *, bool, int); | |
528 | void vprint(const char *, struct vnode *); | 528 | void vprint(const char *, struct vnode *); | |
529 | void vput(struct vnode *); | 529 | void vput(struct vnode *); | |
530 | bool vrecycle(struct vnode *); | 530 | bool vrecycle(struct vnode *); | |
531 | void vrele(struct vnode *); | 531 | void vrele(struct vnode *); | |
532 | void vrele_async(struct vnode *); | 532 | void vrele_async(struct vnode *); | |
533 | void vrele_flush(void); | |||
534 | int vtruncbuf(struct vnode *, daddr_t, bool, int); | 533 | int vtruncbuf(struct vnode *, daddr_t, bool, int); | |
535 | void vwakeup(struct buf *); | 534 | void vwakeup(struct buf *); | |
536 | int vdead_check(struct vnode *, int); | 535 | int vdead_check(struct vnode *, int); | |
537 | void vrevoke(struct vnode *); | 536 | void vrevoke(struct vnode *); | |
538 | void vremfree(struct vnode *); | 537 | void vremfree(struct vnode *); | |
539 | int vcache_get(struct mount *, const void *, size_t, struct vnode **); | 538 | int vcache_get(struct mount *, const void *, size_t, struct vnode **); | |
540 | int vcache_new(struct mount *, struct vnode *, | 539 | int vcache_new(struct mount *, struct vnode *, | |
541 | struct vattr *, kauth_cred_t, struct vnode **); | 540 | struct vattr *, kauth_cred_t, struct vnode **); | |
542 | int vcache_rekey_enter(struct mount *, struct vnode *, | 541 | int vcache_rekey_enter(struct mount *, struct vnode *, | |
543 | const void *, size_t, const void *, size_t); | 542 | const void *, size_t, const void *, size_t); | |
544 | void vcache_rekey_exit(struct mount *, struct vnode *, | 543 | void vcache_rekey_exit(struct mount *, struct vnode *, | |
545 | const void *, size_t, const void *, size_t); | 544 | const void *, size_t, const void *, size_t); | |
546 | 545 | |||
@@ -571,25 +570,24 @@ int vn_fifo_bypass(void *); | @@ -571,25 +570,24 @@ int vn_fifo_bypass(void *); | |||
571 | /* initialise global vnode management */ | 570 | /* initialise global vnode management */ | |
572 | void vntblinit(void); | 571 | void vntblinit(void); | |
573 | 572 | |||
574 | /* misc stuff */ | 573 | /* misc stuff */ | |
575 | void sched_sync(void *); | 574 | void sched_sync(void *); | |
576 | void vn_syncer_add_to_worklist(struct vnode *, int); | 575 | void vn_syncer_add_to_worklist(struct vnode *, int); | |
577 | void vn_syncer_remove_from_worklist(struct vnode *); | 576 | void vn_syncer_remove_from_worklist(struct vnode *); | |
578 | int dorevoke(struct vnode *, kauth_cred_t); | 577 | int dorevoke(struct vnode *, kauth_cred_t); | |
579 | int rawdev_mounted(struct vnode *, struct vnode **); | 578 | int rawdev_mounted(struct vnode *, struct vnode **); | |
580 | uint8_t vtype2dt(enum vtype); | 579 | uint8_t vtype2dt(enum vtype); | |
581 | 580 | |||
582 | /* see vfssubr(9) */ | 581 | /* see vfssubr(9) */ | |
583 | void vfs_getnewfsid(struct mount *); | 582 | void vfs_getnewfsid(struct mount *); | |
584 | int vfs_drainvnodes(long); | |||
585 | void vfs_timestamp(struct timespec *); | 583 | void vfs_timestamp(struct timespec *); | |
586 | #if defined(DDB) || defined(DEBUGPRINT) | 584 | #if defined(DDB) || defined(DEBUGPRINT) | |
587 | void vfs_vnode_print(struct vnode *, int, void (*)(const char *, ...) | 585 | void vfs_vnode_print(struct vnode *, int, void (*)(const char *, ...) | |
588 | __printflike(1, 2)); | 586 | __printflike(1, 2)); | |
589 | void vfs_mount_print(struct mount *, int, void (*)(const char *, ...) | 587 | void vfs_mount_print(struct mount *, int, void (*)(const char *, ...) | |
590 | __printflike(1, 2)); | 588 | __printflike(1, 2)); | |
591 | #endif /* DDB */ | 589 | #endif /* DDB */ | |
592 | 590 | |||
593 | #endif /* _KERNEL */ | 591 | #endif /* _KERNEL */ | |
594 | 592 | |||
595 | #endif /* !_SYS_VNODE_H_ */ | 593 | #endif /* !_SYS_VNODE_H_ */ |
--- src/sys/sys/vnode_impl.h 2016/11/03 11:04:21 1.2
+++ src/sys/sys/vnode_impl.h 2016/12/14 15:46:57 1.3
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: vnode_impl.h,v 1.2 2016/11/03 11:04:21 hannken Exp $ */ | 1 | /* $NetBSD: vnode_impl.h,v 1.3 2016/12/14 15:46:57 hannken Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2016 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2016 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by | 8 | * by | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -57,15 +57,16 @@ typedef struct vnode_impl vnode_impl_t; | @@ -57,15 +57,16 @@ typedef struct vnode_impl vnode_impl_t; | |||
57 | 57 | |||
58 | #define VIMPL_TO_VNODE(node) ((vnode_t *)(node)) | 58 | #define VIMPL_TO_VNODE(node) ((vnode_t *)(node)) | |
59 | #define VNODE_TO_VIMPL(vp) ((vnode_impl_t *)(vp)) | 59 | #define VNODE_TO_VIMPL(vp) ((vnode_impl_t *)(vp)) | |
60 | 60 | |||
61 | /* | 61 | /* | |
62 | * Vnode manipulation functions. | 62 | * Vnode manipulation functions. | |
63 | */ | 63 | */ | |
64 | const char * | 64 | const char * | |
65 | vstate_name(enum vnode_state); | 65 | vstate_name(enum vnode_state); | |
66 | vnode_t * | 66 | vnode_t * | |
67 | vnalloc_marker(struct mount *); | 67 | vnalloc_marker(struct mount *); | |
68 | void vnfree_marker(vnode_t *); | 68 | void vnfree_marker(vnode_t *); | |
69 | bool vnis_marker(vnode_t *); | 69 | bool vnis_marker(vnode_t *); | |
70 | int vfs_drainvnodes(void); | |||
70 | 71 | |||
71 | #endif /* !_SYS_VNODE_IMPL_H_ */ | 72 | #endif /* !_SYS_VNODE_IMPL_H_ */ |