Minor change in mempool - saving size as power of two in slots
authorNikhil Jain <nikhil@illinois.edu>
Sun, 1 Jan 2012 08:19:14 +0000 (02:19 -0600)
committerNikhil Jain <nikhil@illinois.edu>
Sun, 1 Jan 2012 08:19:14 +0000 (02:19 -0600)
rather in terms of absolute number, corresponding changes
done in isomalloc

src/arch/util/mempool.c
src/arch/util/mempool.h
src/conv-core/isomalloc.c
tests/converse/commbench/reduction.c

index a337bb9502690f94808ba59b0f574ca6651e9753..c22ed57099e69ca9837cd0c819e0a6a46790ba9f 100644 (file)
@@ -1,7 +1,12 @@
 
 /** 
 
-Memory pool implementation , It is only good for Charm++ usage. The first 64 bytes provides additional information. sizeof(int)- size of this block(free or allocated), next mem_handle_t, then void** point to the next available block. 
+Memory pool implementation. It is used in two places-
+1 - For UGNI management of pinned memory
+2 - Isomalloc allocation
+
+Memory is allocated in terms of blocks from the OS and the user
+is given back memory after rounding to nearest power of 2.
 
 Written by Yanhua Sun 08-27-2011
 Generalized by Gengbin Zheng  10/5/2011
@@ -25,11 +30,6 @@ Heavily modified by Nikhil Jain 11/28/2011
 #endif
 
 #include "mempool.h"
-int cutOffPoints[] = {64,128,256,512,1024,2048,4096, 8192,16384,32768,
-                      65536,131072,262144,524288,1048576,2097152,4194304,
-                      8388608,16777216,33554432,67108864,134217728,268435456,
-                      536870912};
-
 
 INLINE_KEYWORD int which_pow2(size_t size)
 {
@@ -82,7 +82,7 @@ INLINE_KEYWORD void fillblock(mempool_type *mptr,block_header *block_head,int po
   for(i=power; i>=0; i--) {
     if(block_head->freelists[i]) {
       head = (slot_header*)((char*)mptr+block_head->freelists[i]);
-      head->size = cutOffPoints[i];
+      head->size = i;
       head->status = 1;
 #if CMK_CONVERSE_GEMINI_UGNI
       head->mempool_ptr = pool;
@@ -124,7 +124,7 @@ int checkblock(mempool_type *mptr,block_header *current,int power)
         current->freelists[i] = loc;
       }
 
-      head_move->size = cutOffPoints[power];
+      head_move->size = power;
       prev = current->freelists[power];
       head_move->next = prev+cutOffPoints[power]; 
       head = (slot_header*)((char*)head_move+cutOffPoints[power]);
@@ -132,7 +132,7 @@ int checkblock(mempool_type *mptr,block_header *current,int power)
         if(i!=power) {
           head = (slot_header*)((char*)head+cutOffPoints[i-1]);
         }
-        head->size = cutOffPoints[i];
+        head->size = i;
         head->status = 1;
 #if CMK_CONVERSE_GEMINI_UGNI
         head->mempool_ptr = current->mempool_ptr;
@@ -329,7 +329,7 @@ void mempool_free(mempool_type *mptr, void *ptr_free)
     //by maintaining extra 8 bytes in slot_header but I am
     //currently doing it by linear search for gemini
     block_head = &mptr->block_head;
-    while(1 && block_head != NULL) {
+    while(block_head != NULL) {
       if((size_t)ptr_free >= (size_t)(block_head->mempool_ptr)
         && (size_t)ptr_free < (size_t)((char*)block_head->mempool_ptr 
         + block_head->size)) {
@@ -350,17 +350,17 @@ void mempool_free(mempool_type *mptr, void *ptr_free)
     size = 0;
     current = to_free;
     while(current->status == 1) {
-      size += current->size;
+      size += cutOffPoints[current->size];
       first = current;
       current = current->gprev?(slot_header*)((char*)mptr+current->gprev):NULL;
       if(current == NULL)
         break;
     }
 
-    size -= to_free->size;
+    size -= cutOffPoints[to_free->size];
     current = to_free;
     while(current->status == 1) {
-      size += current->size;
+      size += cutOffPoints[current->size];
       current = current->gnext?(slot_header*)((char*)mptr+current->gnext):NULL;
       if(current == NULL)
         break;
@@ -372,7 +372,7 @@ void mempool_free(mempool_type *mptr, void *ptr_free)
     current = first;
     while(current!=used_next) {
       if(current!=to_free) {
-        power = which_pow2(current->size);
+        power = current->size;
         temp = current->prev?(slot_header*)((char*)mptr+current->prev):NULL;
         if(temp!=NULL) {
           temp->next = current->next;
@@ -403,7 +403,7 @@ void mempool_free(mempool_type *mptr, void *ptr_free)
     for(i=power; i>=0; i--) {
       if(left>=cutOffPoints[i]) {
         current = (slot_header*)((char*)mptr+loc);
-        current->size = cutOffPoints[i];
+        current->size = i;
         current->status = 1;
 #if CMK_CONVERSE_GEMINI_UGNI
        current->mempool_ptr = block_head->mempool_ptr;
index 0a28cf65f223eff9c21783224f0a12f4a4f80846..0337ca180f1db36a4a67a1a7ab5fed3eca3a758a 100644 (file)
@@ -19,6 +19,12 @@ typedef void * (* mempool_newblockfn)(size_t *size, mem_handle_t *mem_hndl, int
 typedef void (* mempool_freeblock)(void *ptr, mem_handle_t mem_hndl);
 
 #define cutOffNum 24 
+static int cutOffPoints[] = {64,128,256,512,1024,2048,4096, 8192,16384,32768,
+                      65536,131072,262144,524288,1048576,2097152,4194304,
+                      8388608,16777216,33554432,67108864,134217728,268435456,
+                      536870912};
+
+
 
 //header of an free slot
 typedef struct slot_header_
index a7da4f773fb06c0ac30b96709db3b9c1c63a961d..6daa15c96b4c49a52bf93e1648440ea170a2361b 100644 (file)
@@ -2590,13 +2590,13 @@ void CmiIsomallocBlockListPup(pup_er p,CmiIsomallocBlockList **lp, CthThread tid
         currSlot = (slot_header*)((char*)current+sizeof(block_header));
       }
       while(currSlot != NULL) {
-        pup_int(p,&currSlot->size);
+        pup_int(p,&cutOffPoints[currSlot->size]);
         if(currSlot->status) {
           pup_int(p,&flags[0]);
           pup_bytes(p,(void*)currSlot,sizeof(slot_header));
         } else {
           pup_int(p,&flags[1]);
-          pup_bytes(p,(void*)currSlot,currSlot->size);
+          pup_bytes(p,(void*)currSlot,cutOffPoints[currSlot->size]);
         }
         currSlot = currSlot->gnext?(slot_header*)((char*)mptr+currSlot->gnext):NULL;
       }
index 114e74f68c2fc7803f35bde1186e4359eeb6de82..33d1f03368b842f9bdafdbf4af0c5d7d98291370 100644 (file)
@@ -65,8 +65,6 @@ typedef struct _timemsg {
 
 typedef struct _timemsg timemsg;
 
-
-
 static char *sync_outstr =
 "[broadcast] (%s) %le seconds per %d bytes\n"
 ;