From f581908691711b7e0867fbe5d15b6b4daf0bda36 Mon Sep 17 00:00:00 2001 From: obdev Date: Thu, 20 Jul 2023 07:24:14 +0000 Subject: [PATCH] use memory ctx to allocate the memory of mstx full tablets --- src/storage/tablet/ob_full_tablet_creator.cpp | 38 ++++++++++++------- src/storage/tablet/ob_full_tablet_creator.h | 16 ++++---- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/storage/tablet/ob_full_tablet_creator.cpp b/src/storage/tablet/ob_full_tablet_creator.cpp index 65c35c79d..93c9290c0 100644 --- a/src/storage/tablet/ob_full_tablet_creator.cpp +++ b/src/storage/tablet/ob_full_tablet_creator.cpp @@ -25,14 +25,14 @@ namespace storage { ObFullTabletCreator::ObFullTabletCreator() : is_inited_(false), - mstx_allocator_(), tiny_allocator_(), transform_head_(), transform_tail_(), wait_create_tablets_cnt_(0), created_tablets_cnt_(0), persist_queue_cnt_(0), - mutex_() + mutex_(), + mstx_mem_ctx_(nullptr) { } @@ -45,14 +45,22 @@ int ObFullTabletCreator::init(const uint64_t tenant_id) if (OB_UNLIKELY(is_inited_)) { ret = OB_INIT_TWICE; LOG_WARN("ObTenantMetaMemMgr has been initialized", K(ret)); - } else if (OB_FAIL(mstx_allocator_.init(lib::ObMallocAllocator::get_instance(), - OB_MALLOC_NORMAL_BLOCK_SIZE, ObMemAttr(tenant_id, "MSTXAllocator", ObCtxIds::DEFAULT_CTX_ID)))) { - LOG_WARN("fail to init tenant mstx allocator", K(ret)); } else if (OB_FAIL(tiny_allocator_.init(lib::ObMallocAllocator::get_instance(), OB_MALLOC_NORMAL_BLOCK_SIZE/2, ObMemAttr(tenant_id, "TinyAllocator", ObCtxIds::DEFAULT_CTX_ID)))) { LOG_WARN("fail to init tenant tiny allocator", K(ret)); } else { - is_inited_ = true; + ContextParam param; + param.set_mem_attr(tenant_id, "MSTXCTX", common::ObCtxIds::DEFAULT_CTX_ID) + .set_ablock_size(64L << 10) + .set_properties(ALLOC_THREAD_SAFE); + if (OB_FAIL(ROOT_CONTEXT->CREATE_CONTEXT(mstx_mem_ctx_, param))) { + LOG_WARN("fail to create entity", K(ret)); + } else if (nullptr == mstx_mem_ctx_) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("memory entity is null", K(ret)); + } else { + is_inited_ = true; + } } if (OB_UNLIKELY(!is_inited_)) { reset(); @@ -67,8 +75,11 @@ void ObFullTabletCreator::reset() persist_queue_cnt_ = 0; wait_create_tablets_cnt_ = 0; created_tablets_cnt_ = 0; - mstx_allocator_.reset(); tiny_allocator_.reset(); + if (NULL != mstx_mem_ctx_) { + DESTROY_CONTEXT(mstx_mem_ctx_); + mstx_mem_ctx_ = nullptr; + } is_inited_ = false; } @@ -114,8 +125,8 @@ int ObFullTabletCreator::throttle_tablet_creation() const int64_t wait_create_tablets_cnt = ATOMIC_LOAD(&wait_create_tablets_cnt_); LOG_WARN("prepare create tablet timeout", K_(created_tablets_cnt), K_(persist_queue_cnt), K(wait_create_tablets_cnt), K(hanging_tablets_cnt), K(limit_size), - K(mstx_allocator_.total()), K(mstx_allocator_.used()), - K(tiny_allocator_.total()), K(tiny_allocator_.used())); + K(tiny_allocator_.total()), K(tiny_allocator_.used()), + K(mstx_mem_ctx_->hold()), K(mstx_mem_ctx_->used())); } } } while (need_wait); @@ -128,9 +139,10 @@ int ObFullTabletCreator::create_tablet(ObTabletHandle &tablet_handle) ObTablet *tablet = nullptr; ObArenaAllocator *allocator = nullptr; ObMetaDiskAddr mem_addr; - const int64_t page_size = OB_MALLOC_NORMAL_BLOCK_SIZE - FIFO_START_OFFSET; + const int64_t page_size = OB_MALLOC_NORMAL_BLOCK_SIZE; - if (OB_ISNULL(allocator = OB_NEWx(ObArenaAllocator, (&tiny_allocator_), mstx_allocator_, page_size))) { + if (OB_ISNULL(allocator = OB_NEWx( + ObArenaAllocator, (&tiny_allocator_), mstx_mem_ctx_->get_malloc_allocator(), page_size))) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("fail to new arena allocator", K(ret)); /* TODO(zhuixin.gsy) rm these set_xx after merge master*/ @@ -259,8 +271,8 @@ int ObFullTabletCreator::persist_tablet() const int64_t wait_create_tablets_cnt = ATOMIC_LOAD(&wait_create_tablets_cnt_); FLOG_INFO("Finish persist task one round", K(persist_tablets_cnt), K(error_tablets_cnt), K(retry_tablets_cnt), K_(created_tablets_cnt), K_(persist_queue_cnt), K(wait_create_tablets_cnt), K(hanging_tablets_cnt), - K(mstx_allocator_.total()), K(mstx_allocator_.used()), - K(tiny_allocator_.total()), K(tiny_allocator_.used())); + K(tiny_allocator_.total()), K(tiny_allocator_.used()), + K(mstx_mem_ctx_->hold()), K(mstx_mem_ctx_->used())); } return ret; } diff --git a/src/storage/tablet/ob_full_tablet_creator.h b/src/storage/tablet/ob_full_tablet_creator.h index 1518986c0..dfe690cef 100644 --- a/src/storage/tablet/ob_full_tablet_creator.h +++ b/src/storage/tablet/ob_full_tablet_creator.h @@ -17,6 +17,7 @@ #include "lib/allocator/page_arena.h" #include "lib/list/ob_dlist.h" #include "storage/meta_mem/ob_tablet_handle.h" +#include "lib/rc/context.h" namespace oceanbase { @@ -42,23 +43,23 @@ public: int create_tablet(ObTabletHandle &tablet_handle); int persist_tablet(); void destroy_queue(); // used to release tablets when t3m::destroy - common::ObIAllocator &get_allocator() { return mstx_allocator_; } /* ATTENTION: below functions should be called without any ls_tablet or t3m locks */ int throttle_tablet_creation(); int push_tablet_to_queue(const ObTabletHandle &tablet_handle); int remove_tablet_from_queue(const ObTabletHandle &tablet_handle); void free_tablet(ObTablet *tablet); - OB_INLINE int64_t total() const { return tiny_allocator_.total() + mstx_allocator_.total(); } - OB_INLINE int64_t used() const { return tiny_allocator_.used() + mstx_allocator_.used(); } + OB_INLINE int64_t total() const { + return tiny_allocator_.total() + (nullptr == mstx_mem_ctx_ ? 0 : mstx_mem_ctx_->hold()); } + OB_INLINE int64_t used() const { + return tiny_allocator_.used() + (nullptr == mstx_mem_ctx_ ? 0 : mstx_mem_ctx_->used()); } OB_INLINE int64_t get_used_obj_cnt() const { return ATOMIC_LOAD(&created_tablets_cnt_); } - TO_STRING_KV(K(mstx_allocator_.used()), K(mstx_allocator_.total()), - K(tiny_allocator_.used()), K(tiny_allocator_.total()), - "full allocator total", total()); + TO_STRING_KV(K(tiny_allocator_.used()), K(tiny_allocator_.total()), + "full allocator used", used(), "full allocator total", total()); private: int pop_tablet(ObTabletHandle &tablet_handle); + common::ObIAllocator &get_allocator() { return mstx_mem_ctx_->get_malloc_allocator(); } private: bool is_inited_; - common::ObFIFOAllocator mstx_allocator_; common::ObFIFOAllocator tiny_allocator_; ObTabletHandle transform_head_; // for transform thread ObTabletHandle transform_tail_; // for transform thread @@ -66,6 +67,7 @@ private: int64_t created_tablets_cnt_; // tablets has been created int64_t persist_queue_cnt_; // tablets in persist queue lib::ObMutex mutex_; + lib::MemoryContext mstx_mem_ctx_; DISALLOW_COPY_AND_ASSIGN(ObFullTabletCreator); }; } // namespace storage