Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
.
authorMarion Guthmuller <marion.guthmuller@loria.fr>
Mon, 30 Jan 2012 16:27:41 +0000 (17:27 +0100)
committerMarion Guthmuller <marion.guthmuller@loria.fr>
Mon, 30 Jan 2012 16:27:41 +0000 (17:27 +0100)
src/xbt/mmalloc/mfree.c
src/xbt/mmalloc/mm_legacy.c
src/xbt/mmalloc/mmalloc.c
src/xbt/mmalloc/mmprivate.h
src/xbt/mmalloc/mrealloc.c

index e9e7210..53e83ce 100644 (file)
@@ -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 -=
     /* 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->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
 
     /* 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.  */
     /* 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.  */
       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;
       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;
         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++;
 
       /* Keep the statistics accurate.  */
       mdp->heapstats.chunks_used++;
index c75d10b..f520762 100644 (file)
@@ -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 :
        
        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++;
            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{
              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)){           
              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;
              }
            } 
          }
                errors++;
              }else{
                return 1;
              }
            } 
          }
-         i = i+mdp1->heapinfo[i].busy.info.size;
+         i = i+mdp1->heapinfo[i].busy.info.block.size;
 
          break;
        default :         
 
          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 :
        
            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++;
                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{
                  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++;
                  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 :     
 
              break;
            default :     
index ab198a9..0af8597 100644 (file)
@@ -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;
            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));
         = 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;
     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;
         }
         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);
         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.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;
     mdp->heapstats.chunks_used++;
     mdp->heapstats.bytes_used += blocks * BLOCKSIZE;
     mdp->heapstats.bytes_free -= blocks * BLOCKSIZE;
index 509eaff..d2e2331 100644 (file)
@@ -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_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
     } info;
   } busy;
   /* Heap information for a free block (that may be the first of
index aeb358a..7e83e20 100644 (file)
@@ -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);
     /* 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;
       /* 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;
       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. */
       /* 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;
       /* Prevent free from actually returning memory to the system.  */
       oldlimit = mdp->heaplimit;
       mdp->heaplimit = 0;