Skip to content

Do not compensate for rounding error when calculating tier sizes #43

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

Merged
merged 1 commit into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions cachelib/allocator/CacheAllocatorConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -883,12 +883,6 @@ CacheAllocatorConfig<T>::getMemoryTierConfigs() const {
sum_sizes += tier_config.getSize();
}

if (size != sum_sizes) {
// Adjust capacity of the last tier to account for rounding error
config.back().setSize(
config.back().getSize() + (getCacheSize() - sum_sizes));
}

return config;
}

Expand Down
8 changes: 3 additions & 5 deletions cachelib/allocator/tests/MemoryTiersTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ class MemoryTiersTest: public AllocatorTest<Allocator> {
size_t sum_ratios = std::accumulate(configs.begin(), configs.end(), 0,
[](const size_t i, const MemoryTierCacheConfig& config) { return i + config.getRatio();});

EXPECT_EQ(sum_sizes, expectedTotalCacheSize);
size_t partition_size = 0, remaining_capacity = actualConfig.getCacheSize();
size_t partition_size = 0;
if (sum_ratios) {
partition_size = actualConfig.getCacheSize() / sum_ratios;
/* Sum of sizes can be lower due to rounding down to partition_size. */
EXPECT_GE(sum_sizes, expectedTotalCacheSize - partition_size);
}

for(auto i = 0; i < configs.size(); ++i) {
Expand All @@ -65,10 +66,7 @@ class MemoryTiersTest: public AllocatorTest<Allocator> {
if (configs[i].getRatio() && (i < configs.size() - 1)) {
EXPECT_EQ(configs[i].getSize(), partition_size * configs[i].getRatio());
}
remaining_capacity -= configs[i].getSize();
}

EXPECT_EQ(remaining_capacity, 0);
}

LruAllocatorConfig createTestCacheConfig(
Expand Down