Fix the low utilization of SimpleAllocer
This commit is contained in:
2
deps/oblib/src/lib/hash/ob_hashutils.h
vendored
2
deps/oblib/src/lib/hash/ob_hashutils.h
vendored
@ -1399,6 +1399,8 @@ public:
|
||||
void take_off_from_fl(Block *block)
|
||||
{
|
||||
if (block == block->next) {
|
||||
abort_unless(block == block_free_list_);
|
||||
block->prev = block->next = NULL;
|
||||
block_free_list_ = NULL;
|
||||
} else {
|
||||
block->prev->next = block->next;
|
||||
|
||||
1
deps/oblib/unittest/lib/CMakeLists.txt
vendored
1
deps/oblib/unittest/lib/CMakeLists.txt
vendored
@ -51,6 +51,7 @@ oblib_addtest(hash/test_cuckoo_hashmap.cpp)
|
||||
oblib_addtest(hash/test_hashmap.cpp)
|
||||
oblib_addtest(hash/test_fnv_hash.cpp)
|
||||
oblib_addtest(hash/test_hashset.cpp)
|
||||
oblib_addtest(hash/test_hashutils.cpp)
|
||||
oblib_addtest(hash/test_iteratable_hashmap.cpp)
|
||||
oblib_addtest(hash/test_iteratable_hashset.cpp)
|
||||
oblib_addtest(hash/test_link_hashmap.cpp)
|
||||
|
||||
87
deps/oblib/unittest/lib/hash/test_hashutils.cpp
vendored
Normal file
87
deps/oblib/unittest/lib/hash/test_hashutils.cpp
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#define private public
|
||||
#include "lib/hash/ob_hashset.h"
|
||||
#include "lib/hash/ob_hashutils.h"
|
||||
#undef private
|
||||
#include "lib/allocator/ob_malloc.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace oceanbase;
|
||||
using namespace common;
|
||||
using namespace hash;
|
||||
|
||||
class TestHashUtils: public ::testing::Test
|
||||
{
|
||||
public:
|
||||
virtual void SetUp() {}
|
||||
virtual void TearDown() {}
|
||||
};
|
||||
|
||||
struct MySimpleAllocer
|
||||
{
|
||||
public:
|
||||
explicit MySimpleAllocer()
|
||||
{
|
||||
used_cnt_ = 0;
|
||||
}
|
||||
void *alloc(const int64_t sz)
|
||||
{
|
||||
used_cnt_++;
|
||||
return ob_malloc(sz, attr_);
|
||||
}
|
||||
void free(void *p)
|
||||
{
|
||||
ob_free(p);
|
||||
used_cnt_--;
|
||||
}
|
||||
void set_attr(const ObMemAttr &attr) { attr_ = attr; }
|
||||
void set_label(const lib::ObLabel &label) { attr_.label_ = label; }
|
||||
int64_t used_cnt_;
|
||||
ObMemAttr attr_;
|
||||
};
|
||||
|
||||
TEST_F(TestHashUtils, Basic)
|
||||
{
|
||||
static constexpr int NODE_NUM = 2;
|
||||
using TestAlloc = hash::SimpleAllocer<int, NODE_NUM, SpinMutexDefendMode, MySimpleAllocer>;
|
||||
TestAlloc alloc;
|
||||
int *obj = alloc.alloc();
|
||||
ASSERT_TRUE(obj != NULL);
|
||||
int *obj2 = alloc.alloc();
|
||||
ASSERT_TRUE(obj2 != NULL);
|
||||
alloc.free(obj2);
|
||||
int *obj3 = alloc.alloc();
|
||||
ASSERT_EQ(obj3, obj2);
|
||||
alloc.free(obj3);
|
||||
int *obj4 = alloc.alloc();
|
||||
ASSERT_EQ(obj4, obj3);
|
||||
alloc.free(obj);
|
||||
alloc.free(obj4);
|
||||
ASSERT_EQ(0, alloc.allocer_.used_cnt_);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
oceanbase::common::ObLogger::get_logger().set_log_level("INFO");
|
||||
OB_LOGGER.set_log_level("INFO");
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@ -864,7 +864,8 @@ int select_sysstat(lua_State* L)
|
||||
GCTX.omt_->get_tenant_ids(ids);
|
||||
LuaVtableGenerator gen(L, columns);
|
||||
for (int64_t i = 0; i < ids.size() && !gen.is_end(); ++i) {
|
||||
HEAP_VAR(ObDiagnoseTenantInfo, diag_info) {
|
||||
ObArenaAllocator diag_allocator;
|
||||
HEAP_VAR(ObDiagnoseTenantInfo, diag_info, &diag_allocator) {
|
||||
if (OB_FAIL(ObDIGlobalTenantCache::get_instance().get_the_diag_info(ids.at(i), diag_info))) {
|
||||
OB_LOG(ERROR, "failed to get_the_diag_info", K(ids.at(i)), K(ret));
|
||||
} else if (OB_FAIL(observer::ObAllVirtualSysStat::update_all_stats(ids.at(i), diag_info.get_set_stat_stats()))) {
|
||||
@ -2016,7 +2017,8 @@ int enable_system_tenant_memory_limit(lua_State* L)
|
||||
int get_tenant_sysstat(int64_t tenant_id, int64_t statistic, int64_t &value)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
HEAP_VAR(ObDiagnoseTenantInfo, diag_info) {
|
||||
ObArenaAllocator diag_allocator;
|
||||
HEAP_VAR(ObDiagnoseTenantInfo, diag_info, &diag_allocator) {
|
||||
if (statistic < 0
|
||||
|| statistic >= ObStatEventIds::STAT_EVENT_SET_END
|
||||
|| ObStatEventIds::STAT_EVENT_ADD_END == statistic) {
|
||||
|
||||
@ -28,7 +28,7 @@ ObAllVirtualSysEvent::ObAllVirtualSysEvent()
|
||||
port_(0),
|
||||
event_iter_(0),
|
||||
tenant_id_(OB_INVALID_ID),
|
||||
diag_info_()
|
||||
diag_info_(allocator_)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@ -33,7 +33,7 @@ ObAllVirtualSysStat::ObAllVirtualSysStat()
|
||||
port_(0),
|
||||
stat_iter_(0),
|
||||
tenant_id_(OB_INVALID_TENANT_ID),
|
||||
diag_info_()
|
||||
diag_info_(allocator_)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ ObInfoSchemaKvCacheTable::ObInfoSchemaKvCacheTable()
|
||||
cache_iter_(0),
|
||||
str_buf_(),
|
||||
arenallocator_(),
|
||||
tenant_di_info_(),
|
||||
tenant_di_info_(allocator_),
|
||||
tenant_dis_()
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user