remove details of the kernel malloc() implementation from header files:

- change MALLOC() and FREE() to just call their function equivalents.
 - remove references to other malloc()-related constants.
This commit is contained in:
chs 2006-10-02 02:59:38 +00:00
parent 4d15d9eb84
commit 164df76537
4 changed files with 66 additions and 122 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: pmap.c,v 1.138 2006/07/08 00:27:30 matt Exp $ */ /* $NetBSD: pmap.c,v 1.139 2006/10/02 02:59:38 chs Exp $ */
/* /*
* Copyright (c) 1994, 1998, 1999, 2003 Ludd, University of Lule}, Sweden. * Copyright (c) 1994, 1998, 1999, 2003 Ludd, University of Lule}, Sweden.
* All rights reserved. * All rights reserved.
@ -30,7 +30,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.138 2006/07/08 00:27:30 matt Exp $"); __KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.139 2006/10/02 02:59:38 chs Exp $");
#include "opt_ddb.h" #include "opt_ddb.h"
#include "opt_cputype.h" #include "opt_cputype.h"
@ -201,6 +201,11 @@ calc_kvmsize(vsize_t usrptsize)
{ {
vsize_t kvmsize, bufsz; vsize_t kvmsize, bufsz;
/*
* Compute the number of pages kmem_map will have.
*/
kmeminit_nkmempages();
/* All physical memory */ /* All physical memory */
kvmsize = avail_end; kvmsize = avail_end;
/* User Page table area. This may be large */ /* User Page table area. This may be large */
@ -208,8 +213,7 @@ calc_kvmsize(vsize_t usrptsize)
/* Kernel stacks per process */ /* Kernel stacks per process */
kvmsize += (USPACE * maxproc); kvmsize += (USPACE * maxproc);
/* kernel malloc arena */ /* kernel malloc arena */
kvmsize += (NKMEMPAGES_MAX_DEFAULT * PAGE_SIZE + kvmsize += nkmempages * PAGE_SIZE;
NKMEMPAGES_MAX_DEFAULT * sizeof(struct kmemusage));
/* IO device register space */ /* IO device register space */
kvmsize += (IOSPSZ * VAX_NBPG); kvmsize += (IOSPSZ * VAX_NBPG);
/* Pager allocations */ /* Pager allocations */

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_malloc.c,v 1.102 2006/07/21 10:08:41 yamt Exp $ */ /* $NetBSD: kern_malloc.c,v 1.103 2006/10/02 02:59:38 chs Exp $ */
/* /*
* Copyright (c) 1987, 1991, 1993 * Copyright (c) 1987, 1991, 1993
@ -66,7 +66,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.102 2006/07/21 10:08:41 yamt Exp $"); __KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.103 2006/10/02 02:59:38 chs Exp $");
#include "opt_lockdebug.h" #include "opt_lockdebug.h"
@ -113,10 +113,62 @@ int nkmempages = NKMEMPAGES;
#include "opt_malloclog.h" #include "opt_malloclog.h"
#include "opt_malloc_debug.h" #include "opt_malloc_debug.h"
#define MINALLOCSIZE (1 << MINBUCKET)
#define BUCKETINDX(size) \
((size) <= (MINALLOCSIZE * 128) \
? (size) <= (MINALLOCSIZE * 8) \
? (size) <= (MINALLOCSIZE * 2) \
? (size) <= (MINALLOCSIZE * 1) \
? (MINBUCKET + 0) \
: (MINBUCKET + 1) \
: (size) <= (MINALLOCSIZE * 4) \
? (MINBUCKET + 2) \
: (MINBUCKET + 3) \
: (size) <= (MINALLOCSIZE* 32) \
? (size) <= (MINALLOCSIZE * 16) \
? (MINBUCKET + 4) \
: (MINBUCKET + 5) \
: (size) <= (MINALLOCSIZE * 64) \
? (MINBUCKET + 6) \
: (MINBUCKET + 7) \
: (size) <= (MINALLOCSIZE * 2048) \
? (size) <= (MINALLOCSIZE * 512) \
? (size) <= (MINALLOCSIZE * 256) \
? (MINBUCKET + 8) \
: (MINBUCKET + 9) \
: (size) <= (MINALLOCSIZE * 1024) \
? (MINBUCKET + 10) \
: (MINBUCKET + 11) \
: (size) <= (MINALLOCSIZE * 8192) \
? (size) <= (MINALLOCSIZE * 4096) \
? (MINBUCKET + 12) \
: (MINBUCKET + 13) \
: (size) <= (MINALLOCSIZE * 16384) \
? (MINBUCKET + 14) \
: (MINBUCKET + 15))
/*
* Array of descriptors that describe the contents of each page
*/
struct kmemusage {
short ku_indx; /* bucket index */
union {
u_short freecnt;/* for small allocations, free pieces in page */
u_short pagecnt;/* for large allocations, pages alloced */
} ku_un;
};
#define ku_freecnt ku_un.freecnt
#define ku_pagecnt ku_un.pagecnt
struct kmembuckets kmembuckets[MINBUCKET + 16]; struct kmembuckets kmembuckets[MINBUCKET + 16];
struct kmemusage *kmemusage; struct kmemusage *kmemusage;
char *kmembase, *kmemlimit; char *kmembase, *kmemlimit;
/*
* Turn virtual addresses into kmem map indicies
*/
#define btokup(addr) (&kmemusage[((caddr_t)(addr) - kmembase) >> PGSHIFT])
struct malloc_type *kmemstatistics; struct malloc_type *kmemstatistics;
#ifdef MALLOCLOG #ifdef MALLOCLOG

View File

@ -1,4 +1,4 @@
/* $NetBSD: subr_autoconf.c,v 1.114 2006/05/14 05:26:59 christos Exp $ */ /* $NetBSD: subr_autoconf.c,v 1.115 2006/10/02 02:59:38 chs Exp $ */
/* /*
* Copyright (c) 1996, 2000 Christopher G. Demetriou * Copyright (c) 1996, 2000 Christopher G. Demetriou
@ -77,7 +77,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.114 2006/05/14 05:26:59 christos Exp $"); __KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.115 2006/10/02 02:59:38 chs Exp $");
#include "opt_ddb.h" #include "opt_ddb.h"
@ -877,7 +877,7 @@ config_makeroom(int n, struct cfdriver *cd)
*/ */
old = cd->cd_ndevs; old = cd->cd_ndevs;
if (old == 0) if (old == 0)
new = MINALLOCSIZE / sizeof(void *); new = 4;
else else
new = old * 2; new = old * 2;
while (new <= n) while (new <= n)

View File

@ -1,4 +1,4 @@
/* $NetBSD: malloc.h,v 1.95 2006/03/17 23:27:12 christos Exp $ */ /* $NetBSD: malloc.h,v 1.96 2006/10/02 02:59:38 chs Exp $ */
/* /*
* Copyright (c) 1987, 1993 * Copyright (c) 1987, 1993
@ -77,19 +77,6 @@ MALLOC_DECLARE(M_BWMETER);
MALLOC_DECLARE(M_1394DATA); MALLOC_DECLARE(M_1394DATA);
#endif /* _KERNEL */ #endif /* _KERNEL */
/*
* Array of descriptors that describe the contents of each page
*/
struct kmemusage {
short ku_indx; /* bucket index */
union {
u_short freecnt;/* for small allocations, free pieces in page */
u_short pagecnt;/* for large allocations, pages alloced */
} ku_un;
};
#define ku_freecnt ku_un.freecnt
#define ku_pagecnt ku_un.pagecnt
/* /*
* Set of buckets for each size of memory block that is retained * Set of buckets for each size of memory block that is retained
*/ */
@ -105,109 +92,10 @@ struct kmembuckets {
}; };
#ifdef _KERNEL #ifdef _KERNEL
#define MINALLOCSIZE (1 << MINBUCKET)
#define BUCKETINDX(size) \
((size) <= (MINALLOCSIZE * 128) \
? (size) <= (MINALLOCSIZE * 8) \
? (size) <= (MINALLOCSIZE * 2) \
? (size) <= (MINALLOCSIZE * 1) \
? (MINBUCKET + 0) \
: (MINBUCKET + 1) \
: (size) <= (MINALLOCSIZE * 4) \
? (MINBUCKET + 2) \
: (MINBUCKET + 3) \
: (size) <= (MINALLOCSIZE* 32) \
? (size) <= (MINALLOCSIZE * 16) \
? (MINBUCKET + 4) \
: (MINBUCKET + 5) \
: (size) <= (MINALLOCSIZE * 64) \
? (MINBUCKET + 6) \
: (MINBUCKET + 7) \
: (size) <= (MINALLOCSIZE * 2048) \
? (size) <= (MINALLOCSIZE * 512) \
? (size) <= (MINALLOCSIZE * 256) \
? (MINBUCKET + 8) \
: (MINBUCKET + 9) \
: (size) <= (MINALLOCSIZE * 1024) \
? (MINBUCKET + 10) \
: (MINBUCKET + 11) \
: (size) <= (MINALLOCSIZE * 8192) \
? (size) <= (MINALLOCSIZE * 4096) \
? (MINBUCKET + 12) \
: (MINBUCKET + 13) \
: (size) <= (MINALLOCSIZE * 16384) \
? (MINBUCKET + 14) \
: (MINBUCKET + 15))
/*
* Turn virtual addresses into kmem map indicies
*/
#define kmemxtob(alloc) (kmembase + (alloc) * NBPG)
#define btokmemx(addr) (((caddr_t)(addr) - kmembase) / NBPG)
#define btokup(addr) (&kmemusage[((caddr_t)(addr) - kmembase) >> PGSHIFT])
extern struct simplelock malloc_slock;
/*
* Macro versions for the usual cases of malloc/free
*/
#if defined(KMEMSTATS) || defined(DIAGNOSTIC) || defined(_LKM) || \
defined(MALLOCLOG) || defined(LOCKDEBUG) || defined(MALLOC_NOINLINE)
#define MALLOC(space, cast, size, type, flags) \ #define MALLOC(space, cast, size, type, flags) \
(space) = (cast)malloc((u_long)(size), (type), (flags)) (space) = (cast)malloc((u_long)(size), (type), (flags))
#define FREE(addr, type) free((caddr_t)(addr), (type)) #define FREE(addr, type) free((caddr_t)(addr), (type))
#else /* do not collect statistics */
#define MALLOC(space, cast, size, type, flags) \
do { \
unsigned long __size = (unsigned long)(size); \
struct kmembuckets *__kbp = &kmembuckets[BUCKETINDX(__size)]; \
int __s = splvm(); \
switch (__size) { \
case size: /* fail to compile if size is not const */ \
break; \
} \
simple_lock(&malloc_slock); \
if (__kbp->kb_next == NULL) { \
simple_unlock(&malloc_slock); \
(space) = (cast)malloc(__size, (type), (flags)); \
splx(__s); \
} else { \
(space) = (cast)__kbp->kb_next; \
__kbp->kb_next = *(caddr_t *)(space); \
simple_unlock(&malloc_slock); \
splx(__s); \
if ((flags) & M_ZERO) \
memset((space), 0, __size); \
} \
} while (/* CONSTCOND */ 0)
#define FREE(addr, type) \
do { \
struct kmembuckets *__kbp; \
struct kmemusage *__kup = btokup((addr)); \
int __s = splvm(); \
if (1 << __kup->ku_indx > MAXALLOCSAVE) { \
free((caddr_t)(addr), (type)); \
} else { \
simple_lock(&malloc_slock); \
__kbp = &kmembuckets[__kup->ku_indx]; \
if (__kbp->kb_next == NULL) \
__kbp->kb_next = (caddr_t)(addr); \
else \
*(caddr_t *)(__kbp->kb_last) = (caddr_t)(addr); \
*(caddr_t *)(addr) = NULL; \
__kbp->kb_last = (caddr_t)(addr); \
simple_unlock(&malloc_slock); \
} \
splx(__s); \
} while(/* CONSTCOND */ 0)
#endif /* do not collect statistics */
extern struct kmemusage *kmemusage;
extern char *kmembase;
extern struct kmembuckets kmembuckets[];
#ifdef MALLOCLOG #ifdef MALLOCLOG
void *_malloc(unsigned long, struct malloc_type *, int, const char *, long); void *_malloc(unsigned long, struct malloc_type *, int, const char *, long);
void _free(void *, struct malloc_type *, const char *, long); void _free(void *, struct malloc_type *, const char *, long);