summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_malloc.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1998-11-10 08:46:24 +0000
committerpeter <peter@FreeBSD.org>1998-11-10 08:46:24 +0000
commit0f95240d58e95f72af7231f521da0616cf35fa6d (patch)
tree3268fe697d81b0d844e113bf9f3e1204467fa87d /sys/kern/kern_malloc.c
parent5d771943bc4269a8c023903ae33f4861803c511a (diff)
downloadFreeBSD-src-0f95240d58e95f72af7231f521da0616cf35fa6d.zip
FreeBSD-src-0f95240d58e95f72af7231f521da0616cf35fa6d.tar.gz
Have MALLOC_DECLARE() initialize malloc types explicitly, and have them
removed at module unload (if in a module of course). However; this introduces a new dependency on <sys/kernel.h> for things that use MALLOC_DECLARE(). Bruce told me it is better to add sys/kernel.h to the handful of files that need it rather than add an extra include to sys/malloc.h for kernel compiles. Updates to follow in subsequent commits.
Diffstat (limited to 'sys/kern/kern_malloc.c')
-rw-r--r--sys/kern/kern_malloc.c40
1 files changed, 34 insertions, 6 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index 3de5e17..1ced96a 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.47 1998/08/16 01:21:51 bde Exp $
+ * $Id: kern_malloc.c,v 1.48 1998/10/25 17:44:51 phk Exp $
*/
#include "opt_vm.h"
@@ -53,12 +53,11 @@
#include <vm/vm_map.h>
static void kmeminit __P((void *));
-static void malloc_init __P((struct malloc_type *));
SYSINIT(kmem, SI_SUB_KMEM, SI_ORDER_FIRST, kmeminit, NULL)
static MALLOC_DEFINE(M_FREE, "free", "should be on free list");
-static struct malloc_type *kmemstatistics = M_FREE;
+static struct malloc_type *kmemstatistics;
static struct kmembuckets bucket[MINBUCKET + 16];
static struct kmemusage *kmemusage;
static char *kmembase;
@@ -432,14 +431,18 @@ kmeminit(dummy)
}
}
-static void
-malloc_init(type)
- struct malloc_type *type;
+void
+malloc_init(data)
+ void *data;
{
+ struct malloc_type *type = (struct malloc_type *)data;
if (type->ks_magic != M_MAGIC)
panic("malloc type lacks magic");
+ if (type->ks_next)
+ return;
+
if (cnt.v_page_count == 0)
panic("malloc_init not allowed before vm init");
@@ -451,3 +454,28 @@ malloc_init(type)
type->ks_next = kmemstatistics;
kmemstatistics = type;
}
+
+void
+malloc_uninit(data)
+ void *data;
+{
+ struct malloc_type *type = (struct malloc_type *)data;
+ struct malloc_type *t;
+
+ if (type->ks_magic != M_MAGIC)
+ panic("malloc type lacks magic");
+
+ if (cnt.v_page_count == 0)
+ panic("malloc_uninit not allowed before vm init");
+
+ if (type == kmemstatistics)
+ kmemstatistics = type->ks_next;
+ else {
+ for (t = kmemstatistics; t->ks_next != NULL; t = t->ks_next) {
+ if (t->ks_next == type) {
+ t->ks_next = type->ks_next;
+ break;
+ }
+ }
+ }
+}
OpenPOWER on IntegriCloud