changeset 175:de5e7c522f1f false_sharing

aligned memory allocation
author Merten Sach <msach@mailbox.tu-berlin.de>
date Tue, 20 Dec 2011 19:17:11 +0100
parents c3f458403cd6
children cf5faa15cb4d
files VMS.c VMS_defs.h vmalloc.c
diffstat 3 files changed, 6 insertions(+), 4 deletions(-) [+]
line diff
     1.1 --- a/VMS.c	Tue Dec 20 16:50:21 2011 +0100
     1.2 +++ b/VMS.c	Tue Dec 20 19:17:11 2011 +0100
     1.3 @@ -193,7 +193,7 @@
     1.4     for( i = 0; i < NUM_SCHED_SLOTS; i++ )
     1.5      {
     1.6        //schedSlots[i] = VMS__malloc( sizeof(SchedSlot) );
     1.7 -       posix_memalign(&schedSlots[i], CACHELINE_SIZE, sizeof(SchedSlot) );
     1.8 +       posix_memalign(&schedSlots[i], CACHELINE_SIZE, CACHELINE_SIZE );
     1.9  
    1.10           //Set state to mean "handling requests done, slot needs filling"
    1.11        schedSlots[i]->workIsDone         = FALSE;
     2.1 --- a/VMS_defs.h	Tue Dec 20 16:50:21 2011 +0100
     2.2 +++ b/VMS_defs.h	Tue Dec 20 19:17:11 2011 +0100
     2.3 @@ -18,7 +18,7 @@
     2.4  #define __align_to_cacheline__ __attribute__ ((aligned(CACHELINE_SIZE)))
     2.5  //aligns a pointer to cacheline. The memory area has to contain at least
     2.6  //CACHELINE_SIZE bytes more then needed
     2.7 -//#define __align_adress(ptr) (void*)(((uintptr_t)(ptr))&((uintptr_t)(!0x0FF)))+256
     2.8 +#define __align_adress(ptr) ((void*)(((uintptr_t)(ptr))&((uintptr_t)(~0x0FF))))
     2.9  
    2.10  //===============================  Debug  ===================================
    2.11  //
     3.1 --- a/vmalloc.c	Tue Dec 20 16:50:21 2011 +0100
     3.2 +++ b/vmalloc.c	Tue Dec 20 19:17:11 2011 +0100
     3.3 @@ -141,7 +141,9 @@
     3.4  MallocProlog *divideChunk(MallocProlog* chunk, size_t newSize)
     3.5  {
     3.6      MallocProlog* newChunk = (MallocProlog*)((uintptr_t)chunk->nextHigherInMem -
     3.7 -            newSize - sizeof(MallocProlog));
     3.8 +            newSize);
     3.9 +    
    3.10 +    newChunk = __align_adress((uintptr_t)newChunk+CACHELINE_SIZE-1)-sizeof(MallocProlog);
    3.11      
    3.12      newChunk->nextLowerInMem  = chunk;
    3.13      newChunk->nextHigherInMem = chunk->nextHigherInMem;
    3.14 @@ -212,7 +214,7 @@
    3.15     #endif
    3.16     //========================================================================
    3.17     
    3.18 -   sizeRequested += CACHELINE_SIZE; //Allocate more than cacheline_size to avoid false sharing
    3.19 +   sizeRequested += (2*CACHELINE_SIZE); //Allocate more than cacheline_size to avoid false sharing
    3.20     
    3.21     MallocArrays* freeLists = _VMSMasterEnv->freeLists;
    3.22     MallocProlog* foundChunk;