diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-06-29 14:56:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-29 14:56:55 +0200 |
commit | 4525c30d10357706eaac1e151204a612f8d49056 (patch) | |
tree | 279ee29858cf27cc12c75d6ab002289321afb4bd /vespamalloc | |
parent | efe1bc39bad0169e7f508d227dd98790ea7a0780 (diff) | |
parent | bb00676ae9d58e54e7079a7844250d50bd350682 (diff) |
Merge pull request #18458 from vespa-engine/balder/gc-unused-code
Balder/gc unused code
Diffstat (limited to 'vespamalloc')
-rw-r--r-- | vespamalloc/etc/vespamalloc.conf | 4 | ||||
-rw-r--r-- | vespamalloc/src/vespamalloc/malloc/common.h | 18 | ||||
-rw-r--r-- | vespamalloc/src/vespamalloc/malloc/datasegment.h | 6 | ||||
-rw-r--r-- | vespamalloc/src/vespamalloc/malloc/datasegment.hpp | 3 | ||||
-rw-r--r-- | vespamalloc/src/vespamalloc/malloc/globalpool.h | 7 | ||||
-rw-r--r-- | vespamalloc/src/vespamalloc/malloc/globalpool.hpp | 60 | ||||
-rw-r--r-- | vespamalloc/src/vespamalloc/malloc/malloc.h | 23 | ||||
-rw-r--r-- | vespamalloc/src/vespamalloc/malloc/memorywatcher.h | 52 | ||||
-rw-r--r-- | vespamalloc/src/vespamalloc/malloc/threadlist.h | 4 | ||||
-rw-r--r-- | vespamalloc/src/vespamalloc/malloc/threadpool.h | 7 | ||||
-rw-r--r-- | vespamalloc/src/vespamalloc/malloc/threadpool.hpp | 6 |
11 files changed, 68 insertions, 122 deletions
diff --git a/vespamalloc/etc/vespamalloc.conf b/vespamalloc/etc/vespamalloc.conf index 2ae0af00a11..3ece047ae07 100644 --- a/vespamalloc/etc/vespamalloc.conf +++ b/vespamalloc/etc/vespamalloc.conf @@ -3,7 +3,6 @@ logfile stderr # default(stderr) This is the file to where log is written (stderr, stdout, filename) # Tuning. But default is probably good. -alwaysreuselimit 0x200000 # default(0x200000) Objects larger than this will always be returned to the segment for reuse, also by other size classes.. threadcachelimit 0x10000 # default(0x10000) Max bytes in thread local cache per size class. fillvalue 0xa8 # default(0xa8) means not used. libvespamalloc(dXXXX).so have the possibility to fill memory on free and verify on malloc. This is to help catch use after free errors. @@ -24,7 +23,4 @@ bigblocklimit 0x80000000 # default(0x800000) Limit for when to log ne pralloc_loglimit 0x7fffffffffffffff # What to log pr alloc. default(0x7fffffffffffffff) except mallocdst(0x200000). mallocdst_nl(0x7fffffffffffffff), but has effect on SIGHUP. #Some deprecated/less usefull ones. -atnomem_loglevel 2 # default(1) Loglevel used when datasegment is exhausted. -atdoubledelete_loglevel 2 # default(1) Loglevel used when vespa_malloc discovers a double delete. -atinvalid_loglevel 2 # default(1) Loglevel used when vespa_malloc discovers logical error. allocs2show 0 # Number of allocations to show when dumping stacktrace. diff --git a/vespamalloc/src/vespamalloc/malloc/common.h b/vespamalloc/src/vespamalloc/malloc/common.h index b1b26f6b350..2bb7df58957 100644 --- a/vespamalloc/src/vespamalloc/malloc/common.h +++ b/vespamalloc/src/vespamalloc/malloc/common.h @@ -52,15 +52,13 @@ static constexpr uint32_t NUM_THREADS = 16384; #define PARANOID_CHECK3(a) #endif -typedef MmapMemory OSMemory; - -typedef int SizeClassT; +using OSMemory = MmapMemory; +using SizeClassT = int; +constexpr size_t ALWAYS_REUSE_LIMIT = 0x200000ul; -inline int msbIdx(uint64_t v) { - int64_t result; - __asm __volatile("bsrq %0,%0" : "=r" (result) : "0" (v)); - return result; +inline constexpr int msbIdx(uint64_t v) { + return (sizeof(v)*8 - 1) - __builtin_clzl(v); } template <size_t MinClassSizeC> @@ -69,14 +67,14 @@ class CommonT public: static constexpr size_t MAX_ALIGN = 0x200000ul; enum {MinClassSize = MinClassSizeC}; - static inline SizeClassT sizeClass(size_t sz) { + static inline constexpr SizeClassT sizeClass(size_t sz) { SizeClassT tmp(msbIdx(sz - 1) - (MinClassSizeC - 1)); return (sz <= (1 << MinClassSizeC )) ? 0 : tmp; } - static inline size_t classSize(SizeClassT sc) { return (size_t(1) << (sc + MinClassSizeC)); } + static inline constexpr size_t classSize(SizeClassT sc) { return (size_t(1) << (sc + MinClassSizeC)); } }; -inline void crash() { *((volatile unsigned *) NULL) = 0; } +inline void crash() { *((volatile unsigned *) nullptr) = 0; } template <typename T> inline void swap(T & a, T & b) { T tmp(a); a = b; b = tmp; } diff --git a/vespamalloc/src/vespamalloc/malloc/datasegment.h b/vespamalloc/src/vespamalloc/malloc/datasegment.h index 5c1c1f06088..3bd87ca343f 100644 --- a/vespamalloc/src/vespamalloc/malloc/datasegment.h +++ b/vespamalloc/src/vespamalloc/malloc/datasegment.h @@ -30,11 +30,8 @@ public: size_t textSize() const { return size_t(start()); } size_t infoThread(FILE * os, int level, uint32_t thread, SizeClassT sct, uint32_t maxThreadId=0) const __attribute__((noinline)); void info(FILE * os, size_t level) __attribute__((noinline)); - void setupLog(size_t noMemLogLevel, size_t bigMemLogLevel, - size_t bigLimit, size_t bigIncrement, - size_t allocs2Show) + void setupLog(size_t bigMemLogLevel, size_t bigLimit, size_t bigIncrement, size_t allocs2Show) { - _noMemLogLevel = noMemLogLevel; _bigSegmentLogLevel = bigMemLogLevel; if ((size_t(end()) < _nextLogLimit) || (size_t(end()) < (size_t(start()) + bigLimit))) { _nextLogLimit = size_t(start()) + bigLimit; @@ -114,7 +111,6 @@ private: typedef BlockT BlockList[BlockCount]; typedef FreeListT<BlockCount/2> FreeList; OSMemory _osMemory; - size_t _noMemLogLevel; size_t _bigSegmentLogLevel; size_t _bigIncrement; size_t _allocs2Show; diff --git a/vespamalloc/src/vespamalloc/malloc/datasegment.hpp b/vespamalloc/src/vespamalloc/malloc/datasegment.hpp index 355c9e9daad..3fb56c6feb3 100644 --- a/vespamalloc/src/vespamalloc/malloc/datasegment.hpp +++ b/vespamalloc/src/vespamalloc/malloc/datasegment.hpp @@ -13,7 +13,6 @@ DataSegment<MemBlockPtrT>::~DataSegment() = default; template<typename MemBlockPtrT> DataSegment<MemBlockPtrT>::DataSegment() : _osMemory(BlockSize), - _noMemLogLevel(1), _bigSegmentLogLevel(0), _bigIncrement (0x4000000), _allocs2Show (8), @@ -98,8 +97,6 @@ void * DataSegment<MemBlockPtrT>::getBlock(size_t & oldBlockSize, SizeClassT sc) if (recurse++ == 0) { perror("Failed extending datasegment: "); assert(false); - MemBlockPtrT::dumpInfo(_noMemLogLevel); - sleep(2); } return nullptr; } diff --git a/vespamalloc/src/vespamalloc/malloc/globalpool.h b/vespamalloc/src/vespamalloc/malloc/globalpool.h index 872fd9b936e..98f19efae31 100644 --- a/vespamalloc/src/vespamalloc/malloc/globalpool.h +++ b/vespamalloc/src/vespamalloc/malloc/globalpool.h @@ -27,8 +27,10 @@ public: DataSegment<MemBlockPtrT> & dataSegment() { return _dataSegment; } void enableThreadSupport() __attribute__((noinline)); - static void setParams(size_t alwaysReuseLimit, size_t threadCacheLimit); - static size_t computeExactSize(size_t sz); + static void setParams(size_t threadCacheLimit); + static size_t computeExactSize(size_t sz) { + return (((sz + (ALWAYS_REUSE_LIMIT - 1)) / ALWAYS_REUSE_LIMIT) * ALWAYS_REUSE_LIMIT); + } void info(FILE * os, size_t level=0) __attribute__((noinline)); private: @@ -78,7 +80,6 @@ private: std::atomic<size_t> _allocChunkList; Stat _stat[NUM_SIZE_CLASSES]; static size_t _threadCacheLimit __attribute__((visibility("hidden"))); - static size_t _alwaysReuseLimit __attribute__((visibility("hidden"))); }; } diff --git a/vespamalloc/src/vespamalloc/malloc/globalpool.hpp b/vespamalloc/src/vespamalloc/malloc/globalpool.hpp index 69f2a2cf820..cd0546933ae 100644 --- a/vespamalloc/src/vespamalloc/malloc/globalpool.hpp +++ b/vespamalloc/src/vespamalloc/malloc/globalpool.hpp @@ -9,12 +9,10 @@ namespace vespamalloc { template <typename MemBlockPtrT> size_t AllocPoolT<MemBlockPtrT>::_threadCacheLimit __attribute__((visibility("hidden"))) = 0x10000; -template <typename MemBlockPtrT> -size_t AllocPoolT<MemBlockPtrT>::_alwaysReuseLimit __attribute__((visibility("hidden"))) = 0x200000; template <typename MemBlockPtrT> AllocPoolT<MemBlockPtrT>::AllocPoolT(DataSegment<MemBlockPtrT> & ds) - : _chunkPool(NULL), + : _chunkPool(nullptr), _scList(), _dataSegment(ds), _getChunks(0), @@ -25,9 +23,7 @@ AllocPoolT<MemBlockPtrT>::AllocPoolT(DataSegment<MemBlockPtrT> & ds) } template <typename MemBlockPtrT> -AllocPoolT<MemBlockPtrT>::~AllocPoolT() -{ -} +AllocPoolT<MemBlockPtrT>::~AllocPoolT() = default; template <typename MemBlockPtrT> void AllocPoolT<MemBlockPtrT>::enableThreadSupport() @@ -37,9 +33,8 @@ void AllocPoolT<MemBlockPtrT>::enableThreadSupport() template <typename MemBlockPtrT> void -AllocPoolT<MemBlockPtrT>::setParams(size_t alwaysReuseLimit, size_t threadCacheLimit) +AllocPoolT<MemBlockPtrT>::setParams(size_t threadCacheLimit) { - _alwaysReuseLimit = alwaysReuseLimit; _threadCacheLimit = threadCacheLimit; } @@ -48,16 +43,16 @@ typename AllocPoolT<MemBlockPtrT>::ChunkSList * AllocPoolT<MemBlockPtrT>::getFree(SizeClassT sc) { typename ChunkSList::AtomicHeadPtr & empty = _scList[sc]._empty; - ChunkSList * csl(NULL); - while ((csl = ChunkSList::linkOut(empty)) == NULL) { + ChunkSList * csl(nullptr); + while ((csl = ChunkSList::linkOut(empty)) == nullptr) { Guard sync(_mutex); - if (empty.load(std::memory_order_relaxed)._ptr == NULL) { + if (empty.load(std::memory_order_relaxed)._ptr == nullptr) { ChunkSList * ncsl(getChunks(sync, 1)); if (ncsl) { ChunkSList::linkInList(empty, ncsl); } else { - assert(ncsl != NULL); - return NULL; + assert(ncsl != nullptr); + return nullptr; } } } @@ -69,16 +64,16 @@ template <typename MemBlockPtrT> typename AllocPoolT<MemBlockPtrT>::ChunkSList * AllocPoolT<MemBlockPtrT>::getAlloc(SizeClassT sc) { - ChunkSList * csl(NULL); + ChunkSList * csl(nullptr); typename ChunkSList::AtomicHeadPtr & full = _scList[sc]._full; - while ((csl = ChunkSList::linkOut(full)) == NULL) { + while ((csl = ChunkSList::linkOut(full)) == nullptr) { Guard sync(_mutex); - if (full.load(std::memory_order_relaxed)._ptr == NULL) { + if (full.load(std::memory_order_relaxed)._ptr == nullptr) { ChunkSList * ncsl(malloc(sync, sc)); if (ncsl) { ChunkSList::linkInList(full, ncsl); } else { - return NULL; + return nullptr; } } USE_STAT2(_stat[sc]._getAlloc.fetch_add(1, std::memory_order_relaxed)); @@ -122,12 +117,6 @@ AllocPoolT<MemBlockPtrT>::exchangeAlloc(SizeClassT sc, typename AllocPoolT<MemBl } template <typename MemBlockPtrT> -size_t -AllocPoolT<MemBlockPtrT>::computeExactSize(size_t sz) { - return (((sz + (_alwaysReuseLimit - 1)) / _alwaysReuseLimit) * _alwaysReuseLimit); -} - -template <typename MemBlockPtrT> typename AllocPoolT<MemBlockPtrT>::ChunkSList * AllocPoolT<MemBlockPtrT>::exactAlloc(size_t exactSize, SizeClassT sc, typename AllocPoolT<MemBlockPtrT>::ChunkSList * csl) @@ -145,10 +134,9 @@ AllocPoolT<MemBlockPtrT>::exactAlloc(size_t exactSize, SizeClassT sc, template <typename MemBlockPtrT> typename AllocPoolT<MemBlockPtrT>::ChunkSList * -AllocPoolT<MemBlockPtrT>::returnMemory(SizeClassT sc, - typename AllocPoolT<MemBlockPtrT>::ChunkSList * csl) +AllocPoolT<MemBlockPtrT>::returnMemory(SizeClassT sc, typename AllocPoolT<MemBlockPtrT>::ChunkSList * csl) { - ChunkSList * completelyEmpty(NULL); + ChunkSList * completelyEmpty(nullptr); #if 0 completelyEmpty = exchangeFree(sc, csl); #else @@ -174,15 +162,15 @@ AllocPoolT<MemBlockPtrT>::malloc(const Guard & guard, SizeClassT sc) const size_t cs(MemBlockPtrT::classSize(sc)); size_t blockSize = cs * numBlocks; void * block = _dataSegment.getBlock(blockSize, sc); - ChunkSList * csl(NULL); - if (block != NULL) { + ChunkSList * csl(nullptr); + if (block != nullptr) { numBlocks = (blockSize + cs - 1)/cs; const size_t blocksPerChunk(std::max(1, std::min(int(ChunkSList::NumBlocks), int(_threadCacheLimit >> (MemBlockPtrT::MinClassSize + sc))))); const size_t numChunks = (numBlocks+(blocksPerChunk-1))/blocksPerChunk; csl = getChunks(guard, numChunks); - if (csl != NULL) { + if (csl != nullptr) { char *first = (char *) block; const size_t itemSize = cs; size_t numItems(0); @@ -216,9 +204,9 @@ AllocPoolT<MemBlockPtrT>::getChunks(const Guard & guard, size_t numChunks) ChunkSList * prev(csl); bool enough(true); for (size_t i=0; enough && (i < numChunks); i++, csl = csl->getNext()) { - if (csl == NULL) { + if (csl == nullptr) { csl = allocChunkList(guard); - enough = (csl != NULL); + enough = (csl != nullptr); if (prev) { prev->setNext(csl); } else { @@ -230,9 +218,9 @@ AllocPoolT<MemBlockPtrT>::getChunks(const Guard & guard, size_t numChunks) if (enough) { csl = _chunkPool; _chunkPool = prev->getNext(); - prev->setNext(NULL); + prev->setNext(nullptr); } else { - csl = NULL; + csl = nullptr; } USE_STAT2(_getChunks.fetch_add(1, std::memory_order_relaxed)); USE_STAT2(_getChunksSum.fetch_add(numChunks, std::memory_order_relaxed)); @@ -247,14 +235,14 @@ AllocPoolT<MemBlockPtrT>::allocChunkList(const Guard & guard) (void) guard; size_t blockSize(sizeof(ChunkSList)*0x2000); void * block = _dataSegment.getBlock(blockSize, _dataSegment.SYSTEM_BLOCK); - ChunkSList * newList(NULL); - if (block != NULL) { + ChunkSList * newList(nullptr); + if (block != nullptr) { size_t chunksInBlock(blockSize/sizeof(ChunkSList)); newList = new (block) ChunkSList[chunksInBlock]; for (size_t j=0; j < (chunksInBlock-1); j++) { newList[j].setNext(newList+j+1); } - newList[chunksInBlock-1].setNext(NULL); + newList[chunksInBlock-1].setNext(nullptr); } USE_STAT2(_allocChunkList.fetch_add(1, std::memory_order_relaxed)); return newList; diff --git a/vespamalloc/src/vespamalloc/malloc/malloc.h b/vespamalloc/src/vespamalloc/malloc/malloc.h index 51efe28eafc..f9a749c006e 100644 --- a/vespamalloc/src/vespamalloc/malloc/malloc.h +++ b/vespamalloc/src/vespamalloc/malloc/malloc.h @@ -53,22 +53,15 @@ public: void info(FILE * os, size_t level=0) __attribute__ ((noinline)); - void setupSegmentLog(size_t noMemLogLevel, - size_t bigMemLogLevel, - size_t bigLimit, - size_t bigIncrement, - size_t allocs2Show) - { - _segment.setupLog(noMemLogLevel, bigMemLogLevel, bigLimit, bigIncrement, allocs2Show); + void setupSegmentLog(size_t bigMemLogLevel, size_t bigLimit, size_t bigIncrement, size_t allocs2Show) { + _segment.setupLog(bigMemLogLevel, bigLimit, bigIncrement, allocs2Show); } - void setupLog(size_t doubleDelete, size_t invalidMem, size_t prAllocLimit) { - _doubleDeleteLogLevel = doubleDelete; - _invalidMemLogLevel = invalidMem; + void setupLog(size_t prAllocLimit) { _prAllocLimit = prAllocLimit; } - void setParams(size_t alwayReuseLimit, size_t threadCacheLimit) { - _threadList.setParams(alwayReuseLimit, threadCacheLimit); - _allocPool.setParams(alwayReuseLimit, threadCacheLimit); + void setParams(size_t threadCacheLimit) { + _threadList.setParams(threadCacheLimit); + _allocPool.setParams(threadCacheLimit); } const DataSegment<MemBlockPtrT> & dataSegment() const { return _segment; } private: @@ -76,8 +69,6 @@ private: void crash() __attribute__((noinline));; typedef AllocPoolT<MemBlockPtrT> AllocPool; typedef typename ThreadListT::ThreadPool ThreadPool; - size_t _doubleDeleteLogLevel; - size_t _invalidMemLogLevel; size_t _prAllocLimit; DataSegment<MemBlockPtrT> _segment; AllocPool _allocPool; @@ -87,8 +78,6 @@ private: template <typename MemBlockPtrT, typename ThreadListT> MemoryManager<MemBlockPtrT, ThreadListT>::MemoryManager(size_t logLimitAtStart) : IAllocator(), - _doubleDeleteLogLevel(1), - _invalidMemLogLevel(1), _prAllocLimit(logLimitAtStart), _segment(), _allocPool(_segment), diff --git a/vespamalloc/src/vespamalloc/malloc/memorywatcher.h b/vespamalloc/src/vespamalloc/malloc/memorywatcher.h index 2bb38541314..b56200e2ab2 100644 --- a/vespamalloc/src/vespamalloc/malloc/memorywatcher.h +++ b/vespamalloc/src/vespamalloc/malloc/memorywatcher.h @@ -43,7 +43,7 @@ private: const char * valueName() const { return _valueName; } const char * value() const { return _value; } void value(const char * v) __attribute__((noinline)); - long valueAsLong() const __attribute__((noinline)) { return strtol(_value, NULL, 0); } + long valueAsLong() const __attribute__((noinline)) { return strtol(_value, nullptr, 0); } void info(FILE * os) __attribute__ ((noinline)) { fprintf(os, "%s = %s %ld", valueName(), value(), valueAsLong()); } @@ -54,15 +54,11 @@ private: class Params { public: enum { - alwaysreuselimit = 0, threadcachelimit, logfile, sigprof_loglevel, atend_loglevel, pralloc_loglimit, - atnomem_loglevel, - atdoubledelete_loglevel, - atinvalid_loglevel, bigsegment_loglevel, bigsegment_limit, bigsegment_increment, @@ -109,8 +105,6 @@ private: NameValuePair _params[numberofentries]; }; FILE * _logFile; - int _infoAtAbort; - int _infoAtNOMEM; Params _params; struct sigaction _oldSig; @@ -119,15 +113,11 @@ private: template <typename T, typename S> MemoryWatcher<T, S>::Params::Params() { - _params[ alwaysreuselimit] = NameValuePair("alwaysreuselimit", "0x200000"); // 2M for allignment with hugepage size. _params[ threadcachelimit] = NameValuePair("threadcachelimit", "0x10000"); // 64K _params[ logfile] = NameValuePair("logfile", "stderr"); _params[ sigprof_loglevel] = NameValuePair("sigprof_loglevel", "1"); _params[ atend_loglevel] = NameValuePair("atend_loglevel", "1"); _params[ pralloc_loglimit] = NameValuePair("pralloc_loglimit", "0x2000000"); - _params[ atnomem_loglevel] = NameValuePair("atnomem_loglevel", "1"); - _params[atdoubledelete_loglevel] = NameValuePair("atdoubledelete_loglevel", "1"); - _params[ atinvalid_loglevel] = NameValuePair("atinvalid_loglevel", "1"); _params[ bigsegment_loglevel] = NameValuePair("bigsegment_loglevel", "1"); _params[ bigsegment_limit] = NameValuePair("bigsegment_limit", "0x1000000000"); // 64GM _params[ bigsegment_increment] = NameValuePair("bigsegment_increment", "0x100000000"); //4GM @@ -163,9 +153,7 @@ void MemoryWatcher<T, S>::NameValuePair::value(const char * v) { template <typename T, typename S> MemoryWatcher<T, S>::MemoryWatcher(int infoAtEnd, size_t prAllocAtStart) : MemoryManager<T, S>(prAllocAtStart), - _logFile(stderr), - _infoAtAbort(-1), - _infoAtNOMEM(1) + _logFile(stderr) { _manager = this; char tmp[16]; @@ -199,7 +187,7 @@ bool MemoryWatcher<T, S>::activateLogFile(const char *logfile) if ((oldFp != stderr) && (oldFp != stdout)) { fclose(oldFp); } - return (_logFile != NULL); + return (_logFile != nullptr); } template <typename T, typename S> @@ -207,16 +195,12 @@ void MemoryWatcher<T, S>::activateOptions() { activateLogFile(_params[Params::logfile].value()); T::dumpFile(_logFile); - this->setupSegmentLog(_params[Params::atnomem_loglevel].valueAsLong(), - _params[Params::bigsegment_loglevel].valueAsLong(), - _params[Params::bigsegment_limit].valueAsLong(), - _params[Params::bigsegment_increment].valueAsLong(), - _params[Params::allocs2show].valueAsLong()); - this->setupLog(_params[Params::atdoubledelete_loglevel].valueAsLong(), - _params[Params::atinvalid_loglevel].valueAsLong(), - _params[Params::pralloc_loglimit].valueAsLong()); - this->setParams(_params[Params::alwaysreuselimit].valueAsLong(), - _params[Params::threadcachelimit].valueAsLong()); + this->setupSegmentLog(_params[Params::bigsegment_loglevel].valueAsLong(), + _params[Params::bigsegment_limit].valueAsLong(), + _params[Params::bigsegment_increment].valueAsLong(), + _params[Params::allocs2show].valueAsLong()); + this->setupLog(_params[Params::pralloc_loglimit].valueAsLong()); + this->setParams(_params[Params::threadcachelimit].valueAsLong()); T::bigBlockLimit(_params[Params::bigblocklimit].valueAsLong()); T::setFill(_params[Params::fillvalue].valueAsLong()); @@ -229,7 +213,7 @@ const char *vespaHomeConf(char pathName[]) const char *home = "/opt/vespa"; const char *conf = "/etc/vespamalloc.conf"; const char *env = getenv("VESPA_HOME"); - if (env != NULL) { + if (env != nullptr) { home = env; } if ((strlen(home) + strlen(conf)) >= PATH_MAX) { @@ -279,21 +263,21 @@ void MemoryWatcher<T, S>::parseOptions(char * options) { bool isComment(false); const char ignore('\0'); - const char *valueName(NULL); - const char *value(NULL); + const char *valueName(nullptr); + const char *value(nullptr); bool isWhite(true); for(char *p=options; *p; p++) { char c(*p); if (c == '\n') { - if ((valueName != NULL) && (value != NULL)) { + if ((valueName != nullptr) && (value != nullptr)) { if (_params.update(valueName, value) == false) { fprintf(stderr, "Invalid parameter %s", valueName); } } isComment = false; isWhite = true; - valueName = NULL; - value = NULL; + valueName = nullptr; + value = nullptr; } else if (isComment) { *p = ignore; } else if (c == '#') { @@ -302,7 +286,7 @@ void MemoryWatcher<T, S>::parseOptions(char * options) } else { if (isWhite) { if (!isspace(c)) { - if (valueName == NULL) { + if (valueName == nullptr) { valueName = p; } else { value = p; @@ -347,7 +331,7 @@ void MemoryWatcher<T, S>::signalHandler(int signum, siginfo_t * sig, void * arg if (_params[Params::sigprof_loglevel].valueAsLong() > 1) { fprintf(_logFile, "SignalHandler %d done\n", signum); } - if ((_oldSig.sa_handler != SIG_IGN) && (_oldSig.sa_handler != SIG_DFL) && (_oldSig.sa_handler != NULL)) { + if ((_oldSig.sa_handler != SIG_IGN) && (_oldSig.sa_handler != SIG_DFL) && (_oldSig.sa_handler != nullptr)) { (_oldSig.sa_sigaction)(signum, sig, arg); } } @@ -377,7 +361,7 @@ bool MemoryWatcher<T, S>::signal(int signum) } template <typename T, typename S> -MemoryWatcher<T, S> * MemoryWatcher<T, S>::_manager = NULL; +MemoryWatcher<T, S> * MemoryWatcher<T, S>::_manager = nullptr; } // namespace vespamalloc diff --git a/vespamalloc/src/vespamalloc/malloc/threadlist.h b/vespamalloc/src/vespamalloc/malloc/threadlist.h index 9edf086ca96..91409eb2c95 100644 --- a/vespamalloc/src/vespamalloc/malloc/threadlist.h +++ b/vespamalloc/src/vespamalloc/malloc/threadlist.h @@ -19,8 +19,8 @@ public: using AllocPool = AllocPoolT<MemBlockPtrT>; ThreadListT(AllocPool & pool); ~ThreadListT(); - void setParams(size_t alwayReuseLimit, size_t threadCacheLimit) { - ThreadPool::setParams(alwayReuseLimit, threadCacheLimit); + void setParams(size_t threadCacheLimit) { + ThreadPool::setParams(threadCacheLimit); } bool quitThisThread(); bool initThisThread(); diff --git a/vespamalloc/src/vespamalloc/malloc/threadpool.h b/vespamalloc/src/vespamalloc/malloc/threadpool.h index d4a754532ff..493369a4441 100644 --- a/vespamalloc/src/vespamalloc/malloc/threadpool.h +++ b/vespamalloc/src/vespamalloc/malloc/threadpool.h @@ -37,7 +37,7 @@ public: uint32_t threadId() const { return _threadId; } void quit() { _osThreadId = 0; } // Implicit memory barrier void init(int thrId); - static void setParams(size_t alwayReuseLimit, size_t threadCacheLimit); + static void setParams(size_t threadCacheLimit); bool grabAvailable(); private: bool hasActuallyBeenUsed() const; @@ -62,7 +62,7 @@ private: ChunkSList *_freeTo; }; void mallocHelper(size_t exactSize, SizeClassT sc, AllocFree & af, MemBlockPtrT & mem) __attribute__ ((noinline)); - static bool alwaysReuse(SizeClassT sc) { return sc > _alwaysReuseSCLimit; } + static constexpr bool alwaysReuse(SizeClassT sc) { return sc > ALWAYS_REUSE_SC_LIMIT; } AllocPool * _allocPool; AllocFree _memList[NUM_SIZE_CLASSES]; @@ -70,7 +70,8 @@ private: uint32_t _threadId; std::atomic<ssize_t> _osThreadId; - static SizeClassT _alwaysReuseSCLimit __attribute__((visibility("hidden"))); + static constexpr SizeClassT ALWAYS_REUSE_SC_LIMIT = std::max(MemBlockPtrT::sizeClass(ALWAYS_REUSE_LIMIT), + SizeClassT(MemBlockPtrT::SizeClassSpan)); static size_t _threadCacheLimit __attribute__((visibility("hidden"))); }; diff --git a/vespamalloc/src/vespamalloc/malloc/threadpool.hpp b/vespamalloc/src/vespamalloc/malloc/threadpool.hpp index b28aa144c34..b4ce1b6d6d0 100644 --- a/vespamalloc/src/vespamalloc/malloc/threadpool.hpp +++ b/vespamalloc/src/vespamalloc/malloc/threadpool.hpp @@ -6,8 +6,6 @@ namespace vespamalloc { template <typename MemBlockPtrT, typename ThreadStatT> -SizeClassT ThreadPoolT<MemBlockPtrT, ThreadStatT>::_alwaysReuseSCLimit __attribute__((visibility("hidden"))) = MemBlockPtrT::sizeClass(0x200000); -template <typename MemBlockPtrT, typename ThreadStatT> size_t ThreadPoolT<MemBlockPtrT, ThreadStatT>::_threadCacheLimit __attribute__((visibility("hidden"))) = 0x10000; template <typename MemBlockPtrT, typename ThreadStatT> @@ -188,10 +186,8 @@ void ThreadPoolT<MemBlockPtrT, ThreadStatT>::init(int thrId) } template <typename MemBlockPtrT, typename ThreadStatT > -void ThreadPoolT<MemBlockPtrT, ThreadStatT>::setParams(size_t alwaysReuseLimit, size_t threadCacheLimit) +void ThreadPoolT<MemBlockPtrT, ThreadStatT>::setParams(size_t threadCacheLimit) { - _alwaysReuseSCLimit = std::max(MemBlockPtrT::sizeClass(alwaysReuseLimit), - SizeClassT(MemBlockPtrT::SizeClassSpan)); _threadCacheLimit = threadCacheLimit; } |