Date: Sun, 17 Sep 2006 15:36:11 GMT From: Howard Su <howardsu@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 106246 for review Message-ID: <200609171536.k8HFaBTh037913@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <sys/cdefs.h> #include <sys/param.h> -#include <sys/systm.h> -#include <sys/types.h> +#include <sys/queue.h> #include <sys/kernel.h> -#include <sys/kmem.h> #include <sys/malloc.h> +#include <sys/vmem.h> + +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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200609171536.k8HFaBTh037913>