From efe5bc6a3cb7f2069646883f29a16d3f345f74f8 Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Sat, 9 May 2020 22:27:56 -0400 Subject: [PATCH] Split allocator cache into two pools of different sizes --- Grid/allocator/AlignedAllocator.cc | 69 +++++++++++++++--------------- Grid/allocator/AlignedAllocator.h | 17 ++++---- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/Grid/allocator/AlignedAllocator.cc b/Grid/allocator/AlignedAllocator.cc index d53c4dc2..77646410 100644 --- a/Grid/allocator/AlignedAllocator.cc +++ b/Grid/allocator/AlignedAllocator.cc @@ -6,21 +6,19 @@ NAMESPACE_BEGIN(Grid); MemoryStats *MemoryProfiler::stats = nullptr; bool MemoryProfiler::debug = false; -#ifdef GRID_NVCC -#define SMALL_LIMIT (0) -#else -#define SMALL_LIMIT (4096) -#endif - -#ifdef POINTER_CACHE -int PointerCache::victim; - +int PointerCache::Victim; +int PointerCache::VictimSmall; PointerCache::PointerCacheEntry PointerCache::Entries[PointerCache::Ncache]; +PointerCache::PointerCacheEntry PointerCache::EntriesSmall[PointerCache::NcacheSmall]; -void *PointerCache::Insert(void *ptr,size_t bytes) { - - if (bytes < SMALL_LIMIT ) return ptr; - +void *PointerCache::Insert(void *ptr,size_t bytes) +{ + if (bytes < GRID_ALLOC_SMALL_LIMIT ) + return Insert(ptr,bytes,EntriesSmall,NcacheSmall,VictimSmall); + return Insert(ptr,bytes,Entries,Ncache,Victim); +} +void *PointerCache::Insert(void *ptr,size_t bytes,PointerCacheEntry *entries,int ncache,int &victim) +{ #ifdef GRID_OMP assert(omp_in_parallel()==0); #endif @@ -28,8 +26,8 @@ void *PointerCache::Insert(void *ptr,size_t bytes) { void * ret = NULL; int v = -1; - for(int e=0;e #define POINTER_CACHE #define GRID_ALLOC_ALIGN (2*1024*1024) +#define GRID_ALLOC_SMALL_LIMIT (4096) NAMESPACE_BEGIN(Grid); // Move control to configure.ac and Config.h? -#ifdef POINTER_CACHE + class PointerCache { private: /*Pinning pages is costly*/ /*Could maintain separate large and small allocation caches*/ -#ifdef GRID_NVCC - static const int Ncache=128; -#else +/* Could make these configurable, perhaps up to a max size*/ + static const int NcacheSmall=128; static const int Ncache=8; -#endif - static int victim; typedef struct { void *address; @@ -65,14 +63,17 @@ private: } PointerCacheEntry; static PointerCacheEntry Entries[Ncache]; + static int Victim; + static PointerCacheEntry EntriesSmall[NcacheSmall]; + static int VictimSmall; public: static void *Insert(void *ptr,size_t bytes) ; + static void *Insert(void *ptr,size_t bytes,PointerCacheEntry *entries,int ncache,int &victim) ; static void *Lookup(size_t bytes) ; - + static void *Lookup(size_t bytes,PointerCacheEntry *entries,int ncache) ; }; -#endif std::string sizeString(size_t bytes);