-
Notifications
You must be signed in to change notification settings - Fork 894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Run defrag on dbs > 0 as well #1737
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,6 @@ using absl::GetFlag; | |
|
||
namespace { | ||
|
||
constexpr DbIndex kDefaultDbIndex = 0; | ||
constexpr uint64_t kCursorDoneState = 0u; | ||
|
||
vector<EngineShardSet::CachedStats> cached_stats; // initialized in EngineShardSet::Init | ||
|
@@ -94,6 +93,11 @@ void EngineShard::DefragTaskState::UpdateScanState(uint64_t cursor_val) { | |
underutilized_found = false; | ||
} | ||
|
||
void EngineShard::DefragTaskState::ResetScanState() { | ||
dbid = cursor = 0u; | ||
underutilized_found = false; | ||
} | ||
|
||
// This function checks 3 things: | ||
// 1. Don't try memory fragmentation if we don't use "enough" memory (control by | ||
// mem_defrag_threshold flag) | ||
|
@@ -137,8 +141,8 @@ bool EngineShard::DoDefrag() { | |
const float threshold = GetFlag(FLAGS_mem_defrag_page_utilization_threshold); | ||
|
||
auto& slice = db_slice(); | ||
DCHECK(slice.IsDbValid(kDefaultDbIndex)); | ||
auto [prime_table, expire_table] = slice.GetTables(kDefaultDbIndex); | ||
DCHECK(slice.IsDbValid(defrag_state_.dbid)); | ||
auto [prime_table, expire_table] = slice.GetTables(defrag_state_.dbid); | ||
PrimeTable::Cursor cur = defrag_state_.cursor; | ||
uint64_t reallocations = 0; | ||
unsigned traverses_count = 0; | ||
|
@@ -158,6 +162,15 @@ bool EngineShard::DoDefrag() { | |
} while (traverses_count < kMaxTraverses && cur); | ||
|
||
defrag_state_.UpdateScanState(cur.value()); | ||
|
||
// Once we're done with a db, jump to the next | ||
if (defrag_state_.cursor == kCursorDoneState) { | ||
defrag_state_.dbid++; | ||
// Skip null dbs that still take up slots in the array | ||
while (defrag_state_.dbid < slice.db_array_size() && !slice.IsDbValid(defrag_state_.dbid)) | ||
defrag_state_.dbid++; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, if the db has less elements than kMaxTraverses, then it will proceed with the next db only on the next phase. I don't see it as a big flaw given that |
||
|
||
if (reallocations > 0) { | ||
VLOG(1) << "shard " << slice.shard_id() << ": successfully defrag " << reallocations | ||
<< " times, did it in " << traverses_count << " cursor is at the " | ||
|
@@ -168,10 +181,15 @@ bool EngineShard::DoDefrag() { | |
<< (defrag_state_.cursor == kCursorDoneState ? "end" : "in progress") | ||
<< " but no location for defrag were found"; | ||
} | ||
|
||
stats_.defrag_realloc_total += reallocations; | ||
stats_.defrag_task_invocation_total++; | ||
stats_.defrag_attempt_total += attempts; | ||
return defrag_state_.cursor > kCursorDoneState; | ||
|
||
bool items_left = slice.IsDbValid(defrag_state_.dbid); | ||
if (!items_left) | ||
defrag_state_.ResetScanState(); | ||
return items_left; | ||
} | ||
|
||
// the memory defragmentation task is as follow: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we ever reduce number of our databases? i.e. flushall?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't, see
DbSlice::FlushDb
But I can change it a little nonetheless to make it safer