Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Add some very simple code to auto-size the kmem_map. We...
details: https://anonhg.NetBSD.org/src/rev/fa1659a4cdcd
branches: trunk
changeset: 481997:fa1659a4cdcd
user: thorpej <thorpej%NetBSD.org@localhost>
date: Fri Feb 11 19:22:52 2000 +0000
description:
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:
sys/conf/files | 3 +-
sys/kern/kern_malloc.c | 97 ++++++++++++++++++++++++++++++++++++++++++-------
sys/sys/proc.h | 3 +-
sys/uvm/uvm_extern.h | 7 +++-
sys/uvm/uvm_meter.c | 5 ++-
sys/vm/vm_param.h | 6 ++-
6 files changed, 100 insertions(+), 21 deletions(-)
diffs (270 lines):
diff -r f669395b9c09 -r fa1659a4cdcd sys/conf/files
--- a/sys/conf/files Fri Feb 11 19:09:56 2000 +0000
+++ b/sys/conf/files Fri Feb 11 19:22:52 2000 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files,v 1.347 2000/01/31 14:18:52 itojun Exp $
+# $NetBSD: files,v 1.348 2000/02/11 19:22:53 thorpej Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
@@ -24,6 +24,7 @@
NFS_BOOT_TCP NFS_BOOT_OPTIONS NFS_BOOT_RWSIZE
defopt NFSSERVER
+defopt opt_kmempages.h NKMEMPAGES NKMEMPAGES_MIN NKMEMPAGES_MAX
defopt opt_malloclog.h MALLOCLOG MALLOCLOGSIZE
defopt opt_pool.h POOL_DIAGNOSTIC
defopt opt_poollog.h POOL_LOGSIZE
diff -r f669395b9c09 -r fa1659a4cdcd sys/kern/kern_malloc.c
--- a/sys/kern/kern_malloc.c Fri Feb 11 19:09:56 2000 +0000
+++ b/sys/kern/kern_malloc.c Fri Feb 11 19:22:52 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_malloc.c,v 1.48 2000/02/01 19:37:58 thorpej Exp $ */
+/* $NetBSD: kern_malloc.c,v 1.49 2000/02/11 19:22:52 thorpej Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
@@ -53,6 +53,34 @@
static struct vm_map_intrsafe kmem_map_store;
vm_map_t kmem_map = NULL;
+#include "opt_kmempages.h"
+
+#ifdef NKMEMCLUSTERS
+#error NKMEMCLUSTERS is obsolete; 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
+
#include "opt_kmemstats.h"
#include "opt_malloclog.h"
@@ -223,7 +251,7 @@
if (kbp->kb_next == NULL) {
kbp->kb_last = NULL;
if (size > MAXALLOCSAVE)
- allocsize = roundup(size, NBPG);
+ allocsize = roundup(size, PAGE_SIZE);
else
allocsize = 1 << indx;
npg = btoc(allocsize);
@@ -268,7 +296,7 @@
* bucket, don't assume the list is still empty.
*/
savedlist = kbp->kb_next;
- kbp->kb_next = cp = va + (npg * NBPG) - allocsize;
+ kbp->kb_next = cp = va + (npg << PAGE_SHIFT) - allocsize;
for (;;) {
freep = (struct freelist *)cp;
#ifdef DIAGNOSTIC
@@ -428,8 +456,8 @@
* Check for returns of data that do not point to the
* beginning of the allocation.
*/
- if (size > NBPG)
- alloc = addrmask[BUCKETINDX(NBPG)];
+ if (size > PAGE_SIZE)
+ alloc = addrmask[BUCKETINDX(PAGE_SIZE)];
else
alloc = addrmask[kup->ku_indx];
if (((u_long)addr & alloc) != 0)
@@ -554,8 +582,8 @@
* Check for returns of data that do not point to the
* beginning of the allocation.
*/
- if (cursize > NBPG)
- alloc = addrmask[BUCKETINDX(NBPG)];
+ if (cursize > PAGE_SIZE)
+ alloc = addrmask[BUCKETINDX(PAGE_SIZE)];
else
alloc = addrmask[kup->ku_indx];
if (((u_long)curaddr & alloc) != 0)
@@ -596,6 +624,43 @@
}
/*
+ * 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
@@ -604,7 +669,6 @@
#ifdef KMEMSTATS
register long indx;
#endif
- int npg;
#if ((MAXALLOCSAVE & (MAXALLOCSAVE - 1)) != 0)
ERROR!_kmeminit:_MAXALLOCSAVE_not_power_of_2
@@ -619,22 +683,27 @@
if (sizeof(struct freelist) > (1 << MINBUCKET))
panic("minbucket too small/struct freelist too big");
- npg = VM_KMEM_SIZE/ NBPG;
+ /*
+ * 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 * NBPG),
+ (vaddr_t *)&kmemlimit, (vsize_t)(nkmempages << PAGE_SHIFT),
VM_MAP_INTRSAFE, FALSE, &kmem_map_store.vmi_map);
#ifdef KMEMSTATS
for (indx = 0; indx < MINBUCKET + 16; indx++) {
- if (1 << indx >= NBPG)
+ if (1 << indx >= PAGE_SIZE)
bucket[indx].kb_elmpercl = 1;
else
- bucket[indx].kb_elmpercl = NBPG / (1 << indx);
+ bucket[indx].kb_elmpercl = PAGE_SIZE / (1 << indx);
bucket[indx].kb_highwat = 5 * bucket[indx].kb_elmpercl;
}
for (indx = 0; indx < M_LAST; indx++)
- kmemstats[indx].ks_limit = npg * NBPG * 6 / 10;
+ kmemstats[indx].ks_limit = (nkmempages << PAGE_SHIFT) * 6 / 10;
#endif
}
diff -r f669395b9c09 -r fa1659a4cdcd sys/sys/proc.h
--- a/sys/sys/proc.h Fri Feb 11 19:09:56 2000 +0000
+++ b/sys/sys/proc.h Fri Feb 11 19:22:52 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: proc.h,v 1.85 2000/02/06 16:47:57 eeh Exp $ */
+/* $NetBSD: proc.h,v 1.86 2000/02/11 19:22:54 thorpej Exp $ */
/*-
* Copyright (c) 1986, 1989, 1991, 1993
@@ -382,7 +382,6 @@
void exit2 __P((struct proc *));
int fork1 __P((struct proc *, int, int, void *, size_t, register_t *,
struct proc **));
-void kmeminit __P((void));
void rqinit __P((void));
int groupmember __P((gid_t, struct ucred *));
void cpu_switch __P((struct proc *));
diff -r f669395b9c09 -r fa1659a4cdcd sys/uvm/uvm_extern.h
--- a/sys/uvm/uvm_extern.h Fri Feb 11 19:09:56 2000 +0000
+++ b/sys/uvm/uvm_extern.h Fri Feb 11 19:22:52 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_extern.h,v 1.36 2000/01/11 06:57:49 chs Exp $ */
+/* $NetBSD: uvm_extern.h,v 1.37 2000/02/11 19:22:54 thorpej Exp $ */
/*
*
@@ -408,6 +408,11 @@
boolean_t uvm_vnp_uncache __P((struct vnode *));
struct uvm_object *uvn_attach __P((void *, vm_prot_t));
+/* kern_malloc.c */
+void kmeminit_nkmempages __P((void));
+void kmeminit __P((void));
+extern int nkmempages;
+
#endif /* _KERNEL */
#endif /* _UVM_UVM_EXTERN_H_ */
diff -r f669395b9c09 -r fa1659a4cdcd sys/uvm/uvm_meter.c
--- a/sys/uvm/uvm_meter.c Fri Feb 11 19:09:56 2000 +0000
+++ b/sys/uvm/uvm_meter.c Fri Feb 11 19:22:52 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_meter.c,v 1.10 1999/07/25 06:30:36 thorpej Exp $ */
+/* $NetBSD: uvm_meter.c,v 1.11 2000/02/11 19:22:54 thorpej Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -146,6 +146,9 @@
return (sysctl_rdstruct(oldp, oldlenp, newp, &uvmexp,
sizeof(uvmexp)));
+ case VM_NKMEMPAGES:
+ return (sysctl_rdint(oldp, oldlenp, newp, nkmempages));
+
default:
return (EOPNOTSUPP);
}
diff -r f669395b9c09 -r fa1659a4cdcd sys/vm/vm_param.h
--- a/sys/vm/vm_param.h Fri Feb 11 19:09:56 2000 +0000
+++ b/sys/vm/vm_param.h Fri Feb 11 19:22:52 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vm_param.h,v 1.22 1999/11/30 19:31:05 thorpej Exp $ */
+/* $NetBSD: vm_param.h,v 1.23 2000/02/11 19:22:54 thorpej Exp $ */
/*
* Copyright (c) 1991, 1993
@@ -107,13 +107,15 @@
#define VM_METER 1 /* struct vmmeter */
#define VM_LOADAVG 2 /* struct loadavg */
#define VM_UVMEXP 3 /* struct uvmexp */
-#define VM_MAXID 4 /* number of valid vm ids */
+#define VM_NKMEMPAGES 4 /* kmem_map pages */
+#define VM_MAXID 5 /* number of valid vm ids */
#define CTL_VM_NAMES { \
{ 0, 0 }, \
{ "vmmeter", CTLTYPE_STRUCT }, \
{ "loadavg", CTLTYPE_STRUCT }, \
{ "uvmexp", CTLTYPE_STRUCT }, \
+ { "nkmempages", CTLTYPE_INT }, \
}
Home |
Main Index |
Thread Index |
Old Index