incorporating modifications to mempool done by Gengbin
authorNikhil Jain <nikhil@illinois.edu>
Wed, 12 Oct 2011 04:44:25 +0000 (23:44 -0500)
committerNikhil Jain <nikhil@illinois.edu>
Wed, 12 Oct 2011 04:44:25 +0000 (23:44 -0500)
src/arch/util/mempool.c
src/conv-core/isomalloc.c

index 491dabbb745cc509f0bcef8fb379669bf1ea348c..d88111e954f65ba5476875ebeb585f46027ec12b 100644 (file)
@@ -145,6 +145,7 @@ void*  mempool_malloc(mempool_type *mptr, int size, int expand)
         printf("[%d] No memory has such free empty chunck of %d. expanding %p with new size %d\n", CmiMyPe(), size, expand_pool->mempool_ptr, expand_size);
 #endif
         // FIXME: go to the end of link list
+        //while (mempools_head->next != NULL && mempools_head < expand_pool) mempools_head = mempools_head->next;
         while (mempools_head->next != NULL) mempools_head = mempools_head->next;
         mempools_head->next = expand_pool;
 
@@ -154,13 +155,13 @@ void*  mempool_malloc(mempool_type *mptr, int size, int expand)
         bestfit->next_free = 0;
         bestfit_size = expand_size-sizeof(mempool_block);
 #if 0
-        current = freelist_head;
+        current = freelist_head_ptr;
         while(current!= NULL && current < bestfit )
         {
           previous = current;
-          current = current->next;
+          current = current->next_free?(mempool_header*)((char *)mptr + current->next_free):NULL;
         }
-#else
+#elif 0
         CmiAssert(bestfit > previous);
 #endif
         bestfit_previous = previous;
@@ -230,7 +231,23 @@ void mempool_free(mempool_type *mptr, void *ptr_free)
     printf("[%d] INSIDE FREE ptr=%p, size=%d freehead=%p mutex: %p\n", CmiMyPe(), to_free, free_size, freelist_head, mptr->mutex);
 #endif
     
-    while(current!= NULL && current < to_free )
+    /*while(current!= NULL && current < to_free )
+    {
+#if  MEMPOOL_DEBUG
+        CmiPrintf("[%d] previous=%p, current=%p size:%d %p\n", CmiMyPe(), previous, current, current->size, (char*)current+current->size);
+#endif
+        previous = current;
+        current = current->next_free?(mempool_header*)((char*)mptr + current->next_free):NULL;
+    }*/
+    while(current!= NULL && memcmp(&current->mem_hndl, &to_free->mem_hndl, sizeof(gni_mem_handle_t))!=0)
+    {
+#if  MEMPOOL_DEBUG
+        CmiPrintf("[%d] previous=%p, current=%p size:%d %p\n", CmiMyPe(), previous, current, current->size, (char*)current+current->size);
+#endif
+        previous = current;
+        current = current->next_free?(mempool_header*)((char*)mptr + current->next_free):NULL;
+    }
+    while(current!= NULL && current < to_free && memcmp(&current->mem_hndl, &to_free->mem_hndl, sizeof(gni_mem_handle_t))==0)
     {
 #if  MEMPOOL_DEBUG
         CmiPrintf("[%d] previous=%p, current=%p size:%d %p\n", CmiMyPe(), previous, current, current->size, (char*)current+current->size);
@@ -242,7 +259,7 @@ void mempool_free(mempool_type *mptr, void *ptr_free)
     if (current) CmiPrintf("[%d] previous=%p, current=%p size:%d %p\n", CmiMyPe(), previous, current, current->size, free_lastbytes_pos);
 #endif
     //continuos with previous free space 
-    if(previous!= NULL && (char*)previous+previous->size == to_free &&  memcmp(&previous->mem_hndl, &to_free->mem_hndl, sizeof(gni_mem_handle_t))==0 )
+    if(previous!= NULL && (char*)previous+previous->size == (char*)to_free &&  memcmp(&previous->mem_hndl, &to_free->mem_hndl, sizeof(gni_mem_handle_t))==0 )
     {
         previous->size +=  free_size;
         merged = 1;
index 4903e675eca5b8ddb8877c2b4eaecd9084cc6008..d0db65d03df304f68b7a93da55b8bc2bccf55fdf 100644 (file)
@@ -1650,7 +1650,7 @@ CpvStaticDeclare(slotset *, myss); /*My managed slots*/
 CtvStaticDeclare(mempool_type *, threadpool); /*Thread managed pools*/
 
 //alloc function to be used by mempool
-void * isomallocfn (size_t *size, gni_mem_handle_t *mem_hndl)
+void * isomallocfn (size_t *size, mem_handle_t *mem_hndl)
 {
   CmiInt8 s,n,i;
   void *newaddr;
@@ -1678,7 +1678,7 @@ void * isomallocfn (size_t *size, gni_mem_handle_t *mem_hndl)
 }
 
 //free function to be used by mempool
-void isofreefn(void *ptr, gni_mem_handle_t mem_hndl)
+void isofreefn(void *ptr, mem_handle_t mem_hndl)
 {
   call_munmap(ptr, ((mempool_block *)ptr)->size);
 }
@@ -2536,6 +2536,7 @@ static void print_myslots();
 #if USE_MEMPOOL_ISOMALLOC
 void CmiIsomallocBlockListPup(pup_er p,CmiIsomallocBlockList **lp, CthThread tid)
 {
+  mempool_type *mptr;
   mempool_block *current, *mempools_head;
   void *newblock;
   CmiInt8 slot;
@@ -2546,10 +2547,12 @@ void CmiIsomallocBlockListPup(pup_er p,CmiIsomallocBlockList **lp, CthThread tid
 #if ISOMALLOC_DEBUG
     printf("My rank is %d Pupping for %d \n",CthSelf(),tid);
 #endif
+    mptr = CtvAccessOther(tid,threadpool);
     current = &(CtvAccessOther(tid,threadpool)->mempools_head);
     while(current != NULL) {
       numBlocks++;
-      current = current->next;
+      current = current->memblock_next?(mempool_block *)((char*)mptr+current->memblock_next):NULL;
+      //current = current->next;
     }
 #if ISOMALLOC_DEBUG
     printf("Number of blocks packed %d\n",numBlocks);
@@ -2563,7 +2566,8 @@ void CmiIsomallocBlockListPup(pup_er p,CmiIsomallocBlockList **lp, CthThread tid
 #if ISOMALLOC_DEBUG
       printf("[%d] Packing slot %lld size %d at %p to %p\n",CmiMyPe(),current->mem_hndl,current->size,current->mempool_ptr,current->mempool_ptr+current->size);
 #endif
-      current = current->next;
+      current = current->memblock_next?(mempool_block *)((char*)mptr+current->memblock_next):NULL;
+      //current = current->next;
     }
   }