micro writer buffer uses the default allocator

This commit is contained in:
z404289981
2023-11-14 10:10:32 +00:00
committed by ob-robot
parent d0a66f4900
commit 41296128f1
6 changed files with 169 additions and 165 deletions

View File

@ -32,95 +32,6 @@ namespace compaction
{
/*
* ================================================= ObLocalArena =================================================
*/
ObLocalArena::ObLocalArena(
const lib::ObLabel &label,
const int64_t page_size)
: ref_mem_ctx_(nullptr),
arena_(label, page_size, MTL_ID(), ObCtxIds::DEFAULT_CTX_ID),
hist_mem_hold_(0)
{
ObCompactionMemoryContext *mem_ctx = CURRENT_MEM_CTX();
if (nullptr != mem_ctx) {
bind_mem_ctx(*mem_ctx);
}
}
ObLocalArena::ObLocalArena(
ObCompactionMemoryContext &mem_ctx,
const lib::ObLabel &label,
const int64_t page_size)
: ref_mem_ctx_(nullptr),
arena_(label, page_size, MTL_ID(), ObCtxIds::DEFAULT_CTX_ID),
hist_mem_hold_(0)
{
bind_mem_ctx(mem_ctx);
}
void ObLocalArena::bind_mem_ctx(ObCompactionMemoryContext &mem_ctx)
{
if (NULL == ref_mem_ctx_) {
ref_mem_ctx_ = &mem_ctx;
}
arena_.set_ctx_id(ref_mem_ctx_->get_ctx_id());
}
ObLocalArena::~ObLocalArena()
{
reset();
ref_mem_ctx_ = nullptr;
}
void* ObLocalArena::alloc(const int64_t size)
{
void *buf = arena_.alloc(size);
if (OB_NOT_NULL(buf)) {
update_mem_monitor();
}
return buf;
}
void* ObLocalArena::alloc(const int64_t size, const ObMemAttr &attr)
{
void *buf = arena_.alloc(size, attr);
if (OB_NOT_NULL(buf)) {
update_mem_monitor();
}
return buf;
}
void ObLocalArena::reset()
{
arena_.reset();
update_mem_monitor();
}
void ObLocalArena::clear()
{
arena_.clear();
update_mem_monitor();
}
void ObLocalArena::update_mem_monitor()
{
ref_mem_ctx_ = nullptr == ref_mem_ctx_
? CURRENT_MEM_CTX()
: ref_mem_ctx_;
int64_t cur_mem_hold = arena_.total();
if (nullptr != ref_mem_ctx_ && hist_mem_hold_ != cur_mem_hold) {
if (cur_mem_hold > hist_mem_hold_) {
ref_mem_ctx_->inc_local_hold_mem(cur_mem_hold - hist_mem_hold_);
} else {
ref_mem_ctx_->inc_local_free_mem(hist_mem_hold_ - cur_mem_hold);
}
hist_mem_hold_ = cur_mem_hold;
}
}
/*
* ================================================= Mem Monitor Part =================================================
*/