From 9bb5269c64ed09f6f148a3c9dda1cc8318e9911a Mon Sep 17 00:00:00 2001 From: Tyshawn Date: Thu, 16 May 2024 12:46:49 +0000 Subject: [PATCH] [BUG.FIX] fix normal tablet buffer memory fragment --- .../storage/test_tenant_meta_mem_mgr.cpp | 29 +++++++++++++++++++ src/storage/meta_mem/ob_tenant_meta_mem_mgr.h | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/mittest/mtlenv/storage/test_tenant_meta_mem_mgr.cpp b/mittest/mtlenv/storage/test_tenant_meta_mem_mgr.cpp index df1b0671e..81407087e 100644 --- a/mittest/mtlenv/storage/test_tenant_meta_mem_mgr.cpp +++ b/mittest/mtlenv/storage/test_tenant_meta_mem_mgr.cpp @@ -17,6 +17,7 @@ #define protected public #define private public +#include "lib/alloc/memory_dump.h" #include "storage/tablet/ob_tablet_persister.h" #include "storage/meta_mem/ob_tenant_meta_mem_mgr.h" #include "storage/meta_mem/ob_tablet_leak_checker.h" @@ -1730,6 +1731,34 @@ TEST_F(TestTenantMetaMemMgr, test_show_limit) lib::set_tenant_memory_limit(MTL_ID(), before_tenant_mem); } +TEST_F(TestTenantMetaMemMgr, test_normal_tablet_buffer_fragment) +{ + static const int64_t tablet_cnt = 155000; + ObTabletHandle *tablets = new ObTabletHandle[tablet_cnt]; + const int64_t before_tenant_mem = lib::get_tenant_memory_limit(MTL_ID()); + const int64_t this_case_tenant_mem = 3 * 1024 * 1024 * 1024L; /* 3GB */ + lib::set_tenant_memory_limit(MTL_ID(), this_case_tenant_mem); + for (int64_t i = 0; i < tablet_cnt; ++i) { + ObTabletHandle tablet_handle; + ASSERT_EQ(OB_SUCCESS, MTL(ObTenantMetaMemMgr *)->acquire_tablet(ObTabletPoolType::TP_NORMAL, tablets[i])); + } + ObMallocAllocator::get_instance()->print_tenant_memory_usage(MTL_ID()); + ObMemoryDump::get_instance().init(); + auto task = ObMemoryDump::get_instance().alloc_task(); + task->type_ = STAT_LABEL; + ObMemoryDump::get_instance().push(task); + usleep(1000000); + ObTenantCtxAllocatorGuard ta = ObMallocAllocator::get_instance()->get_tenant_ctx_allocator(MTL_ID(), ObCtxIds::META_OBJ_CTX_ID); + double fragment_rate = 1.0 * (ta->get_hold() - ta->get_used()) / ta->get_hold(); + std::cout << "hold: " << ta->get_hold() << " used: " << ta->get_used() << " limit: " << ta->get_limit() << " fragment_rate: " << fragment_rate << std::endl; + ASSERT_TRUE(fragment_rate < 0.04); + for (int64_t i = 0; i < tablet_cnt; ++i) { + tablets[i].reset(); + } + delete [] tablets; + lib::set_tenant_memory_limit(MTL_ID(), before_tenant_mem); +} + } // end namespace storage } // end namespace oceanbase diff --git a/src/storage/meta_mem/ob_tenant_meta_mem_mgr.h b/src/storage/meta_mem/ob_tenant_meta_mem_mgr.h index 2d620f426..469f7320b 100644 --- a/src/storage/meta_mem/ob_tenant_meta_mem_mgr.h +++ b/src/storage/meta_mem/ob_tenant_meta_mem_mgr.h @@ -122,7 +122,7 @@ class ObTenantMetaMemMgr final { public: static const int64_t THE_SIZE_OF_HEADERS = sizeof(ObFIFOAllocator::NormalPageHeader) + sizeof(ObMetaObjBufferNode); - static const int64_t NORMAL_TABLET_POOL_SIZE = (ABLOCK_SIZE - ABLOCK_HEADER_SIZE) / 2 - AOBJECT_META_SIZE - THE_SIZE_OF_HEADERS; // 3952B + static const int64_t NORMAL_TABLET_POOL_SIZE = (ABLOCK_SIZE - ABLOCK_HEADER_SIZE) / 2 - AOBJECT_META_SIZE - AOBJECT_EXTRA_INFO_SIZE - THE_SIZE_OF_HEADERS; // 3824B static const int64_t LARGE_TABLET_POOL_SIZE = 64 * 1024L - THE_SIZE_OF_HEADERS; // 65,480B static const int64_t MIN_MODE_MAX_TABLET_CNT_IN_OBJ_POOL = 10000;