aboutsummaryrefslogtreecommitdiffstats
path: root/vespamalloc
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-06-29 16:41:52 +0200
committerGitHub <noreply@github.com>2021-06-29 16:41:52 +0200
commit3577dcdb4947d4ffb1ec9daeb8d3e16a24077904 (patch)
treed102f8665f134339c2c4d6f79465bc64983d5157 /vespamalloc
parent10b889945e57bb3369bf75fd90a847ca69899a6e (diff)
parenta044f4310c44ffd90fe8a5d88dd518d265e9eeb8 (diff)
Merge branch 'master' into balder/save-errno-before-checking
Diffstat (limited to 'vespamalloc')
-rw-r--r--vespamalloc/etc/vespamalloc.conf4
-rw-r--r--vespamalloc/src/tests/stacktrace/stacktrace.cpp21
-rw-r--r--vespamalloc/src/tests/test1/new_test.cpp1
-rw-r--r--vespamalloc/src/vespamalloc/malloc/common.h18
-rw-r--r--vespamalloc/src/vespamalloc/malloc/datasegment.h6
-rw-r--r--vespamalloc/src/vespamalloc/malloc/datasegment.hpp3
-rw-r--r--vespamalloc/src/vespamalloc/malloc/globalpool.h7
-rw-r--r--vespamalloc/src/vespamalloc/malloc/globalpool.hpp60
-rw-r--r--vespamalloc/src/vespamalloc/malloc/malloc.h23
-rw-r--r--vespamalloc/src/vespamalloc/malloc/memorywatcher.h52
-rw-r--r--vespamalloc/src/vespamalloc/malloc/overload.h42
-rw-r--r--vespamalloc/src/vespamalloc/malloc/threadlist.h4
-rw-r--r--vespamalloc/src/vespamalloc/malloc/threadpool.h7
-rw-r--r--vespamalloc/src/vespamalloc/malloc/threadpool.hpp6
14 files changed, 77 insertions, 177 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/tests/stacktrace/stacktrace.cpp b/vespamalloc/src/tests/stacktrace/stacktrace.cpp
index 37322994586..f30e3c20f55 100644
--- a/vespamalloc/src/tests/stacktrace/stacktrace.cpp
+++ b/vespamalloc/src/tests/stacktrace/stacktrace.cpp
@@ -17,22 +17,12 @@ void * run(void * arg)
}
void verify_that_vespamalloc_datasegment_size_exists() {
-#if __GLIBC_PREREQ(2, 33)
- struct mallinfo2 info = mallinfo2();
- printf("Malloc used %zdm of memory\n", info.arena);
- assert(info.arena >= 10 * 0x100000ul);
- assert(info.arena < 10000 * 0x100000ul);
- assert(info.fordblks == 0);
- assert(info.fsmblks == 0);
- assert(info.hblkhd == 0);
- assert(info.hblks == 0);
- assert(info.keepcost == 0);
- assert(info.ordblks == 0);
- assert(info.smblks == 0);
- assert(info.uordblks == 0);
- assert(info.usmblks == 0);
-#else
+#pragma GCC diagnostic push
+#if __GNUC_PREREQ(2, 33)
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
struct mallinfo info = mallinfo();
+#pragma GCC diagnostic push
printf("Malloc used %dm of memory\n",info.arena);
assert(info.arena >= 10);
assert(info.arena < 10000);
@@ -45,7 +35,6 @@ void verify_that_vespamalloc_datasegment_size_exists() {
assert(info.smblks == 0);
assert(info.uordblks == 0);
assert(info.usmblks == 0);
-#endif
}
int main(int argc, char *argv[])
diff --git a/vespamalloc/src/tests/test1/new_test.cpp b/vespamalloc/src/tests/test1/new_test.cpp
index 7988367f415..e73def175b0 100644
--- a/vespamalloc/src/tests/test1/new_test.cpp
+++ b/vespamalloc/src/tests/test1/new_test.cpp
@@ -111,7 +111,6 @@ TEST("verify realloarray") {
EXPECT_EQUAL(nullptr, arr3);
EXPECT_EQUAL(ENOMEM, myErrno);
}
-#endif
void verify_vespamalloc_usable_size() {
struct AllocInfo { size_t requested; size_t usable;};
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/overload.h b/vespamalloc/src/vespamalloc/malloc/overload.h
index 8815a11a84f..1ec37c37aa1 100644
--- a/vespamalloc/src/vespamalloc/malloc/overload.h
+++ b/vespamalloc/src/vespamalloc/malloc/overload.h
@@ -106,23 +106,6 @@ void operator delete[](void* ptr, std::size_t sz, std::align_val_t alignment) no
extern "C" {
-#if __GLIBC_PREREQ(2, 33)
-struct mallinfo2 mallinfo2() __THROW __attribute__((visibility ("default")));
-struct mallinfo2 mallinfo2() __THROW {
- struct mallinfo2 info;
- info.arena = vespamalloc::_GmemP->dataSegment().dataSize();
- info.ordblks = 0;
- info.smblks = 0;
- info.hblks = 0;
- info.hblkhd = 0;
- info.usmblks = 0;
- info.fsmblks = 0;
- info.uordblks = 0;
- info.fordblks = 0;
- info.keepcost = 0;
- return info;
-}
-#else
struct mallinfo mallinfo() __THROW __attribute__((visibility ("default")));
struct mallinfo mallinfo() __THROW {
struct mallinfo info;
@@ -138,7 +121,6 @@ struct mallinfo mallinfo() __THROW {
info.keepcost = 0;
return info;
}
-#endif
void * malloc(size_t sz) {
return vespamalloc::createAllocator()->malloc(sz);
@@ -154,17 +136,6 @@ void * realloc(void * ptr, size_t sz)
return vespamalloc::createAllocator()->realloc(ptr, sz);
}
-void * reallocarray(void * ptr, size_t nemb, size_t elemSize) __THROW __attribute__((visibility ("default")));
-void * reallocarray(void * ptr, size_t nemb, size_t elemSize) __THROW
-{
- size_t sz = nemb * elemSize;
- if (nemb != 0 && (sz/nemb != elemSize)) {
- errno = ENOMEM;
- return nullptr;
- }
- return vespamalloc::createAllocator()->realloc(ptr, sz);
-}
-
void* memalign(size_t align, size_t sz) __THROW __attribute__((visibility ("default")));
void* memalign(size_t align, size_t sz) __THROW
{
@@ -202,6 +173,7 @@ void *valloc(size_t size) __THROW
return memalign(sysconf(_SC_PAGESIZE),size);
}
+
void free(void * ptr) {
if (ptr) { vespamalloc::_GmemP->free(ptr); }
}
@@ -215,8 +187,7 @@ size_t malloc_usable_size (void * ptr) __THROW {
#ifdef __clang__
void* __libc_malloc(size_t sz) __THROW __attribute__((malloc, alloc_size(1))) ALIAS("malloc");
void* __libc_realloc(void* ptr, size_t sz) __THROW __attribute__((malloc, alloc_size(2))) ALIAS("realloc");
-void* __libc_reallocarray(void* ptr, size_t nemb, size_t sz) __THROW __attribute__((malloc, alloc_size(2,3))) ALIAS("reallocarray");
-void* __libc_calloc(size_t n, size_t sz) __THROW __attribute__((malloc, alloc_size(1,2))) ALIAS("calloc");
+void* __libc_calloc(size_t n, size_t sz) __THROW __attribute__((malloc, alloc_size(2))) ALIAS("calloc");
void cfree(void *) __THROW ALIAS("free");
void __libc_free(void* ptr) __THROW ALIAS("free");
#pragma clang diagnostic push
@@ -226,20 +197,15 @@ void __libc_cfree(void* ptr) __THROW ALIAS("cfree");
#else
void* __libc_malloc(size_t sz) __THROW __attribute__((leaf, malloc, alloc_size(1))) ALIAS("malloc");
void* __libc_realloc(void* ptr, size_t sz) __THROW __attribute__((leaf, malloc, alloc_size(2))) ALIAS("realloc");
-void* __libc_reallocarray(void* ptr, size_t nemb, size_t sz) __THROW __attribute__((leaf, malloc, alloc_size(2,3))) ALIAS("reallocarray");
-void* __libc_calloc(size_t n, size_t sz) __THROW __attribute__((leaf, malloc, alloc_size(1,2))) ALIAS("calloc");
+void* __libc_calloc(size_t n, size_t sz) __THROW __attribute__((leaf, malloc, alloc_size(2))) ALIAS("calloc");
void cfree(void *) __THROW __attribute__((leaf)) ALIAS("free");
void __libc_free(void* ptr) __THROW __attribute__((leaf)) ALIAS("free");
void __libc_cfree(void* ptr) __THROW __attribute__((leaf)) ALIAS("cfree");
#endif
+struct mallinfo __libc_mallinfo() __THROW ALIAS("mallinfo");
size_t __libc_malloc_usable_size(void *ptr) __THROW ALIAS("malloc_usable_size");
void* __libc_memalign(size_t align, size_t s) __THROW __attribute__((leaf, malloc, alloc_size(2))) ALIAS("memalign");
int __posix_memalign(void** r, size_t a, size_t s) __THROW __nonnull((1)) ALIAS("posix_memalign");
-#if __GLIBC_PREREQ(2, 33)
-struct mallinfo2 __libc_mallinfo2() __THROW ALIAS("mallinfo2");
-#else
-struct mallinfo __libc_mallinfo() __THROW ALIAS("mallinfo");
-#endif
#undef ALIAS
}
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;
}