diff --git a/cachelib/allocator/CacheAllocator-inl.h b/cachelib/allocator/CacheAllocator-inl.h index 348fcb82ec..ea0f56e49f 100644 --- a/cachelib/allocator/CacheAllocator-inl.h +++ b/cachelib/allocator/CacheAllocator-inl.h @@ -1289,10 +1289,11 @@ CacheAllocator::findEviction(PoolId pid, ClassId cid) { : toRecycle_; const bool evictToNvmCache = shouldWriteToNvmCache(*candidate_); - if (evictToNvmCache) - token = nvmCache_->createPutToken(candidate_->getKey()); + auto token_ = evictToNvmCache + ? nvmCache_->createPutToken(candidate_->getKey()) + : typename NvmCacheT::PutToken{}; - if (evictToNvmCache && !token.isValid()) { + if (evictToNvmCache && !token_.isValid()) { stats_.evictFailConcurrentFill.inc(); } else if (candidate_->markForEviction()) { XDCHECK(candidate_->isMarkedForEviction()); @@ -1300,6 +1301,7 @@ CacheAllocator::findEviction(PoolId pid, ClassId cid) { // nor holding a handle to that item 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 @@ -1307,8 +1309,9 @@ CacheAllocator::findEviction(PoolId pid, ClassId cid) { // unmarkForEviction() returns 0 - so just go through normal path. if (!toRecycle_->isChainedItem() || &toRecycle->asChainedItem().getParentItem(compressor_) == - candidate) + candidate) { mmContainer.remove(itr); + } return; } else { if (candidate_->hasChainedItem()) { @@ -1324,8 +1327,9 @@ CacheAllocator::findEviction(PoolId pid, ClassId cid) { } }); - if (!toRecycle) + if (!toRecycle) { continue; + } XDCHECK(toRecycle); XDCHECK(candidate);