-
Notifications
You must be signed in to change notification settings - Fork 71
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
Introduce a TablePinningPolicy to control how and when memory is pinned #459
Conversation
db/db_block_cache_test.cc
Outdated
|
||
options.ignore_unsupported_options = false; | ||
const auto& id = GetParam(); | ||
EXPECT_OK( |
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.
Why EXPECT_OK and not ASSERT_OK?
db/db_block_cache_test.cc
Outdated
ASSERT_EQ(pinning_policy_->GetUsage(), 0); | ||
} | ||
|
||
static const std::vector<std::string>& GetPinningPolicies() { |
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.
Really minor, but unnamed namespaces should be the way to go instead of static functions.
struct ConfigOptions; | ||
// Struct that contains information about the table being evaluated for pinning | ||
struct TablePinningOptions { | ||
TablePinningOptions() {} |
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.
Did you choos the {} and not = default on purpose?
db/db_block_cache_test.cc
Outdated
} | ||
ASSERT_EQ(pinning_policy_->GetUsage(), used); | ||
} | ||
printf("MJR: Pinned=%d\n", (int)used); |
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.
Is printing really necessary? I would avoid printing to the console during unit tests as it just bothers users running unit tests who just want to see the tests pass.
The unit test should use assertions to verify it is passing.
db/db_block_cache_test.cc
Outdated
const auto& id = GetParam(); | ||
EXPECT_OK( | ||
TablePinningPolicy::CreateFromString(options, id, &pinning_policy_)); | ||
printf("MJR: Loaded pinning policy (%s)\n", id.c_str()); |
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.
Please remove the printing (which, btw, may be done using std::cout in unit tests). Please also see my comment below regarding the printf there.
@mrambacher - First batch of comments. Haven't finished the review. |
@mrambacher - In case it wasn't clear. I am waiting for you to address the comments I have given before continuing my review. |
@@ -34,13 +34,32 @@ static std::unordered_map<std::string, OptionTypeInfo> | |||
OptionVerificationType::kNormal, OptionTypeFlags::kNone}}, | |||
}; | |||
|
|||
ScopedPinningPolicy::ScopedPinningPolicy() { | |||
static const uint8_t kNumTypes = 7; | |||
static const int kNumLevels = 7; |
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.
Is that just for testing the concept?
|
||
std::atomic<size_t> usage_; | ||
std::vector<std::atomic_size_t> usage_by_level_; | ||
std::vector<std::atomic_size_t> usage_by_type_; |
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.
Why not initialize the vectors to 0 here and avoid the necessity in the ctor?
} | ||
for (uint8_t t = 0; t < kNumTypes; t++) { | ||
usage_by_type_[t].store(0); | ||
} |
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.
Couldn't you use std::fill?
But a better options IMO is to init all of the fields in the header as I suggest
And you could delegate to the non default ctor by calling here ScopedPinningPolicy(ScopedPinningOptions())
and avoid the code duplication in the ctor-s.
} | ||
for (uint8_t t = 0; t < kNumTypes; t++) { | ||
usage_by_type_[t].store(0); | ||
} |
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.
Please see my comments above for the default ctor.
usage_by_type_[type] += size; | ||
} else { | ||
usage_by_level_[level] += size; | ||
usage_by_type_[type] += size; |
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.
Shouldn't you decrease the usage by level / type when pinned == false?
} else if (pinned) { | ||
usage_by_type_[type] = size; | ||
if (level >= kNumLevels) level = kNumLevels - 1; | ||
if (type >= kNumTypes) type = kNumTypes - 1; |
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.
Only for testing the concept or is that how it's going to be in production code?
@@ -49,78 +68,52 @@ std::string ScopedPinningPolicy::GetId() const { | |||
|
|||
bool ScopedPinningPolicy::MayPin(const TablePinningOptions& tpo, uint8_t type, | |||
size_t size) const { | |||
auto limit = GetUsage(); | |||
return CheckPin(tpo, type, size, limit); | |||
return CheckPin(tpo, type, size, usage_); |
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.
What is MayPin()? used for?
And, it should be clear to the users that they MayPin() may return true but actual pinning may still fail.
build db_bench failed |
comparison of unsigned expression >= 0 is always true [-Werror=type-limits]
@mrambacher plz also add to the HISTORY.md file |
https://github.com/speedb-io/speedb/actions/runs/5444728254/jobs/9904106132#step:6:571 ==15027==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x606000010398 at pc 0x7f21e95a2c2e bp 0x7f21dcdb9f20 sp 0x7f21dcdb9f10 |
Not sure how it disappeared as part of the rebase...
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.
remove foo file.
failed unit tests: |
This PR adds a TablePinningPolicy to the BlockBasedTableOptions. This new class is Customizable and can be created from strings. The class has methods to limit the amount of pin data in the system.
The basic approach is that the unit probes (MayPin) if it believes data is available at the time. If so, the code does it normal checks and then attempts to pin the new data (PinData). Once the code is done with the data, UnPinData puts the memory back into the available pool