Skip to content

Commit 02a3bfb

Browse files
igchorvinser52
authored andcommitted
Do not compensate for rounding error when calculating tier sizes (pmem#43)
Compensation results in ratios being different than originially specified.
1 parent d13568e commit 02a3bfb

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
@@ -911,12 +911,6 @@ CacheAllocatorConfig<T>::getMemoryTierConfigs() const {
911911
sum_sizes += tier_config.getSize();
912912
}
913913

914-
if (size != sum_sizes) {
915-
// Adjust capacity of the last tier to account for rounding error
916-
config.back().setSize(
917-
config.back().getSize() + (getCacheSize() - sum_sizes));
918-
}
919-
920914
return config;
921915
}
922916

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)