Module Name: src Committed By: para Date: Mon Mar 18 13:36:23 UTC 2013
Modified Files: src/sys/kern: init_main.c init_sysctl.c vfs_bio.c src/sys/rump/librump/rumpkern: emul.c src/sys/sys: param.h systm.h Log Message: calculate vnode cache size based on the resource it gets allocated from this stops setting kern.maxvnodes to high so it exhausts available space in kmem http://mail-index.netbsd.org/tech-kern/2013/03/08/msg015095.html To generate a diff of this commit: cvs rdiff -u -r1.447 -r1.448 src/sys/kern/init_main.c cvs rdiff -u -r1.196 -r1.197 src/sys/kern/init_sysctl.c cvs rdiff -u -r1.242 -r1.243 src/sys/kern/vfs_bio.c cvs rdiff -u -r1.154 -r1.155 src/sys/rump/librump/rumpkern/emul.c cvs rdiff -u -r1.425 -r1.426 src/sys/sys/param.h cvs rdiff -u -r1.257 -r1.258 src/sys/sys/systm.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_main.c diff -u src/sys/kern/init_main.c:1.447 src/sys/kern/init_main.c:1.448 --- src/sys/kern/init_main.c:1.447 Thu Feb 21 01:39:55 2013 +++ src/sys/kern/init_main.c Mon Mar 18 13:36:21 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: init_main.c,v 1.447 2013/02/21 01:39:55 pgoyette Exp $ */ +/* $NetBSD: init_main.c,v 1.448 2013/03/18 13:36:21 para Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -97,7 +97,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.447 2013/02/21 01:39:55 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.448 2013/03/18 13:36:21 para Exp $"); #include "opt_ddb.h" #include "opt_ipsec.h" @@ -444,8 +444,8 @@ main(void) * 10% of memory for vnodes and associated data structures in the * assumed worst case. Do not provide fewer than NVNODE vnodes. */ - usevnodes = - calc_cache_size(kernel_map, 10, VNODE_VA_MAXPCT) / VNODE_COST; + usevnodes = calc_cache_size(vmem_size(kmem_arena, VMEM_FREE|VMEM_ALLOC), + 10, VNODE_KMEM_MAXPCT) / VNODE_COST; if (usevnodes > desiredvnodes) desiredvnodes = usevnodes; #endif @@ -1078,20 +1078,17 @@ start_init(void *arg) } /* - * calculate cache size (in bytes) from physmem and vm_map size. + * calculate cache size (in bytes) from physmem and vsize. */ vaddr_t -calc_cache_size(struct vm_map *map, int pct, int va_pct) +calc_cache_size(vsize_t vsize, int pct, int va_pct) { paddr_t t; /* XXX should consider competing cache if any */ /* XXX should consider submaps */ t = (uintmax_t)physmem * pct / 100 * PAGE_SIZE; - if (map != NULL) { - vsize_t vsize; - - vsize = vm_map_max(map) - vm_map_min(map); + if (vsize != 0) { vsize = (uintmax_t)vsize * va_pct / 100; if (t > vsize) { t = vsize; Index: src/sys/kern/init_sysctl.c diff -u src/sys/kern/init_sysctl.c:1.196 src/sys/kern/init_sysctl.c:1.197 --- src/sys/kern/init_sysctl.c:1.196 Thu Mar 7 18:02:54 2013 +++ src/sys/kern/init_sysctl.c Mon Mar 18 13:36:22 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: init_sysctl.c,v 1.196 2013/03/07 18:02:54 matt Exp $ */ +/* $NetBSD: init_sysctl.c,v 1.197 2013/03/18 13:36:22 para 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.196 2013/03/07 18:02:54 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.197 2013/03/18 13:36:22 para Exp $"); #include "opt_sysv.h" #include "opt_compat_netbsd.h" @@ -961,8 +961,9 @@ sysctl_kern_maxvnodes(SYSCTLFN_ARGS) if (new_vnodes <= 0) return (EINVAL); - /* Limits: 75% of KVA and physical memory. */ - new_max = calc_cache_size(kernel_map, 75, 75) / VNODE_COST; + /* Limits: 75% of kmem and physical memory. */ + new_max = calc_cache_size(vmem_size(kmem_arena, VMEM_FREE|VMEM_ALLOC), + 75, 75) / VNODE_COST; if (new_vnodes > new_max) new_vnodes = new_max; Index: src/sys/kern/vfs_bio.c diff -u src/sys/kern/vfs_bio.c:1.242 src/sys/kern/vfs_bio.c:1.243 --- src/sys/kern/vfs_bio.c:1.242 Sun Dec 30 09:19:24 2012 +++ src/sys/kern/vfs_bio.c Mon Mar 18 13:36:22 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_bio.c,v 1.242 2012/12/30 09:19:24 hannken Exp $ */ +/* $NetBSD: vfs_bio.c,v 1.243 2013/03/18 13:36:22 para Exp $ */ /*- * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -123,7 +123,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.242 2012/12/30 09:19:24 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.243 2013/03/18 13:36:22 para Exp $"); #include "opt_bufcache.h" @@ -396,6 +396,7 @@ u_long buf_memcalc(void) { u_long n; + vsize_t mapsz; /* * Determine the upper bound of memory to use for buffers. @@ -417,7 +418,8 @@ buf_memcalc(void) printf("forcing bufcache %d -> 95", bufcache); bufcache = 95; } - n = calc_cache_size(buf_map, bufcache, + mapsz = vm_map_max(buf_map) - vm_map_min(buf_map); + n = calc_cache_size(mapsz, bufcache, (buf_map != kernel_map) ? 100 : BUFCACHE_VA_MAXPCT) / PAGE_SIZE; } Index: src/sys/rump/librump/rumpkern/emul.c diff -u src/sys/rump/librump/rumpkern/emul.c:1.154 src/sys/rump/librump/rumpkern/emul.c:1.155 --- src/sys/rump/librump/rumpkern/emul.c:1.154 Thu Mar 7 19:07:05 2013 +++ src/sys/rump/librump/rumpkern/emul.c Mon Mar 18 13:36:23 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: emul.c,v 1.154 2013/03/07 19:07:05 pooka Exp $ */ +/* $NetBSD: emul.c,v 1.155 2013/03/18 13:36:23 para Exp $ */ /* * Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.154 2013/03/07 19:07:05 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.155 2013/03/18 13:36:23 para Exp $"); #include <sys/param.h> #include <sys/null.h> @@ -192,7 +192,7 @@ lwp_update_creds(struct lwp *l) } vaddr_t -calc_cache_size(struct vm_map *map, int pct, int va_pct) +calc_cache_size(vsize_t vasz, int pct, int va_pct) { paddr_t t; Index: src/sys/sys/param.h diff -u src/sys/sys/param.h:1.425 src/sys/sys/param.h:1.426 --- src/sys/sys/param.h:1.425 Wed Feb 13 14:03:49 2013 +++ src/sys/sys/param.h Mon Mar 18 13:36:23 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: param.h,v 1.425 2013/02/13 14:03:49 hannken Exp $ */ +/* $NetBSD: param.h,v 1.426 2013/03/18 13:36:23 para Exp $ */ /*- * Copyright (c) 1982, 1986, 1989, 1993 @@ -149,8 +149,8 @@ #define NVNODE (NPROC + NTEXT + 100) #define NVNODE_IMPLICIT #endif -#ifndef VNODE_VA_MAXPCT -#define VNODE_VA_MAXPCT 20 +#ifndef VNODE_KMEM_MAXPCT +#define VNODE_KMEM_MAXPCT 60 #endif #ifndef BUFCACHE_VA_MAXPCT #define BUFCACHE_VA_MAXPCT 20 Index: src/sys/sys/systm.h diff -u src/sys/sys/systm.h:1.257 src/sys/sys/systm.h:1.258 --- src/sys/sys/systm.h:1.257 Fri Aug 3 18:08:01 2012 +++ src/sys/sys/systm.h Mon Mar 18 13:36:23 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: systm.h,v 1.257 2012/08/03 18:08:01 matt Exp $ */ +/* $NetBSD: systm.h,v 1.258 2013/03/18 13:36:23 para Exp $ */ /*- * Copyright (c) 1982, 1988, 1991, 1993 @@ -62,7 +62,6 @@ struct tty; struct uio; struct vnode; struct vmspace; -struct vm_map; extern const char *panicstr; /* panic message */ extern int doing_shutdown; /* shutting down */ @@ -534,6 +533,6 @@ void assert_sleepable(void); #define ASSERT_SLEEPABLE() /* nothing */ #endif /* defined(DEBUG) */ -vaddr_t calc_cache_size(struct vm_map *, int, int); +vaddr_t calc_cache_size(vsize_t , int, int); #endif /* !_SYS_SYSTM_H_ */