Skip to content

Commit

Permalink
use ApproximateMemoryUsage instead of ApproximateMemoryUsageFast
Browse files Browse the repository at this point in the history
and memory_usage() instead of mutable_memtable_memory_usage()
  • Loading branch information
Yuval Ariel committed Apr 15, 2024
1 parent 9f5004f commit 3026791
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion db/db_impl/db_impl_write.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion include/rocksdb/write_buffer_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 12 additions & 1 deletion memtable/write_buffer_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int64_t>(mem), buffer_size());
// Checking outside the locks is not reliable, but avoids locking
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3026791

Please sign in to comment.