From 3c716958ddd9e53b21fa98c1e2702127b3574460 Mon Sep 17 00:00:00 2001 From: obdev Date: Wed, 27 Sep 2023 03:10:12 +0000 Subject: [PATCH] Optimize memory release performance for logger --- deps/oblib/src/lib/CMakeLists.txt | 2 +- deps/oblib/src/lib/alloc/alloc_interface.h | 4 +- .../src/lib/alloc/ob_tenant_ctx_allocator.h | 7 +- deps/oblib/src/lib/alloc/object_mgr.cpp | 25 ++++--- deps/oblib/src/lib/alloc/object_mgr.h | 11 ++-- deps/oblib/src/lib/alloc/object_set.cpp | 9 +-- deps/oblib/src/lib/alloc/object_set.h | 4 +- ..._parallel_define.cpp => ob_ctx_define.cpp} | 6 +- deps/oblib/src/lib/allocator/ob_ctx_define.h | 66 +++++++++++++++++++ .../lib/allocator/ob_ctx_parallel_define.h | 54 --------------- .../unittest/lib/alloc/test_object_mgr.cpp | 2 +- 11 files changed, 108 insertions(+), 82 deletions(-) rename deps/oblib/src/lib/allocator/{ob_ctx_parallel_define.cpp => ob_ctx_define.cpp} (84%) create mode 100644 deps/oblib/src/lib/allocator/ob_ctx_define.h delete mode 100644 deps/oblib/src/lib/allocator/ob_ctx_parallel_define.h diff --git a/deps/oblib/src/lib/CMakeLists.txt b/deps/oblib/src/lib/CMakeLists.txt index 610ece35aa..a669eb1151 100644 --- a/deps/oblib/src/lib/CMakeLists.txt +++ b/deps/oblib/src/lib/CMakeLists.txt @@ -268,7 +268,7 @@ ob_set_subtarget(ob_malloc_object_list common_alloc allocator/ob_allocator_v2.cpp allocator/ob_block_alloc_mgr.cpp allocator/ob_concurrent_fifo_allocator.cpp - allocator/ob_ctx_parallel_define.cpp + allocator/ob_ctx_define.cpp allocator/ob_delay_free_allocator.cpp allocator/ob_fifo_allocator.cpp allocator/ob_hazard_ref.cpp diff --git a/deps/oblib/src/lib/alloc/alloc_interface.h b/deps/oblib/src/lib/alloc/alloc_interface.h index 3e32ac2aee..d81bb7378d 100644 --- a/deps/oblib/src/lib/alloc/alloc_interface.h +++ b/deps/oblib/src/lib/alloc/alloc_interface.h @@ -84,10 +84,10 @@ private: }; template -class SetLockerForLogger : public ISetLocker +class SetLockerNoLog : public ISetLocker { public: - SetLockerForLogger(t_lock &mutex) + SetLockerNoLog(t_lock &mutex) : mutex_(mutex), is_disable_(false) {} void lock() override { diff --git a/deps/oblib/src/lib/alloc/ob_tenant_ctx_allocator.h b/deps/oblib/src/lib/alloc/ob_tenant_ctx_allocator.h index bcfc6309e6..5a33f96828 100644 --- a/deps/oblib/src/lib/alloc/ob_tenant_ctx_allocator.h +++ b/deps/oblib/src/lib/alloc/ob_tenant_ctx_allocator.h @@ -43,7 +43,9 @@ public: : resource_handle_(), ref_cnt_(0), tenant_id_(tenant_id), ctx_id_(ctx_id), deleted_(false), obj_mgr_(*this, tenant_id_, ctx_id_, INTACT_NORMAL_AOBJECT_SIZE, - common::ObCtxParallel::instance().parallel_of_ctx(ctx_id_), NULL), + CTX_ATTR(ctx_id).parallel_, + CTX_ATTR(ctx_id).enable_dirty_list_, + NULL), idle_size_(0), head_chunk_(), chunk_cnt_(0), chunk_freelist_mutex_(common::ObLatchIds::CHUNK_FREE_LIST_LOCK), using_list_mutex_(common::ObLatchIds::CHUNK_USING_LIST_LOCK), @@ -58,7 +60,8 @@ public: chunk_freelist_mutex_.enable_record_stat(false); using_list_mutex_.enable_record_stat(false); for (int i = 0; i < ObSubCtxIds::MAX_SUB_CTX_ID; ++i) { - new (obj_mgrs_ + i) ObjectMgr(*this, tenant_id_, ctx_id_, INTACT_MIDDLE_AOBJECT_SIZE, 4, &obj_mgr_); + new (obj_mgrs_ + i) ObjectMgr(*this, tenant_id_, ctx_id_, INTACT_MIDDLE_AOBJECT_SIZE, + 4/*parallel*/, false/*enable_dirty_list*/, &obj_mgr_); } } virtual ~ObTenantCtxAllocator() diff --git a/deps/oblib/src/lib/alloc/object_mgr.cpp b/deps/oblib/src/lib/alloc/object_mgr.cpp index e0fe0f0f59..492ef31a47 100644 --- a/deps/oblib/src/lib/alloc/object_mgr.cpp +++ b/deps/oblib/src/lib/alloc/object_mgr.cpp @@ -11,6 +11,7 @@ */ #include "object_mgr.h" +#include "lib/allocator/ob_ctx_define.h" #include "lib/alloc/ob_malloc_allocator.h" #include "lib/alloc/memory_sanity.h" @@ -18,12 +19,14 @@ using namespace oceanbase; using namespace lib; SubObjectMgr::SubObjectMgr(const bool for_logger, const int64_t tenant_id, const int64_t ctx_id, - const uint32_t ablock_size, IBlockMgr *blk_mgr) + const uint32_t ablock_size, + const bool enable_dirty_list, + IBlockMgr *blk_mgr) : IBlockMgr(tenant_id, ctx_id), mutex_(common::ObLatchIds::ALLOC_OBJECT_LOCK), - normal_locker_(mutex_), logger_locker_(mutex_), + normal_locker_(mutex_), no_log_locker_(mutex_), locker_(!for_logger ? static_cast(normal_locker_) : - static_cast(logger_locker_)), - bs_(), os_(NULL, ablock_size) + static_cast(no_log_locker_)), + bs_(), os_(NULL, ablock_size, enable_dirty_list) { bs_.set_locker(&locker_); os_.set_locker(&locker_); @@ -61,10 +64,12 @@ void SubObjectMgr::free_block(ABlock *block) } ObjectMgr::ObjectMgr(ObTenantCtxAllocator &allocator, uint64_t tenant_id, uint64_t ctx_id, - uint32_t ablock_size, int parallel, IBlockMgr *blk_mgr) + uint32_t ablock_size, int parallel, bool enable_dirty_list, IBlockMgr *blk_mgr) : IBlockMgr(tenant_id, ctx_id), ta_(allocator), - ablock_size_(ablock_size), parallel_(parallel), blk_mgr_(blk_mgr), sub_cnt_(1), - root_mgr_(common::ObCtxIds::LOGGER_CTX_ID == ctx_id, tenant_id, ctx_id, ablock_size_, blk_mgr_), + ablock_size_(ablock_size), parallel_(parallel), enable_dirty_list_(enable_dirty_list), + blk_mgr_(blk_mgr), sub_cnt_(1), + root_mgr_(CTX_ATTR(ctx_id).enable_no_log_, tenant_id, ctx_id, ablock_size_, + enable_dirty_list, blk_mgr_), last_wash_ts_(0), last_washed_size_(0) { root_mgr_.set_tenant_ctx_allocator(allocator); @@ -229,8 +234,8 @@ SubObjectMgr *ObjectMgr::create_sub_mgr() root_mgr.unlock(); if (OB_NOT_NULL(obj)) { SANITY_UNPOISON(obj->data_, obj->alloc_bytes_); - sub_mgr = new (obj->data_) SubObjectMgr(common::ObCtxIds::LOGGER_CTX_ID == ctx_id_, tenant_id_, ctx_id_, - ablock_size_, blk_mgr_); + sub_mgr = new (obj->data_) SubObjectMgr(CTX_ATTR(ctx_id_).enable_no_log_, tenant_id_, ctx_id_, + ablock_size_, enable_dirty_list_, blk_mgr_); sub_mgr->set_tenant_ctx_allocator(ta_); } return sub_mgr; @@ -326,4 +331,4 @@ bool ObjectMgr::check_has_unfree(char *first_label) } } return has_unfree; -} \ No newline at end of file +} diff --git a/deps/oblib/src/lib/alloc/object_mgr.h b/deps/oblib/src/lib/alloc/object_mgr.h index 051dd38b64..84ee0f0306 100644 --- a/deps/oblib/src/lib/alloc/object_mgr.h +++ b/deps/oblib/src/lib/alloc/object_mgr.h @@ -13,7 +13,7 @@ #ifndef _OCEABASE_LIB_ALLOC_OBJECT_MGR_H_ #define _OCEABASE_LIB_ALLOC_OBJECT_MGR_H_ -#include "lib/allocator/ob_ctx_parallel_define.h" +#include "lib/allocator/ob_ctx_define.h" #include "lib/thread_local/ob_tsi_utils.h" #include "lib/random/ob_random.h" #include "lib/ob_abort.h" @@ -37,7 +37,8 @@ class SubObjectMgr : public IBlockMgr friend class ObTenantCtxAllocator; public: SubObjectMgr(const bool for_logger, const int64_t tenant_id, const int64_t ctx_id, - const uint32_t ablock_size, IBlockMgr *blk_mgr); + const uint32_t ablock_size, const bool enable_dirty_list, + IBlockMgr *blk_mgr); virtual ~SubObjectMgr() {} OB_INLINE void set_tenant_ctx_allocator(ObTenantCtxAllocator &allocator) { @@ -75,7 +76,7 @@ private: lib::ObMutexV2 mutex_; #endif SetLocker normal_locker_; - SetLockerForLogger logger_locker_; + SetLockerNoLog no_log_locker_; ISetLocker &locker_; BlockSet bs_; ObjectSet os_; @@ -95,7 +96,8 @@ public: }; public: ObjectMgr(ObTenantCtxAllocator &allocator, uint64_t tenant_id, uint64_t ctx_id, - uint32_t ablock_size, int parallel, IBlockMgr *blk_mgr); + uint32_t ablock_size, int parallel, bool enable_dirty_list, + IBlockMgr *blk_mgr); ~ObjectMgr(); void reset(); @@ -120,6 +122,7 @@ public: ObTenantCtxAllocator &ta_; uint32_t ablock_size_; int parallel_; + bool enable_dirty_list_; IBlockMgr *blk_mgr_; int sub_cnt_; SubObjectMgr root_mgr_; diff --git a/deps/oblib/src/lib/alloc/object_set.cpp b/deps/oblib/src/lib/alloc/object_set.cpp index f6162807d1..e69b55c941 100644 --- a/deps/oblib/src/lib/alloc/object_set.cpp +++ b/deps/oblib/src/lib/alloc/object_set.cpp @@ -34,14 +34,15 @@ void __attribute__((weak)) has_unfree_callback(char *info) _OB_LOG_RET(ERROR, OB_ERROR, "HAS UNFREE PTR!!! %s", info); } -ObjectSet::ObjectSet(__MemoryContext__ *mem_context, const uint32_t ablock_size) +ObjectSet::ObjectSet(__MemoryContext__ *mem_context, const uint32_t ablock_size, + const bool enable_dirty_list) : mem_context_(mem_context), locker_(nullptr), blk_mgr_(nullptr), blist_(NULL), last_remainder_(NULL), bm_(NULL), free_lists_(NULL), dirty_list_mutex_(common::ObLatchIds::ALLOC_OBJECT_LOCK), dirty_list_(nullptr), dirty_objs_(0), alloc_bytes_(0), used_bytes_(0), hold_bytes_(0), allocs_(0), normal_alloc_bytes_(0), normal_used_bytes_(0), - normal_hold_bytes_(0), ablock_size_(ablock_size), + normal_hold_bytes_(0), ablock_size_(ablock_size), enable_dirty_list_(enable_dirty_list), cells_per_block_(AllocHelper::cells_per_block(ablock_size)) {} @@ -58,7 +59,7 @@ AObject *ObjectSet::alloc_object( const int64_t ctx_id = blk_mgr_->get_ctx_id(); abort_unless(ctx_id == attr.ctx_id_); - if (OB_UNLIKELY(common::ObCtxIds::LIBEASY == ctx_id)) { + if (OB_UNLIKELY(enable_dirty_list_)) { do_free_dirty_list(); } @@ -376,7 +377,7 @@ void ObjectSet::free_object(AObject *obj) #endif const int64_t ctx_id = blk_mgr_->get_ctx_id(); ObDisableDiagnoseGuard diagnose_disable_guard; - if (ctx_id == common::ObCtxIds::LIBEASY) { + if (OB_UNLIKELY(enable_dirty_list_)) { if (locker_->trylock()) { do_free_object(obj); do_free_dirty_list(); diff --git a/deps/oblib/src/lib/alloc/object_set.h b/deps/oblib/src/lib/alloc/object_set.h index f06d5fa6bd..69947ac8bd 100644 --- a/deps/oblib/src/lib/alloc/object_set.h +++ b/deps/oblib/src/lib/alloc/object_set.h @@ -45,7 +45,8 @@ class ObjectSet public: ObjectSet(__MemoryContext__ *mem_context=nullptr, - const uint32_t ablock_size=INTACT_NORMAL_AOBJECT_SIZE); + const uint32_t ablock_size=INTACT_NORMAL_AOBJECT_SIZE, + const bool enable_dirty_list=false); ~ObjectSet(); // main interfaces @@ -119,6 +120,7 @@ private: uint64_t normal_hold_bytes_; uint32_t ablock_size_; + bool enable_dirty_list_; uint32_t cells_per_block_; DISALLOW_COPY_AND_ASSIGN(ObjectSet); diff --git a/deps/oblib/src/lib/allocator/ob_ctx_parallel_define.cpp b/deps/oblib/src/lib/allocator/ob_ctx_define.cpp similarity index 84% rename from deps/oblib/src/lib/allocator/ob_ctx_parallel_define.cpp rename to deps/oblib/src/lib/allocator/ob_ctx_define.cpp index 15241c1e6c..83e30bd662 100644 --- a/deps/oblib/src/lib/allocator/ob_ctx_parallel_define.cpp +++ b/deps/oblib/src/lib/allocator/ob_ctx_define.cpp @@ -10,15 +10,15 @@ * See the Mulan PubL v2 for more details. */ -#include "lib/allocator/ob_ctx_parallel_define.h" +#include "lib/allocator/ob_ctx_define.h" namespace oceanbase { namespace common { -ObCtxParallel &ObCtxParallel::instance() +ObCtxAttrCenter &ObCtxAttrCenter::instance() { - static ObCtxParallel instance; + static ObCtxAttrCenter instance; return instance; } } // end of namespace common diff --git a/deps/oblib/src/lib/allocator/ob_ctx_define.h b/deps/oblib/src/lib/allocator/ob_ctx_define.h new file mode 100644 index 0000000000..f6fe64aeb2 --- /dev/null +++ b/deps/oblib/src/lib/allocator/ob_ctx_define.h @@ -0,0 +1,66 @@ +/** + * Copyright (c) 2021 OceanBase + * OceanBase CE is licensed under Mulan PubL v2. + * You can use this software according to the terms and conditions of the Mulan PubL v2. + * You may obtain a copy of Mulan PubL v2 at: + * http://license.coscl.org.cn/MulanPubL-2.0 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PubL v2 for more details. + */ + +#ifndef OCEANBASE_COMMON_CTX_DEFINE_H_ +#define OCEANBASE_COMMON_CTX_DEFINE_H_ + +#include "lib/allocator/ob_mod_define.h" + +namespace oceanbase +{ +namespace common +{ + +struct ObCtxAttr +{ + const static int DEFAULT_CTX_PARALLEL = 8; + + bool enable_dirty_list_ = false; + bool enable_no_log_ = false; + int parallel_ = DEFAULT_CTX_PARALLEL; +}; + +struct ObCtxAttrCenter +{ +public: + ObCtxAttrCenter() + { +#define PARALLEL_DEF(name, parallel) ctx_attr_[ObCtxIds::name].parallel_ = parallel; + PARALLEL_DEF(DEFAULT_CTX_ID, 32) + PARALLEL_DEF(LIBEASY, 32) + PARALLEL_DEF(PLAN_CACHE_CTX_ID, 4) + PARALLEL_DEF(LOGGER_CTX_ID, 1) +#undef CTX_PARALLEL_DEF + +#define ENABLE_DIRTY_LIST_DEF(name) ctx_attr_[ObCtxIds::name].enable_dirty_list_ = true; + ENABLE_DIRTY_LIST_DEF(LIBEASY) + ENABLE_DIRTY_LIST_DEF(LOGGER_CTX_ID) +#undef ENABLE_DIRTY_LIST_DEF + +#define ENABLE_NO_LOG_DEF(name) ctx_attr_[ObCtxIds::name].enable_no_log_ = true; + ENABLE_NO_LOG_DEF(LOGGER_CTX_ID) +#undef ENABLE_NO_LOG_DEF + } + static ObCtxAttrCenter &instance(); + ObCtxAttr attr_of_ctx(int64_t ctx_id) const + { + return ctx_attr_[ctx_id]; + } +private: + ObCtxAttr ctx_attr_[ObCtxIds::MAX_CTX_ID]; +}; + +#define CTX_ATTR(ctx_id) ObCtxAttrCenter::instance().attr_of_ctx(ctx_id) +} +} + +#endif //OCEANBASE_COMMON_CTX_DEFINE_H_ diff --git a/deps/oblib/src/lib/allocator/ob_ctx_parallel_define.h b/deps/oblib/src/lib/allocator/ob_ctx_parallel_define.h deleted file mode 100644 index db5320aacc..0000000000 --- a/deps/oblib/src/lib/allocator/ob_ctx_parallel_define.h +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (c) 2021 OceanBase - * OceanBase CE is licensed under Mulan PubL v2. - * You can use this software according to the terms and conditions of the Mulan PubL v2. - * You may obtain a copy of Mulan PubL v2 at: - * http://license.coscl.org.cn/MulanPubL-2.0 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PubL v2 for more details. - */ - -#ifndef OCEANBASE_COMMON_CTX_PARALLEL_DEFINE_H_ -#define OCEANBASE_COMMON_CTX_PARALLEL_DEFINE_H_ - -#include "lib/allocator/ob_mod_define.h" - -namespace oceanbase -{ -namespace common -{ -struct ObCtxParallel -{ -public: - ObCtxParallel() - { - for (int64_t i = 0; i < ObCtxIds::MAX_CTX_ID; i++) { - parallel_[i] = DEFAULT_CTX_PARALLEL; - } -#define CTX_PARALLEL_DEF(name, parallel) parallel_[ObCtxIds::name] = parallel; - CTX_PARALLEL_DEF(DEFAULT_CTX_ID, 32) - CTX_PARALLEL_DEF(LIBEASY, 32) - CTX_PARALLEL_DEF(PLAN_CACHE_CTX_ID, 4) - CTX_PARALLEL_DEF(LOGGER_CTX_ID, 1) -#undef CTX_PARALLEL_DEF - } - static ObCtxParallel &instance(); - int parallel_of_ctx(int64_t ctx_id) const - { - int p = 0; - if (ctx_id >= 0 && ctx_id < ObCtxIds::MAX_CTX_ID) { - p = parallel_[ctx_id]; - } - return p; - } -private: - const static int DEFAULT_CTX_PARALLEL = 8; - int parallel_[ObCtxIds::MAX_CTX_ID]; -}; - -} -} - -#endif //OCEANBASE_COMMON_CTX_PARALLEL_DEFINE_H_ diff --git a/deps/oblib/unittest/lib/alloc/test_object_mgr.cpp b/deps/oblib/unittest/lib/alloc/test_object_mgr.cpp index 76a2c8e2c8..0803872b9d 100644 --- a/deps/oblib/unittest/lib/alloc/test_object_mgr.cpp +++ b/deps/oblib/unittest/lib/alloc/test_object_mgr.cpp @@ -238,7 +238,7 @@ TEST_F(TestObjectMgr, TestSubObjectMgr) abort_unless(ptr != MAP_FAILED); int64_t tenant_id = OB_SERVER_TENANT_ID; int64_t ctx_id = ObCtxIds::DEFAULT_CTX_ID; - SubObjectMgr som(false, tenant_id, ctx_id, INTACT_NORMAL_AOBJECT_SIZE, NULL); + SubObjectMgr som(false, tenant_id, ctx_id, INTACT_NORMAL_AOBJECT_SIZE, false, NULL); ObMemAttr attr; som.set_tenant_ctx_allocator(*ObMallocAllocator::get_instance()->get_tenant_ctx_allocator( tenant_id, ctx_id).ref_allocator());