From eb284828d592ce39bd4b96f084d7cce1d074d4b1 Mon Sep 17 00:00:00 2001 From: Marion Guthmuller Date: Mon, 30 Jan 2012 17:27:41 +0100 Subject: [PATCH] . --- src/xbt/mmalloc/mfree.c | 11 ++++++----- src/xbt/mmalloc/mm_legacy.c | 14 +++++++------- src/xbt/mmalloc/mmalloc.c | 9 ++++++--- src/xbt/mmalloc/mmprivate.h | 6 ++++-- src/xbt/mmalloc/mrealloc.c | 13 +++++++------ 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/xbt/mmalloc/mfree.c b/src/xbt/mmalloc/mfree.c index e9e7210d7f..53e83ce65b 100644 --- a/src/xbt/mmalloc/mfree.c +++ b/src/xbt/mmalloc/mfree.c @@ -36,9 +36,9 @@ void __mmalloc_free(struct mdesc *mdp, void *ptr) /* Get as many statistics as early as we can. */ mdp->heapstats.chunks_used--; mdp->heapstats.bytes_used -= - mdp->heapinfo[block].busy.info.size * BLOCKSIZE; + mdp->heapinfo[block].busy.info.block.size * BLOCKSIZE; mdp->heapstats.bytes_free += - mdp->heapinfo[block].busy.info.size * BLOCKSIZE; + mdp->heapinfo[block].busy.info.block.size * BLOCKSIZE; /* Find the free cluster previous to this one in the free list. Start searching at the last block referenced; this may benefit @@ -59,11 +59,11 @@ void __mmalloc_free(struct mdesc *mdp, void *ptr) /* Determine how to link this block into the free list. */ if (block == i + mdp->heapinfo[i].free.size) { /* Coalesce this block with its predecessor. */ - mdp->heapinfo[i].free.size += mdp->heapinfo[block].busy.info.size; + mdp->heapinfo[i].free.size += mdp->heapinfo[block].busy.info.block.size; block = i; } else { /* Really link this block back into the free list. */ - mdp->heapinfo[block].free.size = mdp->heapinfo[block].busy.info.size; + mdp->heapinfo[block].free.size = mdp->heapinfo[block].busy.info.block.size; mdp->heapinfo[block].free.next = mdp->heapinfo[i].free.next; mdp->heapinfo[block].free.prev = i; mdp->heapinfo[i].free.next = block; @@ -130,7 +130,8 @@ void __mmalloc_free(struct mdesc *mdp, void *ptr) next->prev = prev->prev; } mdp->heapinfo[block].busy.type = 0; - mdp->heapinfo[block].busy.info.size = 1; + mdp->heapinfo[block].busy.info.block.size = 1; + mdp->heapinfo[block].busy.info.block.busy_size = 0; /* Keep the statistics accurate. */ mdp->heapstats.chunks_used++; diff --git a/src/xbt/mmalloc/mm_legacy.c b/src/xbt/mmalloc/mm_legacy.c index c75d10b9b6..f520762bac 100644 --- a/src/xbt/mmalloc/mm_legacy.c +++ b/src/xbt/mmalloc/mm_legacy.c @@ -440,7 +440,7 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2, void *std_heap switch(mdp1->heapinfo[i].busy.type){ case 0 : - if(mdp1->heapinfo[i].busy.info.size != mdp2->heapinfo[i].busy.info.size){ + if(mdp1->heapinfo[i].busy.info.block.size != mdp2->heapinfo[i].busy.info.block.size){ if(XBT_LOG_ISENABLED(xbt_mm_legacy, xbt_log_priority_debug)){ XBT_DEBUG("Different size of a large cluster"); errors++; @@ -448,16 +448,16 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2, void *std_heap return 1; } }else{ - if(memcmp(addr_block1, addr_block2, (mdp1->heapinfo[i].busy.info.size * BLOCKSIZE)) != 0){ + if(memcmp(addr_block1, addr_block2, (mdp1->heapinfo[i].busy.info.block.size * BLOCKSIZE)) != 0){ if(XBT_LOG_ISENABLED(xbt_mm_legacy, xbt_log_priority_debug)){ - XBT_DEBUG("Different data in block %zu (size = %zu) (addr_block1 = %p (current = %p) - addr_block2 = %p)", i, mdp1->heapinfo[i].busy.info.size, addr_block1, (char *)std_heap_addr + sizeof(struct mdesc) + ((i-1) * BLOCKSIZE), addr_block2); + XBT_DEBUG("Different data in block %zu (size = %zu) (addr_block1 = %p (current = %p) - addr_block2 = %p)", i, mdp1->heapinfo[i].busy.info.block.size, addr_block1, (char *)std_heap_addr + sizeof(struct mdesc) + ((i-1) * BLOCKSIZE), addr_block2); errors++; }else{ return 1; } } } - i = i+mdp1->heapinfo[i].busy.info.size; + i = i+mdp1->heapinfo[i].busy.info.block.size; break; default : @@ -533,7 +533,7 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2, void *std_heap switch(mdp1->heapinfo[i].busy.type){ case 0 : - if(mdp1->heapinfo[i].busy.info.size != mdp2->heapinfo[i].busy.info.size){ + if(mdp1->heapinfo[i].busy.info.block.size != mdp2->heapinfo[i].busy.info.block.size){ if(XBT_LOG_ISENABLED(xbt_mm_legacy, xbt_log_priority_debug)){ XBT_DEBUG("Different size of a large cluster"); errors++; @@ -541,7 +541,7 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2, void *std_heap return 1; } }else{ - if(memcmp(addr_block1, addr_block2, (mdp1->heapinfo[i].busy.info.size * BLOCKSIZE)) != 0){ + if(memcmp(addr_block1, addr_block2, (mdp1->heapinfo[i].busy.info.block.size * BLOCKSIZE)) != 0){ if(XBT_LOG_ISENABLED(xbt_mm_legacy, xbt_log_priority_debug)){ XBT_DEBUG("Different data in block %zu (addr_block1 = %p (current = %p) - addr_block2 = %p)", i, addr_block1, (char *)std_heap_addr + sizeof(struct mdesc) + ((i-1) * BLOCKSIZE), addr_block2); errors++; @@ -551,7 +551,7 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2, void *std_heap } } - i = i+mdp1->heapinfo[i].busy.info.size; + i = i+mdp1->heapinfo[i].busy.info.block.size; break; default : diff --git a/src/xbt/mmalloc/mmalloc.c b/src/xbt/mmalloc/mmalloc.c index ab198a97d7..0af8597cfd 100644 --- a/src/xbt/mmalloc/mmalloc.c +++ b/src/xbt/mmalloc/mmalloc.c @@ -86,8 +86,9 @@ static void *morecore(struct mdesc *mdp, size_t size) mdp->heapsize * sizeof(malloc_info)); oldinfo = mdp->heapinfo; newinfo[BLOCK(oldinfo)].busy.type = 0; - newinfo[BLOCK(oldinfo)].busy.info.size + newinfo[BLOCK(oldinfo)].busy.info.block.size = BLOCKIFY(mdp->heapsize * sizeof(malloc_info)); + newinfo[BLOCK(oldinfo)].busy.info.block.busy_size = size; mdp->heapinfo = newinfo; __mmalloc_free(mdp, (void *) oldinfo); mdp->heapsize = newsize; @@ -229,7 +230,8 @@ void *mmalloc(void *md, size_t size) } block = BLOCK(result); mdp->heapinfo[block].busy.type = 0; - mdp->heapinfo[block].busy.info.size = blocks; + mdp->heapinfo[block].busy.info.block.size = blocks; + mdp->heapinfo[block].busy.info.block.busy_size = size; mdp->heapstats.chunks_used++; mdp->heapstats.bytes_used += blocks * BLOCKSIZE; return (result); @@ -262,7 +264,8 @@ void *mmalloc(void *md, size_t size) } mdp->heapinfo[block].busy.type = 0; - mdp->heapinfo[block].busy.info.size = blocks; + mdp->heapinfo[block].busy.info.block.size = blocks; + mdp->heapinfo[block].busy.info.block.busy_size = size; mdp->heapstats.chunks_used++; mdp->heapstats.bytes_used += blocks * BLOCKSIZE; mdp->heapstats.bytes_free -= blocks * BLOCKSIZE; diff --git a/src/xbt/mmalloc/mmprivate.h b/src/xbt/mmalloc/mmprivate.h index 509eaff046..d2e2331792 100644 --- a/src/xbt/mmalloc/mmprivate.h +++ b/src/xbt/mmalloc/mmprivate.h @@ -93,8 +93,10 @@ typedef union { size_t nfree; /* Free fragments in a fragmented block. */ size_t first; /* First free fragment of the block. */ } frag; - /* Size (in blocks) of a large cluster. */ - size_t size; + struct { + size_t size; /* Size (in blocks) of a large cluster. */ + size_t busy_size; + } block; } info; } busy; /* Heap information for a free block (that may be the first of diff --git a/src/xbt/mmalloc/mrealloc.c b/src/xbt/mmalloc/mrealloc.c index aeb358a863..7e83e20876 100644 --- a/src/xbt/mmalloc/mrealloc.c +++ b/src/xbt/mmalloc/mrealloc.c @@ -68,23 +68,24 @@ void *mrealloc(void *md, void *ptr, size_t size) /* The new size is a large allocation as well; see if we can hold it in place. */ blocks = BLOCKIFY(size); - if (blocks < mdp->heapinfo[block].busy.info.size) { + if (blocks < mdp->heapinfo[block].busy.info.block.size) { /* The new size is smaller; return excess memory to the free list. */ //printf("(%s) return excess memory...",xbt_thread_self_name()); mdp->heapinfo[block + blocks].busy.type = 0; - mdp->heapinfo[block + blocks].busy.info.size - = mdp->heapinfo[block].busy.info.size - blocks; - mdp->heapinfo[block].busy.info.size = blocks; + mdp->heapinfo[block + blocks].busy.info.block.size + = mdp->heapinfo[block].busy.info.block.size - blocks; + mdp->heapinfo[block].busy.info.block.size = blocks; + mdp->heapinfo[block].busy.info.block.busy_size = size; mfree(md, ADDRESS(block + blocks)); result = ptr; - } else if (blocks == mdp->heapinfo[block].busy.info.size) { + } else if (blocks == mdp->heapinfo[block].busy.info.block.size) { /* No size change necessary. */ result = ptr; } else { /* Won't fit, so allocate a new region that will. Free the old region first in case there is sufficient adjacent free space to grow without moving. */ - blocks = mdp->heapinfo[block].busy.info.size; + blocks = mdp->heapinfo[block].busy.info.block.size; /* Prevent free from actually returning memory to the system. */ oldlimit = mdp->heaplimit; mdp->heaplimit = 0; -- 2.20.1