diff --git a/src/core/small_string.cc b/src/core/small_string.cc index ac49fb8ab..51a703bd1 100644 --- a/src/core/small_string.cc +++ b/src/core/small_string.cc @@ -12,7 +12,7 @@ #include "base/logging.h" #include "core/segment_allocator.h" -extern "C" bool mi_heap_page_is_underutilized(mi_heap_t* heap, void* p, float ratio); +bool mi_heap_page_is_underutilized(mi_heap_t* heap, void* p, float ratio); namespace dfly { using namespace std; diff --git a/src/redis/CMakeLists.txt b/src/redis/CMakeLists.txt index 7dc19a719..bcfbd57f4 100644 --- a/src/redis/CMakeLists.txt +++ b/src/redis/CMakeLists.txt @@ -1,7 +1,7 @@ option(REDIS_ZMALLOC_MI "Implement zmalloc layer using mimalloc allocator" ON) if (REDIS_ZMALLOC_MI) - set(ZMALLOC_SRC "zmalloc_mi.c") + set(ZMALLOC_SRC "zmalloc_mi.cc") set(ZMALLOC_DEPS "TRDP::mimalloc") else() set(ZMALLOC_SRC "zmalloc.c") diff --git a/src/redis/zmalloc_mi.c b/src/redis/zmalloc_mi.cc similarity index 98% rename from src/redis/zmalloc_mi.c rename to src/redis/zmalloc_mi.cc index 444f04cb5..5ce5b6a84 100644 --- a/src/redis/zmalloc_mi.c +++ b/src/redis/zmalloc_mi.cc @@ -7,7 +7,9 @@ #include #include +extern "C" { #include "zmalloc.h" +} __thread ssize_t zmalloc_used_memory_tl = 0; __thread mi_heap_t* zmalloc_heap = NULL; @@ -147,7 +149,7 @@ bool heap_count_wasted_blocks(const mi_heap_t* heap, const mi_heap_area_t* area, }; int zmalloc_get_allocator_info(size_t* allocated, size_t* active, size_t* resident) { - Sum_t sum = {0}; + Sum_t sum = {0, 0}; mi_heap_visit_blocks(zmalloc_heap, false /* visit all blocks*/, heap_visit_cb, &sum); *allocated = sum.allocated; @@ -172,7 +174,7 @@ int zmalloc_get_allocator_wasted_blocks(float ratio, size_t* allocated, size_t* void init_zmalloc_threadlocal(void* heap) { if (zmalloc_heap) return; - zmalloc_heap = heap; + zmalloc_heap = (mi_heap_t*)heap; } int zmalloc_page_is_underutilized(void* ptr, float ratio) { diff --git a/src/server/debugcmd.cc b/src/server/debugcmd.cc index a1436bdad..57aa3a019 100644 --- a/src/server/debugcmd.cc +++ b/src/server/debugcmd.cc @@ -161,7 +161,11 @@ void DoPopulateBatch(string_view type, string_view prefix, size_t val_size, bool crb.SetReplyMode(ReplyMode::NONE); stub_tx->InitByArgs(local_cntx.conn_state.db_index, args_span); - sf->service().InvokeCmd(cid, args_span, &local_cntx); + try { + sf->service().InvokeCmd(cid, args_span, &local_cntx); + } catch (const bad_alloc& e) { + LOG(WARNING) << "Unable to complete DEBUG POPULATE due to out of memory"; + } } local_cntx.Inject(nullptr); diff --git a/src/server/string_family.cc b/src/server/string_family.cc index e5a757cdc..35dabd5d1 100644 --- a/src/server/string_family.cc +++ b/src/server/string_family.cc @@ -541,7 +541,7 @@ bool StringValue::IsEmpty() const { OpStatus SetCmd::Set(const SetParams& params, string_view key, string_view value) { auto& db_slice = op_args_.shard->db_slice(); - DCHECK(db_slice.IsDbValid(op_args_.db_cntx.db_index)); + DCHECK(db_slice.IsDbValid(op_args_.db_cntx.db_index)) << op_args_.db_cntx.db_index; VLOG(2) << "Set " << key << "(" << db_slice.shard_id() << ") "; if (params.IsConditionalSet()) { diff --git a/src/server/transaction.cc b/src/server/transaction.cc index 65795a52e..954c167dd 100644 --- a/src/server/transaction.cc +++ b/src/server/transaction.cc @@ -1284,7 +1284,12 @@ OpStatus Transaction::RunSquashedMultiCb(RunnableType cb) { DCHECK_EQ(unique_shard_cnt_, 1u); auto* shard = EngineShard::tlocal(); - auto result = cb(this, shard); + RunnableResult result; + try { + result = cb(this, shard); + } catch (const bad_alloc& e) { + result = RunnableResult(OpStatus::OUT_OF_MEMORY); + } shard->db_slice().OnCbFinish(); LogAutoJournalOnShard(shard, result);