# HG changeset patch # User Merten Sach # Date 1324405031 -3600 # Node ID de5e7c522f1ff03e34528b5dcf59ec6a33e54a11 # Parent c3f458403cd6441e3d4b1db1471990b78d9a525c aligned memory allocation diff -r c3f458403cd6 -r de5e7c522f1f VMS.c --- a/VMS.c Tue Dec 20 16:50:21 2011 +0100 +++ b/VMS.c Tue Dec 20 19:17:11 2011 +0100 @@ -193,7 +193,7 @@ for( i = 0; i < NUM_SCHED_SLOTS; i++ ) { //schedSlots[i] = VMS__malloc( sizeof(SchedSlot) ); - posix_memalign(&schedSlots[i], CACHELINE_SIZE, sizeof(SchedSlot) ); + posix_memalign(&schedSlots[i], CACHELINE_SIZE, CACHELINE_SIZE ); //Set state to mean "handling requests done, slot needs filling" schedSlots[i]->workIsDone = FALSE; diff -r c3f458403cd6 -r de5e7c522f1f VMS_defs.h --- a/VMS_defs.h Tue Dec 20 16:50:21 2011 +0100 +++ b/VMS_defs.h Tue Dec 20 19:17:11 2011 +0100 @@ -18,7 +18,7 @@ #define __align_to_cacheline__ __attribute__ ((aligned(CACHELINE_SIZE))) //aligns a pointer to cacheline. The memory area has to contain at least //CACHELINE_SIZE bytes more then needed -//#define __align_adress(ptr) (void*)(((uintptr_t)(ptr))&((uintptr_t)(!0x0FF)))+256 +#define __align_adress(ptr) ((void*)(((uintptr_t)(ptr))&((uintptr_t)(~0x0FF)))) //=============================== Debug =================================== // diff -r c3f458403cd6 -r de5e7c522f1f vmalloc.c --- a/vmalloc.c Tue Dec 20 16:50:21 2011 +0100 +++ b/vmalloc.c Tue Dec 20 19:17:11 2011 +0100 @@ -141,7 +141,9 @@ MallocProlog *divideChunk(MallocProlog* chunk, size_t newSize) { MallocProlog* newChunk = (MallocProlog*)((uintptr_t)chunk->nextHigherInMem - - newSize - sizeof(MallocProlog)); + newSize); + + newChunk = __align_adress((uintptr_t)newChunk+CACHELINE_SIZE-1)-sizeof(MallocProlog); newChunk->nextLowerInMem = chunk; newChunk->nextHigherInMem = chunk->nextHigherInMem; @@ -212,7 +214,7 @@ #endif //======================================================================== - sizeRequested += CACHELINE_SIZE; //Allocate more than cacheline_size to avoid false sharing + sizeRequested += (2*CACHELINE_SIZE); //Allocate more than cacheline_size to avoid false sharing MallocArrays* freeLists = _VMSMasterEnv->freeLists; MallocProlog* foundChunk;