Introduce a TablePinningPolicy to control how and when memory is pinned - #459
Conversation
|
|
||
| options.ignore_unsupported_options = false; | ||
| const auto& id = GetParam(); | ||
| EXPECT_OK( |
There was a problem hiding this comment.
Why EXPECT_OK and not ASSERT_OK?
| ASSERT_EQ(pinning_policy_->GetUsage(), 0); | ||
| } | ||
|
|
||
| static const std::vector<std::string>& GetPinningPolicies() { |
There was a problem hiding this comment.
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.
Did you choos the {} and not = default on purpose?
| } | ||
| ASSERT_EQ(pinning_policy_->GetUsage(), used); | ||
| } | ||
| printf("MJR: Pinned=%d\n", (int)used); |
There was a problem hiding this comment.
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.
| 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.
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. |
|
|
||
| ScopedPinningPolicy::ScopedPinningPolicy() { | ||
| static const uint8_t kNumTypes = 7; | ||
| static const int kNumLevels = 7; |
There was a problem hiding this comment.
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.
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.
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.
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.
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.
Only for testing the concept or is that how it's going to be in production code?
| 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.
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...
|
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