diff options
author | Niels Provos <provos@cvs.openbsd.org> | 2001-12-05 01:57:16 +0000 |
---|---|---|
committer | Niels Provos <provos@cvs.openbsd.org> | 2001-12-05 01:57:16 +0000 |
commit | 7d4e405c93372a538ea996770c4b2713f9f060af (patch) | |
tree | 6cd29f566d8ce4e0b98c833eb388e60be4873329 /sys | |
parent | 0a184a866038ed50ac9395e288f697c8ad216309 (diff) |
make nkmempages dynamic based on memory. okay art@ from netbsd:
date: 2000/02/11 19:22:52; author: thorpej;
Add some very simple code to auto-size the kmem_map. We take the
amount of physical memory, divide it by 4, and then allow machine
dependent code to place upper and lower bounds on the size. Export
the computed value to userspace via the new "vm.nkmempages" sysctl.
NKMEMCLUSTERS is now deprecated and will generate an error if you
attempt to use it. The new option, should you choose to use it,
is called NKMEMPAGES, and two new options NKMEMPAGES_MIN and
NKMEMPAGES_MAX allow the user to configure the bounds in the kernel
config file.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/alpha/include/param.h | 13 | ||||
-rw-r--r-- | sys/arch/amiga/include/param.h | 10 | ||||
-rw-r--r-- | sys/arch/hp300/include/param.h | 12 | ||||
-rw-r--r-- | sys/arch/hppa/include/param.h | 10 | ||||
-rw-r--r-- | sys/arch/i386/include/param.h | 12 | ||||
-rw-r--r-- | sys/arch/mac68k/include/param.h | 12 | ||||
-rw-r--r-- | sys/arch/macppc/include/param.h | 10 | ||||
-rw-r--r-- | sys/arch/mvme88k/include/param.h | 12 | ||||
-rw-r--r-- | sys/arch/mvmeppc/include/param.h | 12 | ||||
-rw-r--r-- | sys/arch/powerpc/include/param.h | 2 | ||||
-rw-r--r-- | sys/arch/sparc/include/param.h | 10 | ||||
-rw-r--r-- | sys/arch/sparc64/include/param.h | 11 | ||||
-rw-r--r-- | sys/arch/sun3/include/param.h | 12 | ||||
-rw-r--r-- | sys/arch/vax/include/param.h | 13 | ||||
-rw-r--r-- | sys/kern/kern_malloc.c | 81 |
15 files changed, 150 insertions, 82 deletions
diff --git a/sys/arch/alpha/include/param.h b/sys/arch/alpha/include/param.h index 611d1dbcff7..d291e572cbb 100644 --- a/sys/arch/alpha/include/param.h +++ b/sys/arch/alpha/include/param.h @@ -1,4 +1,4 @@ -/* $OpenBSD: param.h,v 1.20 2001/05/05 20:56:31 art Exp $ */ +/* $OpenBSD: param.h,v 1.21 2001/12/05 01:57:14 provos Exp $ */ /* $NetBSD: param.h,v 1.30 2000/06/09 16:03:04 thorpej Exp $ */ /* @@ -122,12 +122,11 @@ #endif /* - * Size of kernel malloc arena in CLBYTES-sized logical pages - */ -#ifndef NKMEMCLUSTERS -#define NKMEMCLUSTERS (32768*1024/NBPG) -#endif - + * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized + * logical pages. + */ +#define NKMEMPAGES_MIN_DEFAULT ((8 * 1024 * 1024) >> PAGE_SHIFT) +#define NKMEMPAGES_MAX_DEFAULT ((128 * 1024 * 1024) >> PAGE_SHIFT) /* pages ("clicks") to disk blocks */ #define ctod(x) ((x) << (PGSHIFT - DEV_BSHIFT)) diff --git a/sys/arch/amiga/include/param.h b/sys/arch/amiga/include/param.h index 03b55fc5737..c7bb979d23a 100644 --- a/sys/arch/amiga/include/param.h +++ b/sys/arch/amiga/include/param.h @@ -1,4 +1,4 @@ -/* $OpenBSD: param.h,v 1.17 2001/11/30 21:00:57 miod Exp $ */ +/* $OpenBSD: param.h,v 1.18 2001/12/05 01:57:14 provos Exp $ */ /* $NetBSD: param.h,v 1.35 1997/07/10 08:22:36 veego Exp $ */ /* @@ -65,11 +65,11 @@ #define NPTEPG (NBPG/(sizeof (pt_entry_t))) /* - * Size of kernel malloc arena in logical pages + * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized + * logical pages. */ -#ifndef NKMEMCLUSTERS -#define NKMEMCLUSTERS (2048 * 1024 / PAGE_SIZE) -#endif +#define NKMEMPAGES_MIN_DEFAULT ((2 * 1024 * 1024) >> PAGE_SHIFT) +#define NKMEMPAGES_MAX_DEFAULT ((2 * 1024 * 1024) >> PAGE_SHIFT) #define MSGBUFSIZE 8192 diff --git a/sys/arch/hp300/include/param.h b/sys/arch/hp300/include/param.h index 4f5aca2782d..85b39cad6b0 100644 --- a/sys/arch/hp300/include/param.h +++ b/sys/arch/hp300/include/param.h @@ -1,4 +1,4 @@ -/* $OpenBSD: param.h,v 1.17 2001/11/30 20:58:18 miod Exp $ */ +/* $OpenBSD: param.h,v 1.18 2001/12/05 01:57:14 provos Exp $ */ /* $NetBSD: param.h,v 1.35 1997/07/10 08:22:38 veego Exp $ */ /* @@ -70,11 +70,11 @@ #define NPTEPG (NBPG/(sizeof (pt_entry_t))) /* - * Size of kernel malloc arena in logical pages - */ -#ifndef NKMEMCLUSTERS -# define NKMEMCLUSTERS (2048 * 1024 / PAGE_SIZE) -#endif + * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized + * logical pages. + */ +#define NKMEMPAGES_MIN_DEFAULT ((2 * 1024 * 1024) >> PAGE_SHIFT) +#define NKMEMPAGES_MAX_DEFAULT ((2 * 1024 * 1024) >> PAGE_SHIFT) #define MSGBUFSIZE 4096 diff --git a/sys/arch/hppa/include/param.h b/sys/arch/hppa/include/param.h index 69e14fec266..5b2802990cf 100644 --- a/sys/arch/hppa/include/param.h +++ b/sys/arch/hppa/include/param.h @@ -1,4 +1,4 @@ -/* $OpenBSD: param.h,v 1.13 2001/11/30 17:45:06 miod Exp $ */ +/* $OpenBSD: param.h,v 1.14 2001/12/05 01:57:14 provos Exp $ */ /* * Copyright (c) 1988-1994, The University of Utah and @@ -91,11 +91,11 @@ #endif /* - * Size of kernel malloc arena in logical pages + * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized + * logical pages. */ -#ifndef NKMEMCLUSTERS -#define NKMEMCLUSTERS (16 * 1024 * 1024 / PAGE_SIZE) -#endif +#define NKMEMPAGES_MIN_DEFAULT ((8 * 1024 * 1024) >> PAGE_SHIFT) +#define NKMEMPAGES_MAX_DEFAULT ((64 * 1024 * 1024) >> PAGE_SHIFT) /* pages ("clicks") (4096 bytes) to disk blocks */ #define ctod(x) ((x)<<(PGSHIFT-DEV_BSHIFT)) diff --git a/sys/arch/i386/include/param.h b/sys/arch/i386/include/param.h index c218be4b785..a3ce7f80302 100644 --- a/sys/arch/i386/include/param.h +++ b/sys/arch/i386/include/param.h @@ -1,4 +1,4 @@ -/* $OpenBSD: param.h,v 1.18 2001/07/18 10:47:04 art Exp $ */ +/* $OpenBSD: param.h,v 1.19 2001/12/05 01:57:14 provos Exp $ */ /* $NetBSD: param.h,v 1.29 1996/03/04 05:04:26 cgd Exp $ */ /*- @@ -112,11 +112,11 @@ #endif /* - * Size of kernel malloc arena in logical pages - */ -#ifndef NKMEMCLUSTERS -#define NKMEMCLUSTERS (16 * 1024 * 1024 / PAGE_SIZE) -#endif + * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized + * logical pages. + */ +#define NKMEMPAGES_MIN_DEFAULT ((8 * 1024 * 1024) >> PAGE_SHIFT) +#define NKMEMPAGES_MAX_DEFAULT ((128 * 1024 * 1024) >> PAGE_SHIFT) /* pages ("clicks") to disk blocks */ #define ctod(x) ((x) << (PGSHIFT - DEV_BSHIFT)) diff --git a/sys/arch/mac68k/include/param.h b/sys/arch/mac68k/include/param.h index 6be60f8d1b3..50f6fcfcd50 100644 --- a/sys/arch/mac68k/include/param.h +++ b/sys/arch/mac68k/include/param.h @@ -1,4 +1,4 @@ -/* $OpenBSD: param.h,v 1.14 2001/11/30 20:58:18 miod Exp $ */ +/* $OpenBSD: param.h,v 1.15 2001/12/05 01:57:15 provos Exp $ */ /* $NetBSD: param.h,v 1.28 1997/03/01 06:57:45 scottr Exp $ */ /* @@ -105,11 +105,11 @@ #define NPTEPG (NBPG/(sizeof (pt_entry_t))) /* - * Size of kernel malloc arena in logical pages - */ -#ifndef NKMEMCLUSTERS -#define NKMEMCLUSTERS (2048 * 1024 / PAGE_SIZE) -#endif + * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized + * logical pages. + */ +#define NKMEMPAGES_MIN_DEFAULT ((3 * 1024 * 1024) >> PAGE_SHIFT) +#define NKMEMPAGES_MAX_DEFAULT ((3 * 1024 * 1024) >> PAGE_SHIFT) #define MSGBUFSIZE 4096 diff --git a/sys/arch/macppc/include/param.h b/sys/arch/macppc/include/param.h index a046ab6f7f1..340f72c4b97 100644 --- a/sys/arch/macppc/include/param.h +++ b/sys/arch/macppc/include/param.h @@ -1,4 +1,4 @@ -/* $OpenBSD: param.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ +/* $OpenBSD: param.h,v 1.2 2001/12/05 01:57:15 provos Exp $ */ /* $NetBSD: param.h,v 1.1 1996/09/30 16:34:28 ws Exp $ */ /*- @@ -51,9 +51,9 @@ #define MSGBUFSIZE (NBPG*2) /* - * Size of kernel malloc arena in logical pages. + * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized + * logical pages. */ -#ifndef NKMEMCLUSTERS -#define NKMEMCLUSTERS (16 * 1024 * 1024 / PAGE_SIZE) -#endif +#define NKMEMPAGES_MIN_DEFAULT ((8 * 1024 * 1024) >> PAGE_SHIFT) +#define NKMEMPAGES_MAX_DEFAULT ((48 * 1024 * 1024) >> PAGE_SHIFT) diff --git a/sys/arch/mvme88k/include/param.h b/sys/arch/mvme88k/include/param.h index d1f7b0c4f7b..128d5301cf4 100644 --- a/sys/arch/mvme88k/include/param.h +++ b/sys/arch/mvme88k/include/param.h @@ -1,4 +1,4 @@ -/* $OpenBSD: param.h,v 1.22 2001/11/30 17:45:07 miod Exp $ */ +/* $OpenBSD: param.h,v 1.23 2001/12/05 01:57:15 provos Exp $ */ /* * Copyright (c) 1999 Steve Murphree, Jr. * Copyright (c) 1988 University of Utah. @@ -130,11 +130,11 @@ #endif /* - * Size of kernel malloc arena in logical pages - */ -#ifndef NKMEMCLUSTERS -#define NKMEMCLUSTERS (4096*1024/PAGE_SIZE) -#endif + * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized + * logical pages. + */ +#define NKMEMPAGES_MIN_DEFAULT ((4 * 1024 * 1024) >> PAGE_SHIFT) +#define NKMEMPAGES_MAX_DEFAULT ((4 * 1024 * 1024) >> PAGE_SHIFT) #define MSGBUFSIZE PAGE_SIZE diff --git a/sys/arch/mvmeppc/include/param.h b/sys/arch/mvmeppc/include/param.h index 1cab89fcd14..6505b73ddc8 100644 --- a/sys/arch/mvmeppc/include/param.h +++ b/sys/arch/mvmeppc/include/param.h @@ -1,4 +1,4 @@ -/* $OpenBSD: param.h,v 1.3 2001/09/02 19:40:24 miod Exp $ */ +/* $OpenBSD: param.h,v 1.4 2001/12/05 01:57:15 provos Exp $ */ /* $NetBSD: param.h,v 1.1 1996/09/30 16:34:28 ws Exp $ */ /*- @@ -51,9 +51,13 @@ #define MSGBUFSIZE (NBPG*2) /* - * Size of kernel malloc arena in logical pages. + * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized + * logical pages. */ -#ifndef NKMEMCLUSTERS -#define NKMEMCLUSTERS (16 * 1024 * 1024 / PAGE_SIZE) +#ifndef NKMEMPAGES_MIN_DEFAULT +#define NKMEMPAGES_MIN_DEFAULT ((8 * 1024 * 1024) >> PAGE_SHIFT) +#endif +#ifndef NKMEMPAGES_MAX_DEFAULT +#define NKMEMPAGES_MAX_DEFAULT ((64 * 1024 * 1024) >> PAGE_SHIFT) #endif diff --git a/sys/arch/powerpc/include/param.h b/sys/arch/powerpc/include/param.h index 9d4ce5045c4..3128717c74a 100644 --- a/sys/arch/powerpc/include/param.h +++ b/sys/arch/powerpc/include/param.h @@ -1,4 +1,4 @@ -/* $OpenBSD: param.h,v 1.18 2001/09/01 15:49:05 drahn Exp $ */ +/* $OpenBSD: param.h,v 1.19 2001/12/05 01:57:15 provos Exp $ */ /* $NetBSD: param.h,v 1.1 1996/09/30 16:34:28 ws Exp $ */ /*- diff --git a/sys/arch/sparc/include/param.h b/sys/arch/sparc/include/param.h index d743bb76d18..805f1bca2bb 100644 --- a/sys/arch/sparc/include/param.h +++ b/sys/arch/sparc/include/param.h @@ -1,4 +1,4 @@ -/* $OpenBSD: param.h,v 1.20 2001/07/18 10:47:05 art Exp $ */ +/* $OpenBSD: param.h,v 1.21 2001/12/05 01:57:15 provos Exp $ */ /* $NetBSD: param.h,v 1.29 1997/03/10 22:50:37 pk Exp $ */ /* @@ -127,11 +127,11 @@ extern int nbpg, pgofset, pgshift; #define MSGBUFSIZE 4096 /* cannot be changed without great pain */ /* - * Size of kernel malloc arena in logical pages. + * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized + * logical pages. */ -#ifndef NKMEMCLUSTERS -#define NKMEMCLUSTERS (6 * 1024 * 1024 / PAGE_SIZE) -#endif +#define NKMEMPAGES_MIN_DEFAULT ((6 * 1024 * 1024) >> PAGE_SHIFT) +#define NKMEMPAGES_MAX_DEFAULT ((6 * 1024 * 1024) >> PAGE_SHIFT) /* pages ("clicks") to disk blocks */ #define ctod(x) ((x) << (PGSHIFT - DEV_BSHIFT)) diff --git a/sys/arch/sparc64/include/param.h b/sys/arch/sparc64/include/param.h index 40d3e9e4c74..9f69ac797a4 100644 --- a/sys/arch/sparc64/include/param.h +++ b/sys/arch/sparc64/include/param.h @@ -1,4 +1,4 @@ -/* $OpenBSD: param.h,v 1.4 2001/09/11 03:50:46 jason Exp $ */ +/* $OpenBSD: param.h,v 1.5 2001/12/05 01:57:15 provos Exp $ */ /* $NetBSD: param.h,v 1.25 2001/05/30 12:28:51 mrg Exp $ */ /* @@ -213,9 +213,12 @@ extern int nbpg, pgofset, pgshift; #define MSGBUFSIZE NBPG -#ifndef NKMEMCLUSTERS -#define NKMEMCLUSTERS (16 * 1024 * 1024 / PAGE_SIZE) -#endif +/* + * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized + * logical pages. + */ +#define NKMEMPAGES_MIN_DEFAULT ((6 * 1024 * 1024) >> PAGE_SHIFT) +#define NKMEMPAGES_MAX_DEFAULT ((128 * 1024 * 1024) >> PAGE_SHIFT) /* pages ("clicks") to disk blocks */ #define ctod(x) ((x) << (PGSHIFT - DEV_BSHIFT)) diff --git a/sys/arch/sun3/include/param.h b/sys/arch/sun3/include/param.h index 1da485117d1..85c0f2231c0 100644 --- a/sys/arch/sun3/include/param.h +++ b/sys/arch/sun3/include/param.h @@ -1,4 +1,4 @@ -/* $OpenBSD: param.h,v 1.28 2001/11/30 20:59:12 miod Exp $ */ +/* $OpenBSD: param.h,v 1.29 2001/12/05 01:57:15 provos Exp $ */ /* $NetBSD: param.h,v 1.34 1996/03/04 05:04:40 cgd Exp $ */ /* @@ -79,11 +79,11 @@ #define MSGBUFSIZE (NBPG - MSGBUFOFF) /* - * Size of kernel malloc arena in logical pages - */ -#ifndef NKMEMCLUSTERS -#define NKMEMCLUSTERS (2048*1024/PAGE_SIZE) -#endif + * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized + * logical pages. + */ +#define NKMEMPAGES_MIN_DEFAULT ((2 * 1024 * 1024) >> PAGE_SHIFT) +#define NKMEMPAGES_MAX_DEFAULT ((2 * 1024 * 1024) >> PAGE_SHIFT) /* * spl functions; all are done in-line diff --git a/sys/arch/vax/include/param.h b/sys/arch/vax/include/param.h index 334a7611dcc..2cc57f257d8 100644 --- a/sys/arch/vax/include/param.h +++ b/sys/arch/vax/include/param.h @@ -1,4 +1,4 @@ -/* $OpenBSD: param.h,v 1.20 2001/07/06 02:07:44 provos Exp $ */ +/* $OpenBSD: param.h,v 1.21 2001/12/05 01:57:15 provos Exp $ */ /* $NetBSD: param.h,v 1.39 1999/10/22 21:14:34 ragge Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -125,12 +125,11 @@ #endif /* NMBCLUSTERS */ /* - * Size of kernel malloc arena in NBPG-sized logical pages - */ - -#ifndef NKMEMCLUSTERS -#define NKMEMCLUSTERS (4096*1024/NBPG) -#endif + * Minimum and maximum sizes of the kernel malloc arena in PAGE_SIZE-sized + * logical pages. + */ +#define NKMEMPAGES_MIN_DEFAULT ((4 * 1024 * 1024) >> PAGE_SHIFT) +#define NKMEMPAGES_MAX_DEFAULT ((4 * 1024 * 1024) >> PAGE_SHIFT) /* * Some macros for units conversion diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index c18f8067f51..60409bb69b5 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_malloc.c,v 1.42 2001/11/28 19:28:14 art Exp $ */ +/* $OpenBSD: kern_malloc.c,v 1.43 2001/12/05 01:57:15 provos Exp $ */ /* $NetBSD: kern_malloc.c,v 1.15.4.2 1996/06/13 17:10:56 cgd Exp $ */ /* @@ -49,7 +49,31 @@ static struct vm_map kmem_map_store; struct vm_map *kmem_map = NULL; -int nkmempages; +#ifdef NKMEMCLUSTERS +#error NKMEMCLUSTERS is obsolete; remove it from your kernel config file and use NKMEMPAGES instead or let the kernel auto-size +#endif + +/* + * Default number of pages in kmem_map. We attempt to calculate this + * at run-time, but allow it to be either patched or set in the kernel + * config file. + */ +#ifndef NKMEMPAGES +#define NKMEMPAGES 0 +#endif +int nkmempages = NKMEMPAGES; + +/* + * Defaults for lower- and upper-bounds for the kmem_map page count. + * Can be overridden by kernel config options. + */ +#ifndef NKMEMPAGES_MIN +#define NKMEMPAGES_MIN NKMEMPAGES_MIN_DEFAULT +#endif + +#ifndef NKMEMPAGES_MAX +#define NKMEMPAGES_MAX NKMEMPAGES_MAX_DEFAULT +#endif struct kmembuckets bucket[MINBUCKET + 16]; struct kmemstats kmemstats[M_LAST]; @@ -409,6 +433,43 @@ free(addr, type) } /* + * Compute the number of pages that kmem_map will map, that is, + * the size of the kernel malloc arena. + */ +void +kmeminit_nkmempages() +{ + int npages; + + if (nkmempages != 0) { + /* + * It's already been set (by us being here before, or + * by patching or kernel config options), bail out now. + */ + return; + } + + /* + * We use the following (simple) formula: + * + * - Starting point is physical memory / 4. + * + * - Clamp it down to NKMEMPAGES_MAX. + * + * - Round it up to NKMEMPAGES_MIN. + */ + npages = physmem / 4; + + if (npages > NKMEMPAGES_MAX) + npages = NKMEMPAGES_MAX; + + if (npages < NKMEMPAGES_MIN) + npages = NKMEMPAGES_MIN; + + nkmempages = npages; +} + +/* * Initialize the kernel memory allocator */ void @@ -417,18 +478,22 @@ kmeminit() #ifdef KMEMSTATS long indx; #endif - int npg; #ifdef DIAGNOSTIC if (sizeof(struct freelist) > (1 << MINBUCKET)) panic("kmeminit: minbucket too small/struct freelist too big"); #endif - npg = VM_KMEM_SIZE / PAGE_SIZE; + /* + * Compute the number of kmem_map pages, if we have not + * done so already. + */ + kmeminit_nkmempages(); + kmemusage = (struct kmemusage *) uvm_km_zalloc(kernel_map, - (vsize_t)(npg * sizeof(struct kmemusage))); + (vsize_t)(nkmempages * sizeof(struct kmemusage))); kmem_map = uvm_km_suballoc(kernel_map, (vaddr_t *)&kmembase, - (vaddr_t *)&kmemlimit, (vsize_t)(npg * PAGE_SIZE), + (vaddr_t *)&kmemlimit, (vsize_t)(nkmempages * PAGE_SIZE), VM_MAP_INTRSAFE, FALSE, &kmem_map_store); #ifdef KMEMSTATS for (indx = 0; indx < MINBUCKET + 16; indx++) { @@ -439,13 +504,11 @@ kmeminit() bucket[indx].kb_highwat = 5 * bucket[indx].kb_elmpercl; } for (indx = 0; indx < M_LAST; indx++) - kmemstats[indx].ks_limit = npg * PAGE_SIZE * 6 / 10; + kmemstats[indx].ks_limit = nkmempages * PAGE_SIZE * 6 / 10; #endif #ifdef MALLOC_DEBUG debug_malloc_init(); #endif - - nkmempages = npg; } /* |