Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bazel/seekdb_build_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@ def seekdb_sanity_cxxopts(instrument):

def seekdb_sanity_local_defines():
return select({
_SEEKDB_SANITY_CONFIG: ["ENABLE_SANITY"],
_SEEKDB_SANITY_CONFIG: [
"ENABLE_SANITY",
"OB_HAVE_BUNDLED_JEMALLOC=1",
],
"//conditions:default": [],
})

Expand Down
6 changes: 6 additions & 0 deletions bazel/third_party_headers_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ cc_library(
includes = ["devtools/include"],
)

cc_library(
name = "jemalloc_headers",
hdrs = glob(["include/jemalloc/**/*." + extension for extension in HEADER_EXTENSIONS], allow_empty = True),
includes = ["include"],
)

filegroup(
name = "sanity_pass",
srcs = ["devtools/lib64/libsanitypass.so"],
Expand Down
9 changes: 2 additions & 7 deletions src/oblib/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ seekdb_semantic_unity_cc_library(
implementation_deps = [
":_oblib_implementation_headers",
":oblib_foundation",
"@seekdb_3rd_headers//:jemalloc_headers",
],
copts = SEEKDB_OBLIB_COPTS,
local_defines = SEEKDB_OBLIB_LOCAL_DEFINES,
Expand Down Expand Up @@ -420,13 +421,7 @@ cc_library(
name = "ob_malloc_objects",
implementation_deps = [
":_ob_malloc_impl",
] + select({
"//bazel:sanity_enabled": [
"//bazel:sanity_abort_runtime",
"@seekdb_3rd_headers//:sanity_runtime",
],
"//conditions:default": [],
}),
],
tags = ["manual"],
visibility = ["//src/observer:__pkg__"],
)
Expand Down
35 changes: 35 additions & 0 deletions src/oblib/lib/allocator/ob_jemalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,25 @@ namespace oceanbase
namespace common
{

#if defined(ENABLE_SANITY) && defined(OB_HAVE_BUNDLED_JEMALLOC)
void *jemalloc_sanity_malloc(size_t size) noexcept;
void jemalloc_sanity_free(void *ptr) noexcept;
void *jemalloc_sanity_realloc(void *ptr, size_t size) noexcept;
void *jemalloc_sanity_memalign(size_t alignment, size_t size) noexcept;
size_t jemalloc_sanity_usable_size(void *ptr) noexcept;
bool jemalloc_sanity_enable_background_threads() noexcept;
void jemalloc_sanity_poison(const void *ptr, size_t size) noexcept;
void jemalloc_sanity_unpoison(const void *ptr, size_t size) noexcept;
#endif

inline void *jemalloc_malloc(const size_t size)
{
#if defined(OB_HAVE_BUNDLED_JEMALLOC)
#if defined(ENABLE_SANITY)
return jemalloc_sanity_malloc(size);
#else
return je_malloc(size);
#endif
#else
(void)size;
return nullptr;
Expand All @@ -51,7 +66,11 @@ inline void *jemalloc_malloc(const size_t size)
inline void jemalloc_free(void *ptr)
{
#if defined(OB_HAVE_BUNDLED_JEMALLOC)
#if defined(ENABLE_SANITY)
jemalloc_sanity_free(ptr);
#else
je_free(ptr);
#endif
#else
(void)ptr;
#endif
Expand All @@ -60,7 +79,11 @@ inline void jemalloc_free(void *ptr)
inline void *jemalloc_realloc(void *ptr, const size_t size)
{
#if defined(OB_HAVE_BUNDLED_JEMALLOC)
#if defined(ENABLE_SANITY)
return jemalloc_sanity_realloc(ptr, size);
#else
return je_realloc(ptr, size);
#endif
#else
(void)ptr;
(void)size;
Expand All @@ -71,12 +94,16 @@ inline void *jemalloc_realloc(void *ptr, const size_t size)
inline void *jemalloc_memalign(const size_t alignment, const size_t size)
{
#if defined(OB_HAVE_BUNDLED_JEMALLOC)
#if defined(ENABLE_SANITY)
return jemalloc_sanity_memalign(alignment, size);
#else
#if defined(__APPLE__)
void *ptr = nullptr;
return 0 == je_posix_memalign(&ptr, alignment, size) ? ptr : nullptr;
#else
return je_memalign(alignment, size);
#endif
#endif
#else
(void)alignment;
(void)size;
Expand All @@ -87,7 +114,11 @@ inline void *jemalloc_memalign(const size_t alignment, const size_t size)
inline size_t jemalloc_usable_size(void *ptr)
{
#if defined(OB_HAVE_BUNDLED_JEMALLOC)
#if defined(ENABLE_SANITY)
return nullptr == ptr ? 0 : jemalloc_sanity_usable_size(ptr);
#else
return nullptr == ptr ? 0 : je_malloc_usable_size(ptr);
#endif
#else
(void)ptr;
return 0;
Expand All @@ -97,9 +128,13 @@ inline size_t jemalloc_usable_size(void *ptr)
inline bool jemalloc_enable_background_threads()
{
#if defined(OB_HAVE_BUNDLED_JEMALLOC)
#if defined(ENABLE_SANITY)
return jemalloc_sanity_enable_background_threads();
#else
bool enabled = true;
return 0 == je_mallctl("background_thread", nullptr, nullptr,
&enabled, sizeof(enabled));
#endif
#else
return true;
#endif
Expand Down
Loading
Loading