From 3026791bbf57b1519d7fd91de6ad87ba0dc27171 Mon Sep 17 00:00:00 2001 From: Yuval Ariel Date: Mon, 15 Apr 2024 12:48:47 +0300 Subject: [PATCH] use ApproximateMemoryUsage instead of ApproximateMemoryUsageFast and memory_usage() instead of mutable_memtable_memory_usage() --- db/db_impl/db_impl_write.cc | 2 +- include/rocksdb/write_buffer_manager.h | 2 +- memtable/write_buffer_manager.cc | 13 ++++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/db/db_impl/db_impl_write.cc b/db/db_impl/db_impl_write.cc index ae0d68fbd..250d38251 100644 --- a/db/db_impl/db_impl_write.cc +++ b/db/db_impl/db_impl_write.cc @@ -1763,7 +1763,7 @@ Status DBImpl::HandleWriteBufferManagerFlush(WriteContext* write_context) { // and no immutable memtables for which flush has yet to finish. If // we triggered flush on CFs already trying to flush, we would risk // creating too many immutable memtables leading to write stalls. - auto mem_used = cfd->mem()->ApproximateMemoryUsageFast(); + auto mem_used = cfd->mem()->ApproximateMemoryUsage(); cfds.push_back(cfd); total_mem_to_free -= mem_used; if (total_mem_to_free <= 0) { diff --git a/include/rocksdb/write_buffer_manager.h b/include/rocksdb/write_buffer_manager.h index 52eaf0b82..d5a05bd5c 100644 --- a/include/rocksdb/write_buffer_manager.h +++ b/include/rocksdb/write_buffer_manager.h @@ -155,7 +155,7 @@ class WriteBufferManager final { } int64_t memory_above_flush_trigger() { - return mutable_memtable_memory_usage() - buffer_size() * kMutableLimit; + return memory_usage() - buffer_size() * kMutableLimit; } // Returns the total inactive memory used by memtables. diff --git a/memtable/write_buffer_manager.cc b/memtable/write_buffer_manager.cc index 87fb3cb65..b73cbc861 100644 --- a/memtable/write_buffer_manager.cc +++ b/memtable/write_buffer_manager.cc @@ -112,6 +112,12 @@ void WriteBufferManager::ReserveMem(size_t mem) { memory_used_.fetch_add(mem, std::memory_order_relaxed); new_memory_used = old_memory_used + mem; } + for (auto loggers : loggers_to_client_ids_map_) { + ROCKS_LOG_WARN(loggers.first, + "WBM (%p) ReserveMem called with: %" PRIu64 + " , memory_used: %" PRIu64, + this, mem, new_memory_used); + } if (is_enabled) { UpdateUsageState(new_memory_used, static_cast(mem), buffer_size()); // Checking outside the locks is not reliable, but avoids locking @@ -177,7 +183,12 @@ void WriteBufferManager::FreeMem(size_t mem) { assert(old_memory_used >= mem); new_memory_used = old_memory_used - mem; } - + for (auto loggers : loggers_to_client_ids_map_) { + ROCKS_LOG_WARN(loggers.first, + "WBM (%p) FreeMem called with: %" PRIu64 + ", memory_used: %" PRIu64, + this, mem, new_memory_used); + } if (is_enabled) { [[maybe_unused]] const auto curr_memory_inactive = memory_inactive_.fetch_sub(mem, std::memory_order_relaxed);