Skip to content

Commit 403bca0

Browse files
authored
Do not compensate for rounding error when calculating tier sizes (#43)
Compensation results in ratios being different than originially specified.
1 parent 8a7b4d7 commit 403bca0

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
@@ -883,12 +883,6 @@ CacheAllocatorConfig<T>::getMemoryTierConfigs() const {
883883
sum_sizes += tier_config.getSize();
884884
}
885885

886-
if (size != sum_sizes) {
887-
// Adjust capacity of the last tier to account for rounding error
888-
config.back().setSize(
889-
config.back().getSize() + (getCacheSize() - sum_sizes));
890-
}
891-
892886
return config;
893887
}
894888

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)