Skip to content

Commit 414ab78

Browse files
igchorguptask
authored andcommitted
Do not compensate for rounding error when calculating tier sizes (#43)
Compensation results in ratios being different than originially specified.
1 parent 83a5de7 commit 414ab78

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

cachelib/allocator/CacheAllocatorConfig.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -947,12 +947,6 @@ CacheAllocatorConfig<T>::getMemoryTierConfigs() const {
947947
sum_sizes += tier_config.getSize();
948948
}
949949

950-
if (size != sum_sizes) {
951-
// Adjust capacity of the last tier to account for rounding error
952-
config.back().setSize(
953-
config.back().getSize() + (getCacheSize() - sum_sizes));
954-
}
955-
956950
return config;
957951
}
958952

cachelib/allocator/tests/MemoryTiersTest.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ class MemoryTiersTest: public AllocatorTest<Allocator> {
5252
size_t sum_ratios = std::accumulate(configs.begin(), configs.end(), 0,
5353
[](const size_t i, const MemoryTierCacheConfig& config) { return i + config.getRatio();});
5454

55-
EXPECT_EQ(sum_sizes, expectedTotalCacheSize);
56-
size_t partition_size = 0, remaining_capacity = actualConfig.getCacheSize();
55+
size_t partition_size = 0;
5756
if (sum_ratios) {
5857
partition_size = actualConfig.getCacheSize() / sum_ratios;
58+
/* Sum of sizes can be lower due to rounding down to partition_size. */
59+
EXPECT_GE(sum_sizes, expectedTotalCacheSize - partition_size);
5960
}
6061

6162
for(auto i = 0; i < configs.size(); ++i) {
@@ -65,10 +66,7 @@ class MemoryTiersTest: public AllocatorTest<Allocator> {
6566
if (configs[i].getRatio() && (i < configs.size() - 1)) {
6667
EXPECT_EQ(configs[i].getSize(), partition_size * configs[i].getRatio());
6768
}
68-
remaining_capacity -= configs[i].getSize();
6969
}
70-
71-
EXPECT_EQ(remaining_capacity, 0);
7270
}
7371

7472
LruAllocatorConfig createTestCacheConfig(

0 commit comments

Comments
 (0)