Add sys_parameter: _force_explict_500_malloc && Make the 500 anti-fallback test effective

This commit is contained in:
obdev
2023-06-06 04:12:22 +00:00
committed by ob-robot
parent 56e4920428
commit 6307df5985
18 changed files with 95 additions and 120 deletions

View File

@ -16,6 +16,7 @@
#include "lib/alloc/alloc_struct.h"
#include "lib/alloc/object_set.h"
#include "lib/alloc/memory_sanity.h"
#include "lib/alloc/memory_dump.h"
#include "lib/utility/ob_tracepoint.h"
#include "lib/allocator/ob_mem_leak_checker.h"
#include "lib/allocator/ob_page_manager.h"
@ -90,7 +91,7 @@ void *ObMallocAllocator::alloc(const int64_t size)
return alloc(size, attr);
}
void *ObMallocAllocator::alloc(const int64_t size, const oceanbase::lib::ObMemAttr &attr)
void *ObMallocAllocator::alloc(const int64_t size, const oceanbase::lib::ObMemAttr &_attr)
{
#ifdef OB_USE_ASAN
UNUSED(attr);
@ -101,20 +102,20 @@ void *ObMallocAllocator::alloc(const int64_t size, const oceanbase::lib::ObMemAt
int ret = OB_E(EventTable::EN_4) OB_SUCCESS;
void *ptr = NULL;
ObTenantCtxAllocatorGuard allocator = NULL;
oceanbase::lib::ObMemAttr inner_attr = attr;
#ifdef ENABLE_500_FALLBACK
const bool do_not_use_me = OB_SERVER_TENANT_ID == attr.tenant_id_ && !attr.use_500() &&
mtl_id() != OB_SERVER_TENANT_ID;
if (do_not_use_me) {
inner_attr.tenant_id_ = mtl_id();
inner_attr.ctx_id_ = ObCtxIds::DO_NOT_USE_ME;
lib::ObMemAttr attr = _attr;
if (OB_INVALID_TENANT_ID == attr.tenant_id_) {
LOG_ERROR("invalid tenant id", K(attr.tenant_id_));
attr.tenant_id_ = OB_SERVER_TENANT_ID;
}
#else
const bool do_not_use_me = false;
#endif
if (OB_INVALID_TENANT_ID == inner_attr.tenant_id_) {
inner_attr.tenant_id_ = OB_SERVER_TENANT_ID;
LOG_ERROR("invalid tenant id", K(attr.tenant_id_), K(inner_attr.tenant_id_), K(ret));
lib::ObMemAttr inner_attr = attr;
bool do_not_use_me = false;
if (FORCE_EXPLICT_500_MALLOC()) {
do_not_use_me = OB_SERVER_TENANT_ID == attr.tenant_id_ && !attr.use_500() &&
ob_thread_tenant_id() != OB_SERVER_TENANT_ID;
if (do_not_use_me) {
inner_attr.tenant_id_ = ob_thread_tenant_id();
inner_attr.ctx_id_ = ObCtxIds::DO_NOT_USE_ME;
}
}
if (OB_SUCCESS != ret) {
} else if (OB_UNLIKELY(0 == inner_attr.tenant_id_)
@ -138,13 +139,15 @@ void *ObMallocAllocator::alloc(const int64_t size, const oceanbase::lib::ObMemAt
if (OB_SUCC(ret)) {
if (do_not_use_me) {
if (OB_ISNULL(ptr = allocator->alloc(size, inner_attr))) {
inner_attr = attr;
allocator = get_tenant_ctx_allocator(inner_attr.tenant_id_, inner_attr.ctx_id_);
}
ptr = allocator->alloc(size, inner_attr);
}
if (!ptr) {
ptr = allocator->alloc(size, inner_attr);
inner_attr = attr;
allocator = get_tenant_ctx_allocator(inner_attr.tenant_id_, inner_attr.ctx_id_);
if (OB_ISNULL(allocator)) {
} else {
ptr = allocator->alloc(size, inner_attr);
}
}
}
@ -316,10 +319,8 @@ int ObMallocAllocator::create_tenant_allocator(uint64_t tenant_id, void *buf,
ObTenantCtxAllocator(tenant_id, ctx_id);
if (OB_FAIL(ctx_allocator->set_tenant_memory_mgr())) {
LOG_ERROR("set_tenant_memory_mgr failed", K(ret));
#ifdef ENABLE_500_FALLBACK
} else if (ObCtxIds::DO_NOT_USE_ME == ctx_id) {
ctx_allocator->set_limit(50L<<20);
#endif
ctx_allocator->set_limit(256L<<20);
}
}
if (OB_SUCC(ret)) {
@ -606,11 +607,6 @@ void ObMallocAllocator::add_tenant_allocator_unrecycled(ObTenantCtxAllocator *al
if (enable_tenant_leak_memory_protection_) {
modify_tenant_memory_access_permission(allocator, false);
}
#endif
#ifdef ENABLE_500_FALLBACK
for (int64_t ctx_id = 0; ctx_id < ObCtxIds::MAX_CTX_ID; ctx_id++) {
allocator[ctx_id].set_deleted(true);
}
#endif
ObDisableDiagnoseGuard disable_diagnose_guard;
ObLatchWGuard guard(unrecycled_lock_, ObLatchIds::OB_ALLOCATOR_LOCK);
@ -637,11 +633,6 @@ ObTenantCtxAllocator *ObMallocAllocator::take_off_tenant_allocator_unrecycled(ui
}
}
if (ta != NULL) {
#ifdef ENABLE_500_FALLBACK
for (int64_t ctx_id = 0; ctx_id < ObCtxIds::MAX_CTX_ID; ctx_id++) {
ta[ctx_id].set_deleted(false);
}
#endif
#ifdef ENABLE_SANITY
modify_tenant_memory_access_permission(ta, true);
#endif
@ -779,51 +770,5 @@ void ObMallocAllocator::modify_tenant_memory_access_permission(ObTenantCtxAlloca
}
#endif
#ifdef ENABLE_500_FALLBACK
int64_t __attribute__((weak)) mtl_id()
{
return OB_SERVER_TENANT_ID;
}
#endif
void ObMallocAllocator::print_malloc_sample(uint64_t tenant_id) const
{
UNUSED(tenant_id);
#ifdef ENABLE_500_FALLBACK
int ret = OB_SUCCESS;
auto &mem_dump = ObMemoryDump().get_instance();
if (OB_UNLIKELY(!mem_dump.is_inited())) {
ret = OB_NOT_INIT;
SERVER_LOG(WARN, "mem dump not inited", K(ret));
} else {
ObLatchRGuard guard(mem_dump.iter_lock_, common::ObLatchIds::MEM_DUMP_ITER_LOCK);
auto &sample_map = mem_dump.r_stat_->malloc_sample_map_;
char buf[4096];
int64_t buf_len = sizeof(buf);
int64_t pos = 0;
for (auto it = sample_map.begin(); OB_SUCC(ret) && it != sample_map.end(); it++) {
if (it->first.tenant_id_ == tenant_id) {
void **bt[ARRAYSIZEOF(it->first.bt_)];
MEMCPY(bt, it->first.bt_, sizeof(bt));
char bt_str[512];
parray(bt_str, sizeof(bt_str), (int64_t*)bt, ARRAYSIZEOF(bt));
ret = databuff_printf(buf, buf_len, pos,
"[MEMORY][LEAK_INFO] tenant=%'10ld ctx=%20s mod=%15s alloc_bytes=%'10ld lbt=%s\n",
it->first.tenant_id_,
get_global_ctx_info().get_ctx_name(it->first.ctx_id_),
it->first.label_, it->second.alloc_bytes_, bt_str);
if (OB_SUCC(ret) && pos > sizeof(buf)/2) {
_LOG_INFO("\n%.*s", static_cast<int32_t>(pos), buf);
pos = 0;
}
}
}
if (OB_SUCC(ret) && pos > 0) {
_LOG_INFO("\n%.*s", static_cast<int32_t>(pos), buf);
}
}
#endif
}
} // end of namespace lib
} // end of namespace oceanbase