Skip to content

Commit

Permalink
prettify
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuval Ariel committed Apr 14, 2024
1 parent e7714c4 commit 9f5004f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions db/db_impl/db_impl_write.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1747,9 +1747,13 @@ Status DBImpl::HandleWriteBufferManagerFlush(WriteContext* write_context) {
if (immutable_db_options_.atomic_flush) {
SelectColumnFamiliesForAtomicFlush(&cfds);
} else {
// As part of https://github.com/speedb-io/speedb/pull/859, theres a need to
// schedule more flushes since the cfd picked for flush was the oldest one
// and not necessarily enough to resolve the stall issue.
// For this reason, schedule enough flushes so that the memory usage is at
// least below the flush trigger (kMutableLimit * buffer_size)
int64_t total_mem_to_free =
write_buffer_manager()->mutable_memtable_memory_usage() -
write_buffer_manager()->buffer_size() * 7 / 8;
write_buffer_manager()->memory_above_flush_trigger();
for (auto cfd : *versions_->GetColumnFamilySet()) {
if (cfd->IsDropped()) {
continue;
Expand Down
8 changes: 7 additions & 1 deletion include/rocksdb/write_buffer_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class WriteBufferManager final {
static constexpr uint64_t kNoDelayedWriteFactor = 0U;
static constexpr uint64_t kMaxDelayedWriteFactor = 100U;
static constexpr uint64_t kStopDelayedWriteFactor = kMaxDelayedWriteFactor;
static constexpr double kMutableLimit = 0.875;

enum class UsageState { kNone, kDelay, kStop };

public:
Expand Down Expand Up @@ -152,6 +154,10 @@ class WriteBufferManager final {
return ((inactive >= total) ? 0 : (total - inactive));
}

int64_t memory_above_flush_trigger() {
return mutable_memtable_memory_usage() - buffer_size() * kMutableLimit;
}

// Returns the total inactive memory used by memtables.
size_t immmutable_memtable_memory_usage() const {
return memory_inactive_.load(std::memory_order_relaxed);
Expand Down Expand Up @@ -180,7 +186,7 @@ class WriteBufferManager final {
[[maybe_unused]] auto was_enabled = enabled();

buffer_size_.store(new_size, std::memory_order_relaxed);
mutable_limit_.store(new_size * 7 / 8, std::memory_order_relaxed);
mutable_limit_.store(new_size * kMutableLimit, std::memory_order_relaxed);

assert(was_enabled == enabled());

Expand Down
2 changes: 1 addition & 1 deletion memtable/write_buffer_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ WriteBufferManager::WriteBufferManager(
const FlushInitiationOptions& flush_initiation_options,
uint16_t start_delay_percent)
: buffer_size_(_buffer_size),
mutable_limit_(buffer_size_ * 7 / 8),
mutable_limit_(buffer_size_ * kMutableLimit),
memory_used_(0),
memory_inactive_(0),
memory_being_freed_(0U),
Expand Down

0 comments on commit 9f5004f

Please # to comment.