Module Name: src Committed By: rmind Date: Sat Apr 28 23:03:40 UTC 2012
Modified Files: src/sys/arch/ia64/conf: GENERIC GENERIC.SKI src/sys/conf: files src/sys/ddb: db_command.c src/sys/kern: kern_malloc.c src/sys/sys: malloc.h mallocvar.h Removed Files: src/sys/kern: kern_malloc_debug.c kern_malloc_stdtype.c Log Message: Remove MALLOC_DEBUG and MALLOCLOG, which is dead code after malloc(9) move to kmem(9). Note: kmem(9) has debugging facilities under DEBUG/DIAGNOSTIC. However, expensive kmguard and debug_freecheck have to be enabled manually. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/arch/ia64/conf/GENERIC cvs rdiff -u -r1.7 -r1.8 src/sys/arch/ia64/conf/GENERIC.SKI cvs rdiff -u -r1.1047 -r1.1048 src/sys/conf/files cvs rdiff -u -r1.137 -r1.138 src/sys/ddb/db_command.c cvs rdiff -u -r1.138 -r1.139 src/sys/kern/kern_malloc.c cvs rdiff -u -r1.26 -r0 src/sys/kern/kern_malloc_debug.c cvs rdiff -u -r1.4 -r0 src/sys/kern/kern_malloc_stdtype.c cvs rdiff -u -r1.110 -r1.111 src/sys/sys/malloc.h cvs rdiff -u -r1.10 -r1.11 src/sys/sys/mallocvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/ia64/conf/GENERIC diff -u src/sys/arch/ia64/conf/GENERIC:1.4 src/sys/arch/ia64/conf/GENERIC:1.5 --- src/sys/arch/ia64/conf/GENERIC:1.4 Mon May 17 11:41:28 2010 +++ src/sys/arch/ia64/conf/GENERIC Sat Apr 28 23:03:40 2012 @@ -1,4 +1,4 @@ -# $NetBSD: GENERIC,v 1.4 2010/05/17 11:41:28 kiyohara Exp $ +# $NetBSD: GENERIC,v 1.5 2012/04/28 23:03:40 rmind Exp $ # # GENERIC machine description file # @@ -22,7 +22,7 @@ include "arch/ia64/conf/std.ia64" options INCLUDE_CONFIG_FILE # embed config file in kernel binary -#ident "GENERIC-$Revision: 1.4 $" +#ident "GENERIC-$Revision: 1.5 $" maxusers 32 # estimated number of users @@ -45,8 +45,6 @@ options DDB_ONPANIC=1 # see also sysctl options DDB_HISTORY_SIZE=512 # enable history editing in DDB #options KGDB # remote debugger #options KGDB_DEVNAME="\"com\"",KGDB_DEVADDR=0x3f8,KGDB_DEVRATE=9600 -#options MALLOC_DEBUG -#options MALLOCLOG makeoptions DEBUG="-g" # compile full symbol table # File systems Index: src/sys/arch/ia64/conf/GENERIC.SKI diff -u src/sys/arch/ia64/conf/GENERIC.SKI:1.7 src/sys/arch/ia64/conf/GENERIC.SKI:1.8 --- src/sys/arch/ia64/conf/GENERIC.SKI:1.7 Tue Nov 23 11:14:00 2010 +++ src/sys/arch/ia64/conf/GENERIC.SKI Sat Apr 28 23:03:40 2012 @@ -1,4 +1,4 @@ -# $NetBSD: GENERIC.SKI,v 1.7 2010/11/23 11:14:00 hannken Exp $ +# $NetBSD: GENERIC.SKI,v 1.8 2012/04/28 23:03:40 rmind Exp $ # # GENERIC machine description file # @@ -22,7 +22,7 @@ include "arch/ia64/conf/std.ia64" options INCLUDE_CONFIG_FILE # embed config file in kernel binary -#ident "GENERIC-$Revision: 1.7 $" +#ident "GENERIC-$Revision: 1.8 $" maxusers 32 # estimated number of users @@ -44,8 +44,6 @@ options DDB # in-kernel debugger #options DDB_HISTORY_SIZE=512 # enable history editing in DDB #options KGDB # remote debugger #options KGDB_DEVNAME="\"com\"",KGDB_DEVADDR=0x3f8,KGDB_DEVRATE=9600 -#options MALLOC_DEBUG -#options MALLOCLOG makeoptions DEBUG="-g" # compile full symbol table # File systems Index: src/sys/conf/files diff -u src/sys/conf/files:1.1047 src/sys/conf/files:1.1048 --- src/sys/conf/files:1.1047 Sat Apr 7 05:36:49 2012 +++ src/sys/conf/files Sat Apr 28 23:03:39 2012 @@ -1,4 +1,4 @@ -# $NetBSD: files,v 1.1047 2012/04/07 05:36:49 christos Exp $ +# $NetBSD: files,v 1.1048 2012/04/28 23:03:39 rmind Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 version 20100430 @@ -69,9 +69,6 @@ defflag opt_ntp.h PPS_SYNC NTP defflag opt_ptm.h NO_DEV_PTM COMPAT_BSDPTY defparam opt_kmempages.h NKMEMPAGES NKMEMPAGES_MIN NKMEMPAGES_MAX -defflag opt_malloclog.h MALLOCLOG -defparam opt_malloclog.h MALLOCLOGSIZE -defflag opt_malloc_debug.h MALLOC_DEBUG defflag opt_pool.h POOL_DIAGNOSTIC defparam opt_poollog.h POOL_LOGSIZE @@ -1490,8 +1487,6 @@ file kern/kern_ksyms.c ksyms | ddb | mo file kern/kern_lock.c file kern/kern_lwp.c file kern/kern_malloc.c -file kern/kern_malloc_stdtype.c -file kern/kern_malloc_debug.c malloc_debug file kern/kern_module.c file kern/kern_module_vfs.c file kern/kern_mutex.c Index: src/sys/ddb/db_command.c diff -u src/sys/ddb/db_command.c:1.137 src/sys/ddb/db_command.c:1.138 --- src/sys/ddb/db_command.c:1.137 Sun Nov 13 03:21:51 2011 +++ src/sys/ddb/db_command.c Sat Apr 28 23:03:39 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: db_command.c,v 1.137 2011/11/13 03:21:51 mrg Exp $ */ +/* $NetBSD: db_command.c,v 1.138 2012/04/28 23:03:39 rmind Exp $ */ /* * Copyright (c) 1996, 1997, 1998, 1999, 2002, 2009 The NetBSD Foundation, Inc. @@ -60,7 +60,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.137 2011/11/13 03:21:51 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.138 2012/04/28 23:03:39 rmind Exp $"); #ifdef _KERNEL_OPT #include "opt_aio.h" @@ -79,7 +79,6 @@ __KERNEL_RCSID(0, "$NetBSD: db_command.c #include <sys/reboot.h> #include <sys/device.h> #include <sys/lwp.h> -#include <sys/malloc.h> #include <sys/mbuf.h> #include <sys/namei.h> #include <sys/pool.h> @@ -192,7 +191,6 @@ static void db_help_print_cmd(db_exp static void db_lock_print_cmd(db_expr_t, bool, db_expr_t, const char *); static void db_mount_print_cmd(db_expr_t, bool, db_expr_t, const char *); static void db_mbuf_print_cmd(db_expr_t, bool, db_expr_t, const char *); -static void db_malloc_print_cmd(db_expr_t, bool, db_expr_t, const char *); static void db_map_print_cmd(db_expr_t, bool, db_expr_t, const char *); static void db_namecache_print_cmd(db_expr_t, bool, db_expr_t, const char *); @@ -248,7 +246,6 @@ static const struct db_command db_show_c "Print the files open by process at address", "[/f] address", NULL) }, { DDB_ADD_CMD("lock", db_lock_print_cmd, 0,NULL,NULL,NULL) }, - { DDB_ADD_CMD("malloc", db_malloc_print_cmd,0,NULL,NULL,NULL) }, { DDB_ADD_CMD("map", db_map_print_cmd, 0, "Print the vm_map at address.", "[/f] address",NULL) }, { DDB_ADD_CMD("module", db_show_module_cmd, 0, @@ -985,22 +982,6 @@ db_map_print_cmd(db_expr_t addr, bool ha /*ARGSUSED*/ static void -db_malloc_print_cmd(db_expr_t addr, bool have_addr, - db_expr_t count, const char *modif) -{ - -#ifdef MALLOC_DEBUG - if (!have_addr) - addr = 0; - - debug_malloc_printit(db_printf, (vaddr_t) addr); -#else - db_printf("The kernel is not built with the MALLOC_DEBUG option.\n"); -#endif /* MALLOC_DEBUG */ -} - -/*ARGSUSED*/ -static void db_object_print_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif) { Index: src/sys/kern/kern_malloc.c diff -u src/sys/kern/kern_malloc.c:1.138 src/sys/kern/kern_malloc.c:1.139 --- src/sys/kern/kern_malloc.c:1.138 Mon Feb 6 12:13:44 2012 +++ src/sys/kern/kern_malloc.c Sat Apr 28 23:03:40 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_malloc.c,v 1.138 2012/02/06 12:13:44 drochner Exp $ */ +/* $NetBSD: kern_malloc.c,v 1.139 2012/04/28 23:03:40 rmind Exp $ */ /* * Copyright (c) 1987, 1991, 1993 @@ -65,47 +65,45 @@ * @(#)kern_malloc.c 8.4 (Berkeley) 5/20/95 */ +/* + * Wrapper interface for obsolete malloc(9). + */ + #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.138 2012/02/06 12:13:44 drochner Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.139 2012/04/28 23:03:40 rmind Exp $"); #include <sys/param.h> -#include <sys/proc.h> -#include <sys/kernel.h> #include <sys/malloc.h> #include <sys/kmem.h> -#include <sys/systm.h> -#include <sys/debug.h> -#include <sys/mutex.h> -#include <sys/lockdebug.h> #include <uvm/uvm_extern.h> -#include "opt_kmemstats.h" -#include "opt_malloclog.h" -#include "opt_malloc_debug.h" - -struct kmembuckets kmembuckets[MINBUCKET + 16]; -struct kmemusage *kmemusage; -struct malloc_type *kmemstatistics; - -kmutex_t malloc_lock; +/* + * Built-in malloc types. Note: ought to be removed. + */ +MALLOC_DEFINE(M_DEVBUF, "devbuf", "device driver memory"); +MALLOC_DEFINE(M_DMAMAP, "DMA map", "bus_dma(9) structures"); +MALLOC_DEFINE(M_FREE, "free", "should be on free list"); +MALLOC_DEFINE(M_PCB, "pcb", "protocol control block"); +MALLOC_DEFINE(M_TEMP, "temp", "misc. temporary data buffers"); +MALLOC_DEFINE(M_RTABLE, "routetbl", "routing tables"); +MALLOC_DEFINE(M_FTABLE, "fragtbl", "fragment reassembly header"); +MALLOC_DEFINE(M_UFSMNT, "UFS mount", "UFS mount structure"); +MALLOC_DEFINE(M_NETADDR, "Export Host", "Export host address structure"); +MALLOC_DEFINE(M_IPMOPTS, "ip_moptions", "internet multicast options"); +MALLOC_DEFINE(M_IPMADDR, "in_multi", "internet multicast address"); +MALLOC_DEFINE(M_MRTABLE, "mrt", "multicast routing tables"); +MALLOC_DEFINE(M_BWMETER, "bwmeter", "multicast upcall bw meters"); +/* + * Header contains total size, including the header itself. + */ struct malloc_header { - /* Total size, include the header. */ size_t mh_size; -} __aligned(ALIGNBYTES+1); +} __aligned(ALIGNBYTES + 1); -/* - * Allocate a block of memory - */ -#ifdef MALLOCLOG -void * -_kern_malloc(unsigned long size, struct malloc_type *ksp, int flags, - const char *file, long line) -#else void * kern_malloc(unsigned long size, struct malloc_type *ksp, int flags) -#endif /* MALLOCLOG */ { const int kmflags = (flags & M_NOWAIT) ? KM_NOSLEEP : KM_SLEEP; size_t allocsize, hdroffset; @@ -133,16 +131,8 @@ kern_malloc(unsigned long size, struct m return mh + 1; } -/* - * Free a block of memory allocated by malloc. - */ -#ifdef MALLOCLOG -void -_kern_free(void *addr, struct malloc_type *ksp, const char *file, long line) -#else void kern_free(void *addr, struct malloc_type *ksp) -#endif /* MALLOCLOG */ { struct malloc_header *mh; @@ -156,9 +146,6 @@ kern_free(void *addr, struct malloc_type kmem_intr_free(mh, mh->mh_size); } -/* - * Change the size of a block of memory. - */ void * kern_realloc(void *curaddr, unsigned long newsize, struct malloc_type *ksp, int flags) @@ -171,21 +158,19 @@ kern_realloc(void *curaddr, unsigned lon * realloc() with a NULL pointer is the same as malloc(). */ if (curaddr == NULL) - return (malloc(newsize, ksp, flags)); + return malloc(newsize, ksp, flags); /* * realloc() with zero size is the same as free(). */ if (newsize == 0) { free(curaddr, ksp); - return (NULL); + return NULL; } -#ifdef LOCKDEBUG if ((flags & M_NOWAIT) == 0) { ASSERT_SLEEPABLE(); } -#endif mh = curaddr; mh--; @@ -196,7 +181,7 @@ kern_realloc(void *curaddr, unsigned lon * If we already actually have as much as they want, we're done. */ if (newsize <= cursize) - return (curaddr); + return curaddr; /* * Can't satisfy the allocation with the existing block. @@ -209,7 +194,7 @@ kern_realloc(void *curaddr, unsigned lon * Return NULL to indicate that failure. The old * pointer is still valid. */ - return (NULL); + return NULL; } memcpy(newaddr, curaddr, cursize); @@ -218,81 +203,19 @@ kern_realloc(void *curaddr, unsigned lon * the new one. */ free(curaddr, ksp); - return (newaddr); + return newaddr; } -/* - * Add a malloc type to the system. - */ void malloc_type_attach(struct malloc_type *type) { - - if (type->ks_magic != M_MAGIC) - panic("malloc_type_attach: bad magic"); - -#ifdef DIAGNOSTIC - { - struct malloc_type *ksp; - for (ksp = kmemstatistics; ksp != NULL; ksp = ksp->ks_next) { - if (ksp == type) - panic("%s: `%s' already on list", __func__, - type->ks_shortdesc); - } - } -#endif - -#ifdef KMEMSTATS -#else - type->ks_limit = 0; -#endif - - type->ks_next = kmemstatistics; - kmemstatistics = type; + KASSERT(type->ks_magic == M_MAGIC); } -/* - * Remove a malloc type from the system.. - */ void malloc_type_detach(struct malloc_type *type) { - struct malloc_type *ksp; - -#ifdef DIAGNOSTIC - if (type->ks_magic != M_MAGIC) - panic("malloc_type_detach: bad magic"); -#endif - - if (type == kmemstatistics) - kmemstatistics = type->ks_next; - else { - for (ksp = kmemstatistics; ksp->ks_next != NULL; - ksp = ksp->ks_next) { - if (ksp->ks_next == type) { - ksp->ks_next = type->ks_next; - break; - } - } -#ifdef DIAGNOSTIC - if (ksp->ks_next == NULL) - panic("malloc_type_detach: not on list"); -#endif - } - type->ks_next = NULL; -} - -/* - * Set the limit on a malloc type. - */ -void -malloc_type_setlimit(struct malloc_type *type, u_long limit) -{ -#ifdef KMEMSTATS - mutex_spin_enter(&malloc_lock); - type->ks_limit = limit; - mutex_spin_exit(&malloc_lock); -#endif + KASSERT(type->ks_magic == M_MAGIC); } /* @@ -303,100 +226,8 @@ kmeminit(void) { __link_set_decl(malloc_types, struct malloc_type); struct malloc_type * const *ksp; -#ifdef KMEMSTATS - long indx; -#endif - - mutex_init(&malloc_lock, MUTEX_DEFAULT, IPL_VM); - -#ifdef KMEMSTATS - for (indx = 0; indx < MINBUCKET + 16; indx++) { - if (1 << indx >= PAGE_SIZE) - kmembuckets[indx].kb_elmpercl = 1; - else - kmembuckets[indx].kb_elmpercl = PAGE_SIZE / (1 << indx); - kmembuckets[indx].kb_highwat = - 5 * kmembuckets[indx].kb_elmpercl; - } -#endif /* Attach all of the statically-linked malloc types. */ __link_set_foreach(ksp, malloc_types) malloc_type_attach(*ksp); - -#ifdef MALLOC_DEBUG - debug_malloc_init(); -#endif -} - -#ifdef DDB -#include <ddb/db_output.h> - -/* - * Dump kmem statistics from ddb. - * - * usage: call dump_kmemstats - */ -void dump_kmemstats(void); - -void -dump_kmemstats(void) -{ -#ifdef KMEMSTATS - struct malloc_type *ksp; - - for (ksp = kmemstatistics; ksp != NULL; ksp = ksp->ks_next) { - if (ksp->ks_memuse == 0) - continue; - db_printf("%s%.*s %ld\n", ksp->ks_shortdesc, - (int)(20 - strlen(ksp->ks_shortdesc)), - " ", - ksp->ks_memuse); - } -#else - db_printf("Kmem stats are not being collected.\n"); -#endif /* KMEMSTATS */ -} -#endif /* DDB */ - - -#if 0 -/* - * Diagnostic messages about "Data modified on - * freelist" indicate a memory corruption, but - * they do not help tracking it down. - * This function can be called at various places - * to sanity check malloc's freelist and discover - * where does the corruption take place. - */ -int -freelist_sanitycheck(void) { - int i,j; - struct kmembuckets *kbp; - struct freelist *freep; - int rv = 0; - - for (i = MINBUCKET; i <= MINBUCKET + 15; i++) { - kbp = &kmembuckets[i]; - freep = (struct freelist *)kbp->kb_next; - j = 0; - while(freep) { - vm_map_lock(kmem_map); - rv = uvm_map_checkprot(kmem_map, (vaddr_t)freep, - (vaddr_t)freep + sizeof(struct freelist), - VM_PROT_WRITE); - vm_map_unlock(kmem_map); - - if ((rv == 0) || (*(int *)freep != WEIRD_ADDR)) { - printf("bucket %i, chunck %d at %p modified\n", - i, j, freep); - return 1; - } - freep = (struct freelist *)freep->next; - j++; - } - } - - return 0; } -#endif Index: src/sys/sys/malloc.h diff -u src/sys/sys/malloc.h:1.110 src/sys/sys/malloc.h:1.111 --- src/sys/sys/malloc.h:1.110 Thu Nov 24 16:16:49 2011 +++ src/sys/sys/malloc.h Sat Apr 28 23:03:40 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: malloc.h,v 1.110 2011/11/24 16:16:49 jakllsch Exp $ */ +/* $NetBSD: malloc.h,v 1.111 2012/04/28 23:03:40 rmind Exp $ */ /* * Copyright (c) 1987, 1993 @@ -34,13 +34,6 @@ #ifndef _SYS_MALLOC_H_ #define _SYS_MALLOC_H_ -#if defined(_KERNEL_OPT) -#include "opt_kmemstats.h" -#include "opt_malloclog.h" -#include "opt_malloc_debug.h" -#endif - - #ifdef _KERNEL /* @@ -61,8 +54,6 @@ MALLOC_DECLARE(M_DMAMAP); MALLOC_DECLARE(M_FREE); MALLOC_DECLARE(M_PCB); MALLOC_DECLARE(M_TEMP); - -/* XXX These should all be declared elsewhere. */ MALLOC_DECLARE(M_RTABLE); MALLOC_DECLARE(M_FTABLE); MALLOC_DECLARE(M_UFSMNT); @@ -71,6 +62,15 @@ MALLOC_DECLARE(M_IPMOPTS); MALLOC_DECLARE(M_IPMADDR); MALLOC_DECLARE(M_MRTABLE); MALLOC_DECLARE(M_BWMETER); + +void *kern_malloc(unsigned long, struct malloc_type *, int); +void *kern_realloc(void *, unsigned long, struct malloc_type *, int); +void kern_free(void *, struct malloc_type *); + +#define malloc(size, type, flags) kern_malloc(size, type, flags) +#define free(addr, type) kern_free(addr, type) +#define realloc(ptr, size, type, flags) kern_realloc(ptr, size, type, flags) + #endif /* _KERNEL */ /* @@ -87,35 +87,4 @@ struct kmembuckets { long kb_couldfree; /* over high water mark and could free */ }; -#ifdef _KERNEL -#ifdef MALLOCLOG -void *_kern_malloc(unsigned long, struct malloc_type *, int, const char *, long); -void _kern_free(void *, struct malloc_type *, const char *, long); -#define malloc(size, type, flags) \ - _kern_malloc((size), (type), (flags), __FILE__, __LINE__) -#define free(addr, type) \ - _kern_free((addr), (type), __FILE__, __LINE__) -#else -void *kern_malloc(unsigned long, struct malloc_type *, int); -void kern_free(void *, struct malloc_type *); -#define malloc(size, type, flags) kern_malloc(size, type, flags) -#define free(addr, type) kern_free(addr, type) -#endif /* MALLOCLOG */ - -#ifdef MALLOC_DEBUG -void debug_malloc_init(void); -int debug_malloc(unsigned long, struct malloc_type *, int, void **); -int debug_free(void *, struct malloc_type *); - -void debug_malloc_print(void); -void debug_malloc_printit(void (*)(const char *, ...) - __printflike(1, 2), vaddr_t); -#endif /* MALLOC_DEBUG */ - -void *kern_realloc(void *, unsigned long, struct malloc_type *, int); -#define realloc(ptr, size, type, flags) \ - kern_realloc(ptr, size, type, flags) -unsigned long - malloc_roundup(unsigned long); -#endif /* _KERNEL */ #endif /* !_SYS_MALLOC_H_ */ Index: src/sys/sys/mallocvar.h diff -u src/sys/sys/mallocvar.h:1.10 src/sys/sys/mallocvar.h:1.11 --- src/sys/sys/mallocvar.h:1.10 Sat Oct 15 21:14:57 2011 +++ src/sys/sys/mallocvar.h Sat Apr 28 23:03:40 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: mallocvar.h,v 1.10 2011/10/15 21:14:57 christos Exp $ */ +/* $NetBSD: mallocvar.h,v 1.11 2012/04/28 23:03:40 rmind Exp $ */ /* * Copyright (c) 1987, 1993 @@ -86,7 +86,6 @@ struct malloc_type type[1] = { \ void malloc_type_attach(struct malloc_type *); void malloc_type_detach(struct malloc_type *); -void malloc_type_setlimit(struct malloc_type *, u_long); #endif /* _KERNEL */ #endif /* _SYS_MALLOCVAR_H_ */