From ce45b512b3850a77dbf01a6e872ddcfded752a08 Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Wed, 12 May 1999 11:11:27 +0000 Subject: Fixed corruption of the kmemstatistcs list. The first malloc() with malloc type at the tail of the list changed the list from linear to circular. This seemed to cause surprisingly few problems, but it now causes weird output from `vmstat -m', probably because a more important malloc type is now at the tail of the list. Fix it by abusing ks_limit instead of ks_next as a flag for being on the list. Don't forget to clear the flag when a malloc type is uninit'ed. Uninit'ing is still fundamentally broken -- it loses history. --- sys/kern/kern_malloc.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'sys/kern/kern_malloc.c') diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index e7499d50258f..0b300c2450f8 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)kern_malloc.c 8.3 (Berkeley) 1/4/94 - * $Id: kern_malloc.c,v 1.54 1999/01/27 21:49:56 dillon Exp $ + * $Id: kern_malloc.c,v 1.55 1999/05/06 18:12:42 peter Exp $ */ #include "opt_vm.h" @@ -138,9 +138,8 @@ malloc(size, type, flags) s = splmem(); - if (!type->ks_next) { + if (type->ks_limit == 0) malloc_init(type); - } indx = BUCKETINDX(size); kbp = &bucket[indx]; @@ -283,7 +282,7 @@ free(addr, type) #endif register struct malloc_type *ksp = type; - if (!type->ks_next) + if (type->ks_limit == 0) panic("freeing with unknown type (%s)", type->ks_shortdesc); KASSERT(kmembase <= (char *)addr && (char *)addr < kmemlimit, @@ -466,7 +465,7 @@ malloc_init(data) if (type->ks_magic != M_MAGIC) panic("malloc type lacks magic"); - if (type->ks_next) + if (type->ks_limit != 0) return; if (cnt.v_page_count == 0) @@ -494,6 +493,9 @@ malloc_uninit(data) if (cnt.v_page_count == 0) panic("malloc_uninit not allowed before vm init"); + if (type->ks_limit == 0) + panic("malloc_uninit on uninitialized type"); + if (type == kmemstatistics) kmemstatistics = type->ks_next; else { @@ -504,4 +506,6 @@ malloc_uninit(data) } } } + type->ks_next = NULL; + type->ks_limit = 0; } -- cgit v1.2.3