You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
fix(perf,allocator): adding unit test to check CountingAllocator behavior when it is wrapped in STLPoolAllocator
This commit is contained in:
@ -41,6 +41,16 @@ inline int64_t atomicSubRef(std::atomic<int64_t>& ref, int64_t val)
|
||||
{
|
||||
return ref.fetch_sub(val, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
inline void atomicStoreRef(std::atomic<int64_t>& ref, int64_t val)
|
||||
{
|
||||
ref.store(val, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
inline int64_t atomicLoadRef(const std::atomic<int64_t>& ref)
|
||||
{
|
||||
return ref.load(std::memory_order_relaxed);
|
||||
}
|
||||
// Returns the resulting, incremented value
|
||||
template <typename T>
|
||||
inline T atomicInc(volatile T* mem)
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||
#include <boost/smart_ptr/make_shared_array.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "poolallocator.h"
|
||||
|
||||
using namespace std;
|
||||
@ -34,6 +36,7 @@ namespace utils
|
||||
{
|
||||
PoolAllocator& PoolAllocator::operator=(const PoolAllocator& v)
|
||||
{
|
||||
std::cout << "PoolAllocator copy assignment" << std::endl;
|
||||
allocSize = v.allocSize;
|
||||
tmpSpace = v.tmpSpace;
|
||||
useLock = v.useLock;
|
||||
@ -54,15 +57,19 @@ void PoolAllocator::deallocateAll()
|
||||
void PoolAllocator::newBlock()
|
||||
{
|
||||
capacityRemaining = allocSize;
|
||||
std::cout << "PoolAllocator new block" << std::endl;
|
||||
|
||||
if (!tmpSpace || mem.size() == 0)
|
||||
{
|
||||
if (alloc)
|
||||
{
|
||||
std::cout << "PoolAllocator new block with counting alloc" << std::endl;
|
||||
|
||||
mem.emplace_back(boost::allocate_shared<PoolAllocatorBufType>(*alloc, allocSize));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "PoolAllocator new block w/o counting alloc" << std::endl;
|
||||
mem.emplace_back(boost::make_shared<PoolAllocatorBufType>(allocSize));
|
||||
}
|
||||
nextAlloc = mem.back().get();
|
||||
@ -74,14 +81,17 @@ void PoolAllocator::newBlock()
|
||||
void* PoolAllocator::allocOOB(uint64_t size)
|
||||
{
|
||||
OOBMemInfo memInfo;
|
||||
std::cout << "PoolAllocator allocOOB" << std::endl;
|
||||
|
||||
memUsage += size;
|
||||
if (alloc)
|
||||
{
|
||||
std::cout << "PoolAllocator allocOOB with counting alloc" << std::endl;
|
||||
memInfo.mem = boost::allocate_shared<PoolAllocatorBufType>(*alloc, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "PoolAllocator allocOOB w/o counting alloc" << std::endl;
|
||||
memInfo.mem = boost::make_shared<PoolAllocatorBufType>(size);
|
||||
}
|
||||
memInfo.size = size;
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <optional>
|
||||
@ -32,9 +33,10 @@
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include "countingallocator.h"
|
||||
|
||||
@ -57,6 +59,7 @@ class PoolAllocator
|
||||
, useLock(_useLock)
|
||||
, lock(false)
|
||||
{
|
||||
std::cout << "PoolAllocator w/o counting allocator created" << std::endl;
|
||||
}
|
||||
PoolAllocator(allocators::CountingAllocator<PoolAllocatorBufType> alloc, unsigned windowSize = DEFAULT_WINDOW_SIZE,
|
||||
bool isTmpSpace = false, bool _useLock = false)
|
||||
@ -69,6 +72,7 @@ class PoolAllocator
|
||||
, lock(false)
|
||||
, alloc(alloc)
|
||||
{
|
||||
std::cout << "PoolAllocator with counting allocator created" << std::endl;
|
||||
}
|
||||
PoolAllocator(const PoolAllocator& p)
|
||||
: allocSize(p.allocSize)
|
||||
|
@ -101,11 +101,13 @@ STLPoolAllocator<T>::STLPoolAllocator(joblist::ResourceManager* rm)
|
||||
{
|
||||
if (rm)
|
||||
{
|
||||
std::cout << "STLPoolAllocator with RM " << std::endl;
|
||||
auto alloc = rm->getAllocator<PoolAllocatorBufType>();
|
||||
pa.reset(new PoolAllocator(alloc, DEFAULT_SIZE));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "STLPoolAllocator w/o RM " << std::endl;
|
||||
pa.reset(new PoolAllocator(DEFAULT_SIZE));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user