Skip to content

Commit 874aa52

Browse files
committed
bg fixes - without approx free
1 parent 4f4c4c8 commit 874aa52

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

cachelib/allocator/CacheAllocator-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ template <typename CacheTrait>
385385
bool CacheAllocator<CacheTrait>::shouldWakeupBgEvictor(TierId tid, PoolId pid, ClassId cid) {
386386
// TODO: should we also work on lower tiers? should we have separate set of params?
387387
if (tid == 1) return false;
388-
return getACStats(tid, pid, cid).approxFreePercent <= config_.lowEvictionAcWatermark;
388+
return getACStats(tid, pid, cid).usageFraction()*100 <= config_.lowEvictionAcWatermark;
389389
}
390390

391391
template <typename CacheTrait>

cachelib/allocator/CacheAllocator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,9 +1980,9 @@ auto& mmContainer = getMMContainer(tid, pid, cid);
19801980
if (candidate->markMoving(true)) {
19811981
mmContainer.remove(itr);
19821982
candidates.push_back(candidate);
1983+
} else {
1984+
++itr;
19831985
}
1984-
1985-
++itr;
19861986
}
19871987
});
19881988

cachelib/allocator/FreeThresholdStrategy.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ std::vector<size_t> FreeThresholdStrategy::calculateBatchSizes(
3636
std::vector<size_t> batches{};
3737
for (auto [tid, pid, cid] : acVec) {
3838
auto stats = cache.getACStats(tid, pid, cid);
39-
if (stats.approxFreePercent >= highEvictionAcWatermark) {
39+
if (stats.usageFraction()*100 >= highEvictionAcWatermark) {
4040
batches.push_back(0);
4141
} else {
42-
auto toFreeMemPercent = highEvictionAcWatermark - stats.approxFreePercent;
42+
auto toFreeMemPercent = highEvictionAcWatermark - stats.usageFraction()*100;
4343
auto toFreeItems = static_cast<size_t>(
44-
toFreeMemPercent * stats.memorySize / stats.allocSize);
44+
toFreeMemPercent * (stats.totalSlabs() * Slab::kSize) / stats.allocSize);
4545
batches.push_back(toFreeItems);
4646
}
4747
}

cachelib/allocator/PromotionStrategy.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ class PromotionStrategy : public BackgroundMoverStrategy {
4040
for (auto [tid, pid, cid] : acVec) {
4141
XDCHECK(tid > 0);
4242
auto stats = cache.getACStats(tid - 1, pid, cid);
43-
if (stats.approxFreePercent < promotionAcWatermark)
43+
if (stats.usageFraction()*100 < promotionAcWatermark)
4444
batches.push_back(0);
4545
else {
4646
auto maxPossibleItemsToPromote = static_cast<size_t>(
47-
(promotionAcWatermark - stats.approxFreePercent) *
48-
stats.memorySize / stats.allocSize);
47+
(promotionAcWatermark - stats.usageFraction()*100) *
48+
(stats.totalSlabs() * Slab::kSize) / stats.allocSize);
4949
batches.push_back(maxPossibleItemsToPromote);
5050
}
5151
}

cachelib/allocator/tests/AllocatorMemoryTiersTest.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ class AllocatorMemoryTiersTest : public AllocatorTest<AllocatorT> {
124124
const auto& mpStats = allocator->getPoolByTid(poolId, 0).getStats();
125125
//cache is 10MB should move about 1MB to reach 10% free
126126
uint32_t approxEvict = (1024*1024)/mpStats.acStats.at(cid).allocSize;
127-
while (stats.evictionStats.numMovedItems < approxEvict*0.95 && slabStats.approxFreePercent >= 9.5) {
127+
while (stats.evictionStats.numMovedItems < approxEvict*0.95 && slabStats.usageFraction() >= 0.095) {
128128
std::this_thread::sleep_for(std::chrono::seconds(1));
129129
stats = allocator->getGlobalCacheStats();
130130
slabStats = allocator->getACStats(0,0,cid);
131131
}
132-
ASSERT_GE(slabStats.approxFreePercent,9.5);
132+
ASSERT_GE(slabStats.usageFraction(),0.095);
133133

134134
auto perclassEstats = allocator->getBackgroundMoverClassStats(MoverDir::Evict);
135135
auto perclassPstats = allocator->getBackgroundMoverClassStats(MoverDir::Promote);

0 commit comments

Comments
 (0)