Skip to content

Commit 91a05e3

Browse files
authored
Fix token creation and stats (#79)
* Fix issue with token creation * Do not increment evictFail* stats if evictFailConcurrentFill were incremented
1 parent 43dda43 commit 91a05e3

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

cachelib/allocator/CacheAllocator-inl.h

+18-13
Original file line numberDiff line numberDiff line change
@@ -1603,13 +1603,15 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
16031603
? &toRecycle_->asChainedItem().getParentItem(compressor_)
16041604
: toRecycle_;
16051605

1606-
if (lastTier) {
1607-
// if it's last tier, the item will be evicted
1608-
// need to create put token before marking it exclusive
1609-
token = createPutToken(*candidate_);
1610-
}
1606+
// if it's last tier, the item will be evicted
1607+
// need to create put token before marking it exclusive
1608+
const bool evictToNvmCache = lastTier && shouldWriteToNvmCache(*candidate_);
1609+
1610+
auto token_ = evictToNvmCache
1611+
? nvmCache_->createPutToken(candidate_->getKey())
1612+
: typename NvmCacheT::PutToken{};
16111613

1612-
if (lastTier && shouldWriteToNvmCache(*candidate_) && !token.isValid()) {
1614+
if (evictToNvmCache && !token_.isValid()) {
16131615
stats_.evictFailConcurrentFill.inc();
16141616
} else if ( (lastTier && candidate_->markForEviction()) ||
16151617
(!lastTier && candidate_->markMoving(true)) ) {
@@ -1619,22 +1621,24 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
16191621
// since we won't be moving the item to the next tier
16201622
toRecycle = toRecycle_;
16211623
candidate = candidate_;
1624+
token = std::move(token_);
16221625

16231626
// Check if parent changed for chained items - if yes, we cannot
16241627
// remove the child from the mmContainer as we will not be evicting
16251628
// it. We could abort right here, but we need to cleanup in case
16261629
// unmarkForEviction() returns 0 - so just go through normal path.
16271630
if (!toRecycle_->isChainedItem() ||
16281631
&toRecycle->asChainedItem().getParentItem(compressor_) ==
1629-
candidate)
1632+
candidate) {
16301633
mmContainer.remove(itr);
1634+
}
16311635
return;
1632-
}
1633-
1634-
if (candidate_->hasChainedItem()) {
1635-
stats_.evictFailParentAC.inc();
16361636
} else {
1637-
stats_.evictFailAC.inc();
1637+
if (candidate_->hasChainedItem()) {
1638+
stats_.evictFailParentAC.inc();
1639+
} else {
1640+
stats_.evictFailAC.inc();
1641+
}
16381642
}
16391643

16401644
++itr;
@@ -1643,8 +1647,9 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
16431647
}
16441648
});
16451649

1646-
if (!toRecycle)
1650+
if (!toRecycle) {
16471651
continue;
1652+
}
16481653

16491654
XDCHECK(toRecycle);
16501655
XDCHECK(candidate);

0 commit comments

Comments
 (0)