From owner-p4-projects@FreeBSD.ORG Sun Sep 17 15:36:12 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 3C7A816A49E; Sun, 17 Sep 2006 15:36:12 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E95FA16A47B for ; Sun, 17 Sep 2006 15:36:11 +0000 (UTC) (envelope-from howardsu@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id AC92B43D45 for ; Sun, 17 Sep 2006 15:36:11 +0000 (GMT) (envelope-from howardsu@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k8HFaBD9037918 for ; Sun, 17 Sep 2006 15:36:11 GMT (envelope-from howardsu@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k8HFaBTh037913 for perforce@freebsd.org; Sun, 17 Sep 2006 15:36:11 GMT (envelope-from howardsu@FreeBSD.org) Date: Sun, 17 Sep 2006 15:36:11 GMT Message-Id: <200609171536.k8HFaBTh037913@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to howardsu@FreeBSD.org using -f From: Howard Su To: Perforce Change Reviews Cc: Subject: PERFORCE change 106246 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Sep 2006 15:36:12 -0000 http://perforce.freebsd.org/chv.cgi?CH=106246 Change 106246 by howardsu@su_laptop on 2006/09/17 15:35:20 Reimplement vmem with a full featured idenitity management. Affected files ... .. //depot/projects/dtrace/src/sys/cddl/kern/vmem.c#3 edit .. //depot/projects/dtrace/src/sys/contrib/opensolaris/compat/sys/vmem.h#3 edit Differences ... ==== //depot/projects/dtrace/src/sys/cddl/kern/vmem.c#3 (text+ko) ==== @@ -24,46 +24,84 @@ * */ +#include #include -#include -#include +#include #include -#include #include +#include + +MALLOC_DEFINE(M_VMEM, "identiy pool", "idpool"); -MALLOC_DECLARE(M_VMEM); -MALLOC_DEFINE(M_VMEM, "vmem", "vmem hack"); +LIST_HEAD(vmem, entry); -/* XXX Hacks */ +struct entry { + char *start; + char *end; + LIST_ENTRY(entry) entries; +}; vmem_t * vmem_create(const char *name, void *base, size_t size, size_t quantum, - vmem_alloc_t *afunc, vmem_free_t *ffunc, vmem_t *source, - size_t qcache_max, int vmflag) + vmem_alloc_t *afunc, vmem_free_t *ffunc, vmem_t *source, + size_t qcache_max, int vmflag) { - return (malloc(sizeof(vmem_t), M_VMEM, M_WAITOK | M_ZERO)); + vmem_t *idpool; + struct entry *e; + e = malloc(sizeof(struct entry), M_VMEM, M_WAITOK); + idpool = malloc(sizeof(vmem_t), M_VMEM, M_WAITOK); + + e->start = base; + e->end = (char*)~0; + + LIST_INSERT_HEAD(idpool, e, entries); + return idpool; } void * vmem_alloc(vmem_t *vmp, size_t size, int vmflag) { - /* - * Hope like hell that the caller only uses the value - * returned as a long integer, not a pointer! - */ - return ((void *) ++(*vmp)); + void *ret; + struct entry *np; + np = LIST_FIRST(vmp); + ret = np->start; + if (np->start == np->end) { + LIST_REMOVE(np, entries); + free(np, M_VMEM); + } + else { + np->start++; + } + return ret; } void vmem_free(vmem_t *vmp, void *vaddr, size_t size) { - /* - * Nothing to do here. We didn't really allocate memory - * in the first place. 8-) - */ + struct entry *np, *np_temp, *newnp; + LIST_FOREACH_SAFE(np, vmp, entries, np_temp) { + if ((void*)np->end < p) continue; + + if (np->start == (char*)p + 1) { + np->start--; + return; + } + else { + newnp = malloc(sizeof(vmem_t), M_VMEM, M_WAITOK); + newnp->start = newnp->end = p; + LIST_INSERT_BEFORE(np, newnp, entries); + return; + } + } } + void vmem_destroy(vmem_t *vmp) { + struct entry *np, *np_temp; + LIST_FOREACH_SAFE(np, vmp, entries, np_temp) { + LIST_REMOVE(np, entries); + free(np, M_VMEM); + } free(vmp, M_VMEM); } ==== //depot/projects/dtrace/src/sys/contrib/opensolaris/compat/sys/vmem.h#3 (text+ko) ==== @@ -28,7 +28,8 @@ #define VM_BESTFIT 0x00000100 #define VMC_IDENTIFIER 0x00040000 /* not backed by memory */ -typedef uintptr_t vmem_t; +struct vmem; +typedef struct vmem vmem_t; typedef void *(vmem_alloc_t)(vmem_t *, size_t, int); typedef void (vmem_free_t)(vmem_t *, void *, size_t);