From 9e7a7fb9bc6cec11a14b32e7d5bad6cba189eebe Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 30 Jun 2011 22:34:08 +0000 Subject: [PATCH] add allocation modes --- Robust/src/Runtime/bamboo/multicoregarbage.h | 3 + Robust/src/Runtime/bamboo/multicoremem.c | 85 +++++++++++++++----- 2 files changed, 67 insertions(+), 21 deletions(-) diff --git a/Robust/src/Runtime/bamboo/multicoregarbage.h b/Robust/src/Runtime/bamboo/multicoregarbage.h index 35e95e80..6218cb0c 100644 --- a/Robust/src/Runtime/bamboo/multicoregarbage.h +++ b/Robust/src/Runtime/bamboo/multicoregarbage.h @@ -175,6 +175,9 @@ unsigned int size_cachepolicytbl; #define GCNUMBLOCK (NUMCORES4GC+(BAMBOO_SHARED_MEM_SIZE-BAMBOO_LARGE_SMEM_BOUND)/BAMBOO_SMEM_SIZE) #define GCNUMLOCALBLOCK (GCNUMBLOCK/NUMCORES4GC) +/* Leave the neighboring cores with at least two blocks */ +#define MAXNEIGHBORALLOC (GCNUMLOCALBLOCK-2) + /* This macro defines the smallest memoy chunk the master will hand out to another core during compacting */ #define MINMEMORYCHUNKSIZE 32768 diff --git a/Robust/src/Runtime/bamboo/multicoremem.c b/Robust/src/Runtime/bamboo/multicoremem.c index cc82172b..d0bfbb0c 100644 --- a/Robust/src/Runtime/bamboo/multicoremem.c +++ b/Robust/src/Runtime/bamboo/multicoremem.c @@ -7,37 +7,76 @@ #include "multicorehelper.h" #include "multicoremem_helper.h" -INLINE void * mallocmem(int tofindb, - int totest, - int size, - int * allocsize) { - void * mem = NULL; - // find suitable block - return mem; -} - // Only allocate local mem chunks to each core. // If a core has used up its local shared memory, start gc. void * localmalloc_I(int coren, - int isize, + unsigned int isize, int * allocsize) { - void * mem=globalmalloc_I(coren,isize,allocsize); - return mem; + for(block_t localblocknum=0;localblocknumstatus==BS_FREE) { + unsigned INTPTR freespace=block->freespace&~BAMBOO_CACHE_LINE_MASK; + if (freespace>=memcheck) { + //we have a block + //mark block as used + block->status=BS_USED; + void *blockptr=OFFSET2BASEVA(searchblock)+gcbaseva; + unsigned INTPTR usedspace=((block->usedspace-1)&~BAMBOO_CACHE_LINE_MASK)+BAMBOO_CACHE_LINE_SIZE; + void *startaddr=blockptr+usedspace; + *allocsize=freespace; + return startaddr; + } + } + } + + return NULL; } -#ifdef SMEMF // Allocate the local shared memory to each core with the highest priority, // if a core has used up its local shared memory, try to allocate the // shared memory that belong to its neighbours, if also failed, start gc. void * fixedmalloc_I(int coren, - int isize, + unsigned int memcheck, int * allocsize) { - void * mem=globalmalloc_I(coren,isize,allocsize); - return mem; + //try locally first + void * mem=localmalloc_I(coren,memcheck,allocsize); + if (mem!=NULL) + return mem; + + //failed try neighbors...in a round robin fashion + + int minblockindex=allocationinfo.lowestfreeblock/NUMCORES4GC; + unsigned INTPTR threshold=(desiredmemthreshold?requiredmem:threshold; + + for(block_t lblock=0;lblockstatus==BS_FREE) { + unsigned INTPTR freespace=block->freespace&~BAMBOO_CACHE_LINE_MASK; + if (memcheck<=freespace) { + //we have a block + //mark block as used + block->status=BS_USED; + void *blockptr=OFFSET2BASEVA(globalblockindex)+gcbaseva; + unsigned INTPTR usedspace=((block->usedspace-1)&~BAMBOO_CACHE_LINE_MASK)+BAMBOO_CACHE_LINE_SIZE; + *allocsize=usedspace; + return blockptr+usedspace; + } + } + } + } + } + + //no memory + return NULL; } -#endif -#ifdef SMEMM + // Allocate the local shared memory to each core with the highest priority, // if a core has used up its local shared memory, try to allocate the // shared memory that belong to its neighbours first, if failed, check @@ -47,10 +86,14 @@ void * fixedmalloc_I(int coren, void * mixedmalloc_I(int coren, int isize, int * allocsize) { - void * mem=globalmalloc_I(coren,isize,allocsize); - return mem; + void * mem=fixedmalloc_I(coren,isize,allocsize); + if (mem!=NULL) + return mem; + + //try global allocator instead + return globalmalloc_I(coren, isize, allocsite); } -#endif + // Allocate all the memory chunks globally, do not consider the host cores // When all the shared memory are used up, start gc. -- 2.34.1