Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
diff vmalloc.c @ 134:a9b72021f053
Distributed memory management w/o free requests working
| author | Merten Sach <msach@mailbox.tu-berlin.de> |
|---|---|
| date | Fri, 16 Sep 2011 16:19:24 +0200 |
| parents | dbfc8382d546 |
| children | 0b49fd35afc1 |
line diff
1.1 --- a/vmalloc.c Fri Sep 16 14:26:18 2011 +0200 1.2 +++ b/vmalloc.c Fri Sep 16 16:19:24 2011 +0200 1.3 @@ -12,7 +12,7 @@ 1.4 #include <stdlib.h> 1.5 #include <stdio.h> 1.6 1.7 -#include "ProcrContext.h" 1.8 +#include "VMS.h" 1.9 #include "Histogram/Histogram.h" 1.10 1.11 /*Helper function 1.12 @@ -70,6 +70,8 @@ 1.13 MallocPrologAllocated *returnElem; 1.14 ssize_t amountExtra, sizeConsumed,sizeOfFound; 1.15 uint32 foundElemIsTopOfHeap; 1.16 + 1.17 + printf("Malloc on core %d\n", procrID); 1.18 1.19 //============================= MEASUREMENT STUFF ======================== 1.20 #ifdef MEAS__TIME_MALLOC 1.21 @@ -80,7 +82,7 @@ 1.22 1.23 //step up the size to be aligned at 16-byte boundary, prob better ways 1.24 sizeRequested = (sizeRequested + 16) & ~15; 1.25 - currElem = (_VMSMasterEnv->freeListHead[_VMSMasterEnv->currentMasterProcrID]) 1.26 + currElem = (_VMSMasterEnv->freeListHead[procrID]) 1.27 ->nextChunkInFreeList; 1.28 1.29 while( currElem != NULL ) 1.30 @@ -105,7 +107,7 @@ 1.31 // save addr of start of heap in head's nextLowerInMem 1.32 //Will handle top of Heap specially 1.33 foundElemIsTopOfHeap = foundElem->nextHigherInMem == 1.34 - _VMSMasterEnv->freeListHead->nextHigherInMem; 1.35 + _VMSMasterEnv->freeListHead[procrID]->nextHigherInMem; 1.36 1.37 //before shave off and try to insert new elem, remove found elem 1.38 //note, foundElem will never be the head, so always has valid prevChunk 1.39 @@ -124,14 +126,14 @@ 1.40 { //make new elem by adding to addr of curr elem then casting 1.41 sizeConsumed = sizeof(MallocProlog) + sizeRequested; 1.42 newElem = (MallocProlog *)( (uintptr_t)returnElem + sizeConsumed ); 1.43 - newElem->nextLowerInMem = returnElem; //This is evil (but why?) 1.44 - newElem->nextHigherInMem = returnElem->nextHigherInMem; //This is evil (but why?) 1.45 + newElem->nextLowerInMem = (MallocProlog*)returnElem; 1.46 + newElem->nextHigherInMem = returnElem->nextHigherInMem; 1.47 returnElem->nextHigherInMem = newElem; 1.48 if( ! foundElemIsTopOfHeap ) 1.49 { //there is no next higher for top of heap, so can't write to it 1.50 newElem->nextHigherInMem->nextLowerInMem = newElem; 1.51 } 1.52 - add_chunk_to_free_list( newElem, _VMSMasterEnv->freeListHead ); 1.53 + add_chunk_to_free_list( newElem, _VMSMasterEnv->freeListHead[procrID] ); 1.54 } 1.55 else 1.56 { 1.57 @@ -158,7 +160,7 @@ 1.58 void 1.59 VMS__free(void *ptrToFree) 1.60 { 1.61 - MallocPrologAllocated chunk = (MallocPrologAllocated*)ptrToFree - 1; 1.62 + MallocPrologAllocated *chunk = (MallocPrologAllocated*)ptrToFree - 1; 1.63 if(chunk->procrID == _VMSMasterEnv->currentMasterProcrID) 1.64 { 1.65 VMS__free_on_core(ptrToFree, _VMSMasterEnv->currentMasterProcrID); 1.66 @@ -177,7 +179,8 @@ 1.67 void 1.68 VMS__free_in_lib(void *ptrToFree, VirtProcr *VProc) 1.69 { 1.70 - MallocPrologAllocated chunk = (MallocPrologAllocated*)ptrToFree - 1; 1.71 + MallocPrologAllocated *chunk = (MallocPrologAllocated*)ptrToFree - 1; 1.72 + printf("Free from core %d for core %d\n", VProc->coreAnimatedBy, chunk->procrID); 1.73 if(chunk->procrID == VProc->coreAnimatedBy) 1.74 { 1.75 VMS__free_on_core(ptrToFree, VProc->coreAnimatedBy); 1.76 @@ -206,9 +209,11 @@ 1.77 saveLowTimeStampCountInto( startStamp ); 1.78 #endif 1.79 //======================================================================== 1.80 + 1.81 + MallocProlog* masterListHead = _VMSMasterEnv->freeListHead[procrID]; 1.82 1.83 - if( ptrToFree < (void*)_VMSMasterEnv->freeListHead->nextLowerInMem || 1.84 - ptrToFree > (void*)_VMSMasterEnv->freeListHead->nextHigherInMem ) 1.85 + if( ptrToFree < (void*)masterListHead->nextLowerInMem || 1.86 + ptrToFree > (void*)masterListHead->nextHigherInMem ) 1.87 { //outside the range of data owned by VMS's malloc, so do nothing 1.88 return; 1.89 } 1.90 @@ -250,7 +255,7 @@ 1.91 // changes size of the lower elem, which is still in free-list 1.92 nextLowerElem->nextHigherInMem = nextHigherElem->nextHigherInMem; 1.93 if( nextHigherElem->nextHigherInMem != 1.94 - _VMSMasterEnv->freeListHead->nextHigherInMem ) 1.95 + masterListHead->nextHigherInMem ) 1.96 nextHigherElem->nextHigherInMem->nextLowerInMem = nextLowerElem; 1.97 //notice didn't do anything to elemToFree -- it simply is no 1.98 // longer reachable from any of the lists. Wonder if could be a 1.99 @@ -263,7 +268,7 @@ 1.100 // By side-effect, changes size of the lower elem 1.101 nextLowerElem->nextHigherInMem = elemToFree->nextHigherInMem; 1.102 if( elemToFree->nextHigherInMem != 1.103 - _VMSMasterEnv->freeListHead->nextHigherInMem ) 1.104 + masterListHead->nextHigherInMem ) 1.105 elemToFree->nextHigherInMem->nextLowerInMem = nextLowerElem; 1.106 } 1.107 } 1.108 @@ -280,18 +285,18 @@ 1.109 //Now chg mem-list. By side-effect, changes size of elemToFree 1.110 elemToFree->nextHigherInMem = nextHigherElem->nextHigherInMem; 1.111 if( elemToFree->nextHigherInMem != 1.112 - _VMSMasterEnv->freeListHead->nextHigherInMem ) 1.113 + masterListHead->nextHigherInMem ) 1.114 elemToFree->nextHigherInMem->nextLowerInMem = elemToFree; 1.115 } 1.116 else 1.117 { //neither lower nor higher is availabe to coalesce so add to list 1.118 // this makes prev chunk ptr non-null, which indicates it's free 1.119 elemToFree->nextChunkInFreeList = 1.120 - _VMSMasterEnv->freeListHead->nextChunkInFreeList; 1.121 - _VMSMasterEnv->freeListHead->nextChunkInFreeList = elemToFree; 1.122 + masterListHead->nextChunkInFreeList; 1.123 + masterListHead->nextChunkInFreeList = elemToFree; 1.124 if( elemToFree->nextChunkInFreeList != NULL ) // end-of-list? 1.125 elemToFree->nextChunkInFreeList->prevChunkInFreeList =elemToFree; 1.126 - elemToFree->prevChunkInFreeList = _VMSMasterEnv->freeListHead; 1.127 + elemToFree->prevChunkInFreeList = masterListHead; 1.128 } 1.129 } 1.130 //============================= MEASUREMENT STUFF ======================== 1.131 @@ -376,6 +381,7 @@ 1.132 //Note, this is running in the main thread -- all increases in malloc 1.133 // mem and all frees of it must be done in this thread, with the 1.134 // thread's original stack available 1.135 + 1.136 freeListHead = malloc( sizeof(MallocProlog) ); 1.137 firstChunk = malloc( MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE ); 1.138 if( firstChunk == NULL ) {printf("malloc error\n"); exit(1);} 1.139 @@ -412,12 +418,15 @@ 1.140 /*Designed to be called from the main thread outside of VMS, during cleanup 1.141 */ 1.142 void 1.143 -VMS_ext__free_free_list( MallocProlog *freeListHead ) 1.144 +VMS_ext__free_free_list( MallocProlog* freeListHeads[] ) 1.145 { 1.146 //stashed a ptr to the one and only bug chunk malloc'd from OS in the 1.147 // free list head's next lower in mem pointer 1.148 - free( freeListHead->nextLowerInMem ); 1.149 - 1.150 + int i; 1.151 + for(i=0; i<NUM_CORES; i++) 1.152 + { 1.153 + free( freeListHeads[i]->nextLowerInMem ); 1.154 + } 1.155 //don't free the head -- it'll be in an array eventually -- free whole 1.156 // array when all the free lists linked from it have already been freed 1.157 }
