From 027d955aa752674c7d524a3bba004aaa7af1d0dc Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Thu, 2 Feb 2012 21:08:51 +0100 Subject: [PATCH 1/1] improve the doc to reflect recent changes (and we already have the actual size of blocks) --- src/xbt/mmalloc/mmprivate.h | 12 ++++++++---- src/xbt/mmalloc/mrealloc.c | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/xbt/mmalloc/mmprivate.h b/src/xbt/mmalloc/mmprivate.h index e886092f75..b87c21d8b2 100644 --- a/src/xbt/mmalloc/mmprivate.h +++ b/src/xbt/mmalloc/mmprivate.h @@ -95,6 +95,11 @@ const char *xbt_thread_self_name(void); * When looking for free blocks, we traverse the mdp->heapinfo looking * for a cluster of free blocks that would be large enough. * + * The size of the cluster is only to be trusted in the first block of the cluster. + * If the cluster results of the fusion of several clusters, the previously first + * block of their cluster will have partial data. The only information kept consistent over + * all blocks of the clusters is their type (== -1). + * * Note that there is no way to determine if the block is free or busy by exploring * this structure only. It wasn't intended to be crawled for comparison and we should fix it (TODO). * @@ -103,9 +108,8 @@ const char *xbt_thread_self_name(void); * I retrieve the first block of my cluster. * * TODO: - * - add an indication of the requested size in the busy.block structure - * - add the same for each fragments - * - make room to store the backtrace of where the fragment were malloced, too. + * - add an indication of the requested size in each fragment, similarly to busy_block.busy_size + * - make room to store the backtrace of where the blocks and fragment were malloced, too. */ typedef struct { int type; /* 0: busy large block @@ -119,7 +123,7 @@ typedef struct { } busy_frag; struct { size_t size; /* Size (in blocks) of a large cluster. */ - size_t busy_size; + size_t busy_size; /* Actually used space, in bytes */ } busy_block; /* Heap information for a free block (that may be the first of a free cluster). */ struct { diff --git a/src/xbt/mmalloc/mrealloc.c b/src/xbt/mmalloc/mrealloc.c index ea4d7f6878..5928d132de 100644 --- a/src/xbt/mmalloc/mrealloc.c +++ b/src/xbt/mmalloc/mrealloc.c @@ -26,6 +26,7 @@ void *mrealloc(xbt_mheap_t mdp, void *ptr, size_t size) int type; size_t block, blocks, oldlimit; + /* Only keep real realloc and hidden malloc and free to the relevant functions */ if (size == 0) { mfree(mdp, ptr); return mmalloc(mdp, 0); @@ -33,7 +34,6 @@ void *mrealloc(xbt_mheap_t mdp, void *ptr, size_t size) return mmalloc(mdp, size); } - //printf("(%s)realloc %p to %d...",xbt_thread_self_name(),ptr,(int)size); if ((char *) ptr < (char *) mdp->heapbase || BLOCK(ptr) > mdp->heapsize) { -- 2.20.1