summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>1999-02-26 04:54:01 +0000
committerArtur Grabowski <art@cvs.openbsd.org>1999-02-26 04:54:01 +0000
commite15989470c31efa3a857718e7462663964497155 (patch)
tree8c3443152717af59e2f6dc5556fe89727676ab35 /sys/kern
parent52b4d7fbde220c6651b33720adb78ce6728e00b1 (diff)
kmem allocation changes for uvm
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_lkm.c18
-rw-r--r--sys/kern/kern_malloc.c47
2 files changed, 61 insertions, 4 deletions
diff --git a/sys/kern/kern_lkm.c b/sys/kern/kern_lkm.c
index acab4f431f4..4e2044ed753 100644
--- a/sys/kern/kern_lkm.c
+++ b/sys/kern/kern_lkm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_lkm.c,v 1.24 1999/02/19 17:17:49 art Exp $ */
+/* $OpenBSD: kern_lkm.c,v 1.25 1999/02/26 04:54:00 art Exp $ */
/* $NetBSD: kern_lkm.c,v 1.31 1996/03/31 21:40:27 christos Exp $ */
/*
@@ -250,7 +250,11 @@ lkmunreserve()
* Actually unreserve the memory
*/
if (curp && curp->area) {
+#if defined(UVM)
+ uvm_km_free(kmem_map, curp->area, curp->size);
+#else
kmem_free(kmem_map, curp->area, curp->size);/**/
+#endif
curp->area = 0;
}
@@ -326,7 +330,11 @@ lkmioctl(dev, cmd, data, flag, p)
*/
curp->size = resrvp->size;
+#if defined(UVM)
+ curp->area = uvm_km_zalloc(kmem_map, curp->size);
+#else
curp->area = kmem_alloc(kmem_map, curp->size);/**/
+#endif
curp->offset = 0; /* load offset */
@@ -335,7 +343,13 @@ lkmioctl(dev, cmd, data, flag, p)
if (cmd == LMRESERV && resrvp->sym_size) {
curp->sym_size = resrvp->sym_size;
curp->sym_symsize = resrvp->sym_symsize;
- curp->syms = (caddr_t)kmem_alloc(kmem_map, curp->sym_size);
+#if defined(UVM)
+ curp->syms = (caddr_t)uvm_km_zalloc(kmem_map,
+ curp->sym_size);
+#else
+ curp->syms = (caddr_t)kmem_alloc(kmem_map,
+ curp->sym_size);
+#endif
curp->sym_offset = 0;
resrvp->sym_addr = curp->syms; /* ret symbol addr */
} else {
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index d72f79fdc27..1387333e6f8 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_malloc.c,v 1.11 1999/01/20 21:47:46 art Exp $ */
+/* $OpenBSD: kern_malloc.c,v 1.12 1999/02/26 04:54:00 art Exp $ */
/* $NetBSD: kern_malloc.c,v 1.15.4.2 1996/06/13 17:10:56 cgd Exp $ */
/*
@@ -46,6 +46,13 @@
#include <vm/vm.h>
#include <vm/vm_kern.h>
+#if defined(UVM)
+#include <uvm/uvm_extern.h>
+
+static struct vm_map kmem_map_store;
+vm_map_t kmem_map = NULL;
+#endif
+
struct kmembuckets bucket[MINBUCKET + 16];
#ifdef KMEMSTATS
struct kmemstats kmemstats[M_LAST];
@@ -144,8 +151,14 @@ malloc(size, type, flags)
else
allocsize = 1 << indx;
npg = clrnd(btoc(allocsize));
+#if defined(UVM)
+ va = (caddr_t) uvm_km_kmemalloc(kmem_map, uvmexp.kmem_object,
+ (vsize_t)ctob(npg),
+ (flags & M_NOWAIT) ? UVM_KMF_NOWAIT : 0);
+#else
va = (caddr_t) kmem_malloc(kmem_map, (vm_size_t)ctob(npg),
!(flags & M_NOWAIT));
+#endif
if (va == NULL) {
/*
* Kmem_malloc() can return NULL, even if it can
@@ -212,13 +225,31 @@ malloc(size, type, flags)
freep = (struct freelist *)va;
savedtype = (unsigned)freep->type < M_LAST ?
memname[freep->type] : "???";
+#if defined(UVM)
+ if (kbp->kb_next) {
+ int rv;
+ vaddr_t addr = (vaddr_t)kbp->kb_next;
+
+ vm_map_lock_read(kmem_map);
+ rv = uvm_map_checkprot(kmem_map, addr,
+ addr + sizeof(struct freelist),
+ VM_PROT_WRITE);
+ vm_map_unlock_read(kmem_map);
+
+ if (!rv)
+#else
if (kbp->kb_next &&
- !kernacc(kbp->kb_next, sizeof(struct freelist), 0)) {
+ !kernacc(kbp->kb_next, sizeof(struct freelist), 0))
+#endif
+ {
printf("%s %d of object %p size %ld %s %s (invalid addr %p)\n",
"Data modified on freelist: word",
(int32_t *)&kbp->kb_next - (int32_t *)kbp, va, size,
"previous type", savedtype, kbp->kb_next);
kbp->kb_next = NULL;
+#if defined(UVM)
+ }
+#endif
}
/* Fill the fields that we've used with WEIRD_ADDR */
@@ -308,7 +339,11 @@ free(addr, type)
addr, size, memname[type], alloc);
#endif /* DIAGNOSTIC */
if (size > MAXALLOCSAVE) {
+#if defined(UVM)
+ uvm_km_free(kmem_map, (vaddr_t)addr, ctob(kup->ku_pagecnt));
+#else
kmem_free(kmem_map, (vm_offset_t)addr, ctob(kup->ku_pagecnt));
+#endif
#ifdef KMEMSTATS
size = kup->ku_pagecnt << PGSHIFT;
ksp->ks_memuse -= size;
@@ -399,10 +434,18 @@ kmeminit()
panic("minbucket too small/struct freelist too big");
npg = VM_KMEM_SIZE/ NBPG;
+#if defined(UVM)
+ kmemusage = (struct kmemusage *) uvm_km_zalloc(kernel_map,
+ (vsize_t)(npg * sizeof(struct kmemusage)));
+ kmem_map = uvm_km_suballoc(kernel_map, (vaddr_t *)&kmembase,
+ (vaddr_t *)&kmemlimit, (vsize_t)(npg * NBPG),
+ FALSE, FALSE, &kmem_map_store);
+#else
kmemusage = (struct kmemusage *) kmem_alloc(kernel_map,
(vm_size_t)(npg * sizeof(struct kmemusage)));
kmem_map = kmem_suballoc(kernel_map, (vm_offset_t *)&kmembase,
(vm_offset_t *)&kmemlimit, (vm_size_t)(npg * NBPG), FALSE);
+#endif
#ifdef KMEMSTATS
for (indx = 0; indx < MINBUCKET + 16; indx++) {
if (1 << indx >= CLBYTES)