Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions cachelib/allocator/CacheAllocator-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1603,13 +1603,15 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
? &toRecycle_->asChainedItem().getParentItem(compressor_)
: toRecycle_;

if (lastTier) {
// if it's last tier, the item will be evicted
// need to create put token before marking it exclusive
token = createPutToken(*candidate_);
}
// if it's last tier, the item will be evicted
// need to create put token before marking it exclusive
const bool evictToNvmCache = lastTier && shouldWriteToNvmCache(*candidate_);

auto token_ = evictToNvmCache
? nvmCache_->createPutToken(candidate_->getKey())
: typename NvmCacheT::PutToken{};

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

// Check if parent changed for chained items - if yes, we cannot
// remove the child from the mmContainer as we will not be evicting
// it. We could abort right here, but we need to cleanup in case
// unmarkForEviction() returns 0 - so just go through normal path.
if (!toRecycle_->isChainedItem() ||
&toRecycle->asChainedItem().getParentItem(compressor_) ==
candidate)
candidate) {
mmContainer.remove(itr);
}
return;
}

if (candidate_->hasChainedItem()) {
stats_.evictFailParentAC.inc();
} else {
stats_.evictFailAC.inc();
if (candidate_->hasChainedItem()) {
stats_.evictFailParentAC.inc();
} else {
stats_.evictFailAC.inc();
}
}

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

if (!toRecycle)
if (!toRecycle) {
continue;
}

XDCHECK(toRecycle);
XDCHECK(candidate);
Expand Down