add memattr to memory of glibc_malloc
This commit is contained in:
6
deps/oblib/src/lib/alloc/malloc_hook.cpp
vendored
6
deps/oblib/src/lib/alloc/malloc_hook.cpp
vendored
@ -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)) {
|
||||
|
||||
28
deps/oblib/src/lib/alloc/malloc_hook.h
vendored
28
deps/oblib/src/lib/alloc/malloc_hook.h
vendored
@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user