diff --git a/include/config.h b/include/config.h index 7e38c142..5d866c75 100644 --- a/include/config.h +++ b/include/config.h @@ -130,6 +130,8 @@ #define HASHMAP_NOLOCK +//#define ALIGNED_LARGE_PAGES + #ifdef WIN32 #define sscanf sscanf_s #define sprintf sprintf_s diff --git a/src/hashmap.h b/src/hashmap.h index cd95021e..8a4dea95 100644 --- a/src/hashmap.h +++ b/src/hashmap.h @@ -56,7 +56,12 @@ namespace CTSL //Concurrent Thread Safe Library HashMap(hashFn hashSize_ = HASH_SIZE_DEFAULT) : hashSize(hashSize_) { #ifdef DISABLE_HASHBUCKET +#ifdef ALIGNED_LARGE_PAGES + hashTable = (HashNode*)aligned_large_pages_alloc(sizeof(HashNode) * hashSize); +#else hashTable = new HashNode[hashSize]; //create the key table as an array of key nodes +#endif // ALIGNED_LARGE_PAGES + memset(hashTable, 0, sizeof(HashNode) * hashSize); #else hashTable = new HashBucket[hashSize]; //create the key table as an array of key buckets @@ -65,7 +70,11 @@ namespace CTSL //Concurrent Thread Safe Library ~HashMap() { +#ifdef ALIGNED_LARGE_PAGES + aligned_large_pages_free(hashTable); +#else delete [] hashTable; +#endif } //Copy and Move of the HashMap are not supported at this moment HashMap(const HashMap&) = delete; diff --git a/src/misc.cpp b/src/misc.cpp index 1d47045d..6966bf72 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -410,6 +410,8 @@ void std_aligned_free(void *ptr) #endif } +#ifdef ALIGNED_LARGE_PAGES + /// aligned_large_pages_alloc() will return suitably aligned memory, if possible using large pages. #if defined(_WIN32) @@ -517,7 +519,7 @@ void aligned_large_pages_free(void *mem) } #endif - +#endif // ALIGNED_LARGE_PAGES namespace WinProcGroup { diff --git a/src/misc.h b/src/misc.h index 8d8756a7..ab7c127c 100644 --- a/src/misc.h +++ b/src/misc.h @@ -35,8 +35,10 @@ void prefetch_range(void *addr, size_t len); void start_logger(const std::string &fname); void* std_aligned_alloc(size_t alignment, size_t size); void std_aligned_free(void* ptr); +#ifdef ALIGNED_LARGE_PAGES void* aligned_large_pages_alloc(size_t size); // memory aligned by page size, min alignment: 4096 bytes void aligned_large_pages_free(void* mem); // nop if mem == nullptr +#endif // ALIGNED_LARGE_PAGES void dbg_hit_on(bool b); void dbg_hit_on(bool c, bool b);