From owner-svn-src-user@FreeBSD.ORG Mon Jan 4 09:02:39 2010 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A2BE81065679; Mon, 4 Jan 2010 09:02:39 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 923148FC1B; Mon, 4 Jan 2010 09:02:39 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o0492db5009991; Mon, 4 Jan 2010 09:02:39 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0492dkj009987; Mon, 4 Jan 2010 09:02:39 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <201001040902.o0492dkj009987@svn.freebsd.org> From: Kip Macy Date: Mon, 4 Jan 2010 09:02:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r201476 - user/kmacy/releng_8_rump/lib/libunet X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jan 2010 09:02:39 -0000 Author: kmacy Date: Mon Jan 4 09:02:39 2010 New Revision: 201476 URL: http://svn.freebsd.org/changeset/base/201476 Log: add kmem definitions, remove kern_malloc.c due to use kmem_suballoc Modified: user/kmacy/releng_8_rump/lib/libunet/Makefile user/kmacy/releng_8_rump/lib/libunet/unet_compat.c user/kmacy/releng_8_rump/lib/libunet/unet_glue.c Modified: user/kmacy/releng_8_rump/lib/libunet/Makefile ============================================================================== --- user/kmacy/releng_8_rump/lib/libunet/Makefile Mon Jan 4 08:33:33 2010 (r201475) +++ user/kmacy/releng_8_rump/lib/libunet/Makefile Mon Jan 4 09:02:39 2010 (r201476) @@ -12,7 +12,6 @@ LIB= unet UNET_KERN_COMMON_OBJS += \ kern_environment.o \ kern_event.o \ - kern_malloc.o \ kern_mbuf.o \ kern_module.o \ kern_mtxpool.o \ Modified: user/kmacy/releng_8_rump/lib/libunet/unet_compat.c ============================================================================== --- user/kmacy/releng_8_rump/lib/libunet/unet_compat.c Mon Jan 4 08:33:33 2010 (r201475) +++ user/kmacy/releng_8_rump/lib/libunet/unet_compat.c Mon Jan 4 09:02:39 2010 (r201476) @@ -2,11 +2,30 @@ #define _WANT_UCRED #include #include +#include #include #include struct malloc_type; -#if 0 + +vm_offset_t kmem_malloc(void * map, int bytes, int wait); +void kmem_free(void *map, vm_offset_t addr, vm_size_t size); + +vm_offset_t +kmem_malloc(void * map, int bytes, int wait) +{ + + return ((vm_offset_t)mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0)); +} + + +void +kmem_free(void *map, vm_offset_t addr, vm_size_t size) +{ + + munmap((void *)addr, size); +} + void * unet_malloc(unsigned long size, struct malloc_type *type, int flags) { @@ -20,7 +39,7 @@ unet_free(void *addr, struct malloc_type free(addr); } -#endif + /* * Claim another reference to a ucred structure. */ Modified: user/kmacy/releng_8_rump/lib/libunet/unet_glue.c ============================================================================== --- user/kmacy/releng_8_rump/lib/libunet/unet_glue.c Mon Jan 4 08:33:33 2010 (r201475) +++ user/kmacy/releng_8_rump/lib/libunet/unet_glue.c Mon Jan 4 09:02:39 2010 (r201476) @@ -21,6 +21,7 @@ #include #include #include +#include SYSCTL_NODE(, 0, sysctl, CTLFLAG_RW, 0, "Sysctl internal magic"); @@ -34,6 +35,9 @@ SYSCTL_NODE(, CTL_NET, net, CTLFLAG SYSCTL_NODE(, CTL_VM, vm, CTLFLAG_RW, 0, "Virtual memory"); +MALLOC_DEFINE(M_DEVBUF, "devbuf", "device driver memory"); +MALLOC_DEFINE(M_TEMP, "temp", "misc temporary data buffers"); + int ticks; @@ -162,11 +166,10 @@ vslock(void *addr, size_t len) return (0); } -int +void vsunlock(void *addr, size_t len) { - return (0); } @@ -629,3 +632,90 @@ kproc_exit(int ecode) panic(""); } +vm_offset_t +kmem_alloc_contig(vm_map_t map, vm_size_t size, int flags, vm_paddr_t low, + vm_paddr_t high, unsigned long alignment, unsigned long boundary, + vm_memattr_t memattr) +{ + return (kmem_malloc(map, size, flags)); +} + +void +malloc_init(void *data) +{ +#ifdef notyet + struct malloc_type_internal *mtip; + struct malloc_type *mtp; + + KASSERT(cnt.v_page_count != 0, ("malloc_register before vm_init")); + + mtp = data; + if (mtp->ks_magic != M_MAGIC) + panic("malloc_init: bad malloc type magic"); + + mtip = uma_zalloc(mt_zone, M_WAITOK | M_ZERO); + mtp->ks_handle = mtip; + + mtx_lock(&malloc_mtx); + mtp->ks_next = kmemstatistics; + kmemstatistics = mtp; + kmemcount++; + mtx_unlock(&malloc_mtx); +#endif +} + +void +malloc_uninit(void *data) +{ +#ifdef notyet + struct malloc_type_internal *mtip; + struct malloc_type_stats *mtsp; + struct malloc_type *mtp, *temp; + uma_slab_t slab; + long temp_allocs, temp_bytes; + int i; + + mtp = data; + KASSERT(mtp->ks_magic == M_MAGIC, + ("malloc_uninit: bad malloc type magic")); + KASSERT(mtp->ks_handle != NULL, ("malloc_deregister: cookie NULL")); + + mtx_lock(&malloc_mtx); + mtip = mtp->ks_handle; + mtp->ks_handle = NULL; + if (mtp != kmemstatistics) { + for (temp = kmemstatistics; temp != NULL; + temp = temp->ks_next) { + if (temp->ks_next == mtp) { + temp->ks_next = mtp->ks_next; + break; + } + } + KASSERT(temp, + ("malloc_uninit: type '%s' not found", mtp->ks_shortdesc)); + } else + kmemstatistics = mtp->ks_next; + kmemcount--; + mtx_unlock(&malloc_mtx); + + /* + * Look for memory leaks. + */ + temp_allocs = temp_bytes = 0; + for (i = 0; i < MAXCPU; i++) { + mtsp = &mtip->mti_stats[i]; + temp_allocs += mtsp->mts_numallocs; + temp_allocs -= mtsp->mts_numfrees; + temp_bytes += mtsp->mts_memalloced; + temp_bytes -= mtsp->mts_memfreed; + } + if (temp_allocs > 0 || temp_bytes > 0) { + printf("Warning: memory type %s leaked memory on destroy " + "(%ld allocations, %ld bytes leaked).\n", mtp->ks_shortdesc, + temp_allocs, temp_bytes); + } + + slab = vtoslab((vm_offset_t) mtip & (~UMA_SLAB_MASK)); + uma_zfree_arg(mt_zone, mtip, slab); +#endif +}