summaryrefslogtreecommitdiffstats
path: root/vespamalloc/src/vespamalloc/malloc/datasegment.h
diff options
context:
space:
mode:
Diffstat (limited to 'vespamalloc/src/vespamalloc/malloc/datasegment.h')
-rw-r--r--vespamalloc/src/vespamalloc/malloc/datasegment.h50
1 files changed, 29 insertions, 21 deletions
diff --git a/vespamalloc/src/vespamalloc/malloc/datasegment.h b/vespamalloc/src/vespamalloc/malloc/datasegment.h
index d03a585ccc2..cefa961852f 100644
--- a/vespamalloc/src/vespamalloc/malloc/datasegment.h
+++ b/vespamalloc/src/vespamalloc/malloc/datasegment.h
@@ -13,7 +13,7 @@ template<typename MemBlockPtrT>
class DataSegment
{
public:
- typedef unsigned FreeCountT;
+ using BlockIdT = uint32_t;
enum { UNMAPPED_BLOCK=-4, UNUSED_BLOCK=-3, FREE_BLOCK=-2, SYSTEM_BLOCK=-1, NUM_ADMIN_CLASSES=4 };
DataSegment() __attribute__((noinline));
~DataSegment() __attribute__((noinline));
@@ -21,7 +21,7 @@ public:
void * getBlock(size_t & oldBlockSize, SizeClassT sc) __attribute__((noinline));
void returnBlock(void *ptr) __attribute__((noinline));
SizeClassT sizeClass(const void * ptr) const { return _blockList[blockId(ptr)].sizeClass(); }
- bool containsPtr(const void * ptr) const { return blockId(ptr) < BlockCount; }
+ bool containsPtr(const void * ptr) const { return blockId(ptr) < BlockCount; }
size_t getMaxSize(const void * ptr) const { return _blockList[blockId(ptr)].getMaxSize(); }
const void * start() const { return _osMemory.getStart(); }
const void * end() const { return _osMemory.getEnd(); }
@@ -42,7 +42,7 @@ public:
checkAndLogBigSegment();
}
void enableThreadSupport() { _mutex.init(); }
- static size_t blockId(const void * ptr) {
+ static BlockIdT blockId(const void * ptr) {
return (size_t(ptr) - Memory::getMinPreferredStartAddress())/BlockSize;
}
static void * fromBlockId(size_t id) {
@@ -61,51 +61,59 @@ private:
DataSegment(const DataSegment & rhs);
DataSegment & operator = (const DataSegment & rhs);
- enum { BlockSize=0x200000, BlockCount=0x80000 }; //1T
+ // Allow for 1T heap
+ static constexpr size_t BlockSize = 0x200000ul;
+ static constexpr BlockIdT BlockCount = 0x80000;
class BlockT
{
public:
- BlockT(SizeClassT szClass = UNUSED_BLOCK, FreeCountT numBlocks = 0)
+ BlockT(SizeClassT szClass = UNUSED_BLOCK, BlockIdT numBlocks = 0)
: _sizeClass(szClass), _freeChainLength(0), _realNumBlocks(numBlocks)
{ }
- SizeClassT sizeClass() const { return _sizeClass; }
- FreeCountT realNumBlocks() const { return _realNumBlocks; }
- FreeCountT freeChainLength() const { return _freeChainLength; }
- void sizeClass(SizeClassT sc) { _sizeClass = sc; }
- void realNumBlocks(FreeCountT fc) { _realNumBlocks = fc; }
- void freeChainLength(FreeCountT fc) { _freeChainLength = fc; }
- size_t getMaxSize() const {
+ SizeClassT sizeClass() const { return _sizeClass; }
+ BlockIdT realNumBlocks() const { return _realNumBlocks; }
+ BlockIdT freeChainLength() const { return _freeChainLength; }
+ void sizeClass(SizeClassT sc) { _sizeClass = sc; }
+ void realNumBlocks(BlockIdT fc) { _realNumBlocks = fc; }
+ void freeChainLength(BlockIdT fc) { _freeChainLength = fc; }
+ size_t getMaxSize() const {
return MemBlockPtrT::unAdjustSize(std::min(MemBlockPtrT::classSize(_sizeClass),
size_t(_realNumBlocks) * BlockSize));
}
private:
SizeClassT _sizeClass;
/// Number of blocks free from here and on. For memory reuse, big blocks only.
- FreeCountT _freeChainLength;
+ BlockIdT _freeChainLength;
/// Real number of blocks used. Used to avoid rounding for big blocks.
- FreeCountT _realNumBlocks;
+ BlockIdT _realNumBlocks;
};
template <int MaxCount>
class FreeListT {
public:
+ using Index = BlockIdT;
FreeListT(BlockT * blockList) __attribute__((noinline));
- void add(size_t startIndex) __attribute__((noinline));
- void * sub(size_t numBlocks) __attribute__((noinline));
- size_t lastBlock(size_t nextBlock) __attribute__((noinline));
+ FreeListT(const FreeListT &) = delete;
+ FreeListT & operator =(const FreeListT &) = delete;
+ FreeListT(FreeListT &&) = delete;
+ FreeListT & operator =(FreeListT &&) = delete;
+ ~FreeListT();
+ void add(Index startIndex) __attribute__((noinline));
+ void * sub(Index numBlocks) __attribute__((noinline));
+ Index lastBlock(Index nextBlock) __attribute__((noinline));
void removeLastBlock() {
if (_count > 0) {
_count--;
}
}
- size_t numFreeBlocks() const;
+ Index numFreeBlocks() const;
void info(FILE * os) __attribute__((noinline));
private:
- void * linkOut(size_t findex, size_t left) __attribute__((noinline));
+ void * linkOut(Index findex, Index left) __attribute__((noinline));
BlockT *_blockList;
- size_t _count;
- size_t _freeStartIndex[MaxCount];
+ Index _count;
+ Index _freeStartIndex[MaxCount];
};
void checkAndLogBigSegment() __attribute__((noinline));