add memattr to memory of glibc_malloc

This commit is contained in:
tushicheng
2023-05-18 13:18:37 +00:00
committed by ob-robot
parent 9d3fa298b7
commit 80ee109d1c
2 changed files with 32 additions and 2 deletions

View File

@ -17,8 +17,12 @@
using namespace oceanbase;
using namespace oceanbase::common;
using namespace oceanbase::lib;
bool g_malloc_hook_inited = false;
thread_local ObMemAttr ObMallocHookAttrGuard::tl_mem_attr(OB_SERVER_TENANT_ID,
"glibc_malloc",
ObCtxIds::GLIBC);
void init_malloc_hook()
{
g_malloc_hook_inited = true;
@ -57,7 +61,7 @@ void *ob_malloc_retry(size_t size)
{
void *ptr = nullptr;
do {
ObMemAttr attr(OB_SERVER_TENANT_ID, "glibc_malloc", ObCtxIds::GLIBC);
ObMemAttr attr = ObMallocHookAttrGuard::get_tl_mem_attr();
SET_USE_500(attr);
ptr = ob_malloc(size, attr);
if (OB_ISNULL(ptr)) {

View File

@ -12,7 +12,7 @@
#ifndef MALLOC_HOOK_H
#define MALLOC_HOOK_H
#include "lib/alloc/alloc_struct.h"
extern void init_malloc_hook();
inline bool& in_hook()
@ -20,5 +20,31 @@ inline bool& in_hook()
thread_local bool in_hook = false;
return in_hook;
}
namespace oceanbase
{
namespace lib
{
class ObMallocHookAttrGuard
{
public:
ObMallocHookAttrGuard(ObMemAttr& attr)
: old_attr_(tl_mem_attr)
{
tl_mem_attr = attr;
}
~ObMallocHookAttrGuard()
{
tl_mem_attr = old_attr_;
}
static ObMemAttr get_tl_mem_attr()
{
return tl_mem_attr;
}
private:
static thread_local ObMemAttr tl_mem_attr;
ObMemAttr old_attr_;
};
}
}
#endif /* MALLOC_HOOK_H */