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.
This commit is contained in:
peter 1998-11-10 08:46:24 +00:00
parent 6639fb73d5
commit e2f008042e
2 changed files with 44 additions and 10 deletions

View File

@ -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;
}
}
}
}

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)malloc.h 8.5 (Berkeley) 5/3/95
* $Id: malloc.h,v 1.36 1997/12/27 09:42:03 bde Exp $
* $Id: malloc.h,v 1.37 1998/03/08 09:58:26 julian Exp $
*/
#ifndef _SYS_MALLOC_H_
@ -64,15 +64,20 @@ struct malloc_type {
u_short ks_mapblocks; /* number of times blocked for kernel map */
};
#ifdef KERNEL
void malloc_init __P((void *));
void malloc_uninit __P((void *));
#define MALLOC_DEFINE(type, shortdesc, longdesc) \
struct malloc_type type[1] = { \
{ NULL, 0, 0, 0, 0, 0, 0, M_MAGIC, shortdesc, 0, 0 } \
}; \
struct __hack
SYSINIT(type##_init, SI_SUB_KMEM, SI_ORDER_ANY, malloc_init, type); \
SYSUNINIT(type##_uninit, SI_SUB_KMEM, SI_ORDER_ANY, malloc_uninit, type)
#define MALLOC_DECLARE(type) \
extern struct malloc_type type[1]; \
struct __hack
extern struct malloc_type type[1]
#ifdef MALLOC_INSTANTIATE
#define MALLOC_MAKE_TYPE(type, shortdesc, longdesc) \
@ -85,6 +90,7 @@ struct malloc_type {
MALLOC_MAKE_TYPE(M_CACHE, "namecache", "Dynamically allocated cache entries");
MALLOC_MAKE_TYPE(M_DEVBUF, "devbuf", "device driver memory");
MALLOC_MAKE_TYPE(M_TEMP, "temp", "misc temporary data buffers");
#endif /* KERNEL */
/*
* Array of descriptors that describe the contents of each page