comparison vmalloc.c @ 140:2c8f3cf6c058

Free memory calculation
author Merten Sach <msach@mailbox.tu-berlin.de>
date Mon, 19 Sep 2011 18:43:08 +0200
parents 99798e4438a6
children 79bb48d7d93b
comparison
equal deleted inserted replaced
25:faee7dc89616 26:ecb6ab08f516
13 #include <stdio.h> 13 #include <stdio.h>
14 #include <string.h> 14 #include <string.h>
15 #include <math.h> 15 #include <math.h>
16 16
17 #include "VMS.h" 17 #include "VMS.h"
18 #include "vmalloc.h"
18 #include "Histogram/Histogram.h" 19 #include "Histogram/Histogram.h"
19 20
20 #define MAX_UINT64 0xFFFFFFFFFFFFFFFF 21 #define MAX_UINT64 0xFFFFFFFFFFFFFFFF
21 22
22 inline void 23 inline void
104 //to NULL the container is empty 105 //to NULL the container is empty
105 if(*((void**)(chunk->prevChunkInFreeList)) == NULL && getChunkSize(chunk) >= BIG_LOWER_BOUND); 106 if(*((void**)(chunk->prevChunkInFreeList)) == NULL && getChunkSize(chunk) >= BIG_LOWER_BOUND);
106 { 107 {
107 //Find the approppiate container because we do not know it 108 //Find the approppiate container because we do not know it
108 uint64 containerIdx = ((uintptr_t)chunk->prevChunkInFreeList - (uintptr_t)freeLists->bigChunks) >> 3; 109 uint64 containerIdx = ((uintptr_t)chunk->prevChunkInFreeList - (uintptr_t)freeLists->bigChunks) >> 3;
109 if(containerIdx < (uint32)64) 110 if(containerIdx < (uint64)64)
110 freeLists->bigChunksSearchVector[0] &= ~((uint64)1 << containerIdx); 111 freeLists->bigChunksSearchVector[0] &= ~((uint64)1 << containerIdx);
111 if(containerIdx < 128 && containerIdx >=64) 112 if(containerIdx < 128 && containerIdx >=64)
112 freeLists->bigChunksSearchVector[1] &= ~((uint64)1 << (containerIdx-64)); 113 freeLists->bigChunksSearchVector[1] &= ~((uint64)1 << (containerIdx-64));
113 114
114 } 115 }
249 if(freeLists->smallChunks[freeListIdx] == NULL) 250 if(freeLists->smallChunks[freeListIdx] == NULL)
250 foundChunk = searchChunk(freeLists, SMALL_CHUNK_SIZE*(freeListIdx+1), 0); 251 foundChunk = searchChunk(freeLists, SMALL_CHUNK_SIZE*(freeListIdx+1), 0);
251 else 252 else
252 foundChunk = removeSmallChunk(freeLists, freeListIdx); 253 foundChunk = removeSmallChunk(freeLists, freeListIdx);
253 254
255 _VMSMasterEnv->amtOfOutstandingMem -= getChunkSize(foundChunk) + sizeof(MallocProlog);
254 returnChunk = (MallocPrologAllocated*)foundChunk; 256 returnChunk = (MallocPrologAllocated*)foundChunk;
255 returnChunk->prevChunkInFreeList = NULL;//indicates elem currently allocated 257 returnChunk->prevChunkInFreeList = NULL;//indicates elem currently allocated
256 returnChunk->procrID = procrID; 258 returnChunk->procrID = procrID;
257 return returnChunk + 1; 259 return returnChunk + 1;
258 } 260 }
259 261
260 //Calculate the expected container. Start one higher to have a Chunk that's 262 //Calculate the expected container. Start one higher to have a Chunk that's
261 //always big enough. 263 //always big enough.
265 foundChunk = searchChunk(freeLists, sizeRequested, containerIdx); 267 foundChunk = searchChunk(freeLists, sizeRequested, containerIdx);
266 else 268 else
267 foundChunk = removeChunk(freeLists, containerIdx); 269 foundChunk = removeChunk(freeLists, containerIdx);
268 270
269 //Mark as allocated 271 //Mark as allocated
272 _VMSMasterEnv->amtOfOutstandingMem -= getChunkSize(foundChunk) + sizeof(MallocProlog);
270 returnChunk = (MallocPrologAllocated*)foundChunk; 273 returnChunk = (MallocPrologAllocated*)foundChunk;
271 returnChunk->prevChunkInFreeList = NULL;//indicates elem currently allocated 274 returnChunk->prevChunkInFreeList = NULL;//indicates elem currently allocated
272 returnChunk->procrID = procrID; 275 returnChunk->procrID = procrID;
273 276
274 //============================= MEASUREMENT STUFF ======================== 277 //============================= MEASUREMENT STUFF ========================
370 //======================================================================== 373 //========================================================================
371 374
372 MallocArrays* freeLists = _VMSMasterEnv->freeLists[procrID]; 375 MallocArrays* freeLists = _VMSMasterEnv->freeLists[procrID];
373 MallocProlog *chunkToFree = (MallocProlog*)ptrToFree - 1; 376 MallocProlog *chunkToFree = (MallocProlog*)ptrToFree - 1;
374 uint32 containerIdx; 377 uint32 containerIdx;
378 _VMSMasterEnv->amtOfOutstandingMem += getChunkSize(chunkToFree) + sizeof(MallocProlog);
375 379
376 //Check for free neighbors 380 //Check for free neighbors
377 if(chunkToFree->nextLowerInMem) 381 if(chunkToFree->nextLowerInMem)
378 { 382 {
379 if(chunkToFree->nextLowerInMem->prevChunkInFreeList != NULL) 383 if(chunkToFree->nextLowerInMem->prevChunkInFreeList != NULL)