From 6288cbca766267e7a4a44cac6180151d6bed0c38 Mon Sep 17 00:00:00 2001 From: Bob Beck Date: Wed, 11 Aug 2010 14:35:35 +0000 Subject: Make the number of vnodes to correspond to the number of buffers in buffer cache - we grow them dynamically, but do not attempt to shrink them if the buffer cache shrinks after growing. Tested by very many for a long time. ok oga@ todd@ phessler@ tedu@ --- sys/kern/vfs_subr.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 61fc62d20b4..588e255d328 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_subr.c,v 1.187 2010/06/29 04:09:32 tedu Exp $ */ +/* $OpenBSD: vfs_subr.c,v 1.188 2010/08/11 14:35:34 beck Exp $ */ /* $NetBSD: vfs_subr.c,v 1.53 1996/04/22 01:39:13 christos Exp $ */ /* @@ -108,8 +108,10 @@ void vfs_free_addrlist(struct netexport *); void vputonfreelist(struct vnode *); int vflush_vnode(struct vnode *, void *); +extern struct bcachestats bcasts; int maxvnodes; + #ifdef DEBUG void printlockedvnodes(void); #endif @@ -136,7 +138,7 @@ void vntblinit(void) { /* buffer cache may need a vnode for each buffer */ - maxvnodes = desiredvnodes; + maxvnodes = 2 * desiredvnodes; pool_init(&vnode_pool, sizeof(struct vnode), 0, 0, 0, "vnodes", &pool_allocator_nointr); TAILQ_INIT(&vnode_hold_list); @@ -317,6 +319,13 @@ getnewvnode(enum vtagtype tag, struct mount *mp, int (**vops)(void *), struct vnode *vp; int s; + /* + * allow maxvnodes to increase if the buffer cache itself + * is big enough to justify it. (we don't shrink it ever) + */ + maxvnodes = maxvnodes < bcstats.numbufs ? bcstats.numbufs + : maxvnodes; + /* * We must choose whether to allocate a new vnode or recycle an * existing one. The criterion for allocating a new one is that @@ -333,7 +342,7 @@ getnewvnode(enum vtagtype tag, struct mount *mp, int (**vops)(void *), * referencing buffers. */ toggle ^= 1; - if (numvnodes > 2 * maxvnodes) + if (numvnodes / 2 > maxvnodes) toggle = 0; s = splbio(); @@ -757,7 +766,7 @@ vdrop(struct vnode *vp) { #ifdef DIAGNOSTIC if (vp->v_holdcnt == 0) - panic("vdrop: zero holdcnt"); + panic("vdrop: zero holdcnt"); #endif vp->v_holdcnt--; @@ -843,7 +852,7 @@ vflush_vnode(struct vnode *vp, void *arg) { vgonel(vp, p); return (0); } - + /* * If FORCECLOSE is set, forcibly close the vnode. * For block or character devices, revert to an -- cgit v1.2.3