Skip to content

Commit

Permalink
Fix issue with token creation
Browse files Browse the repository at this point in the history
  • Loading branch information
igchor committed May 31, 2023
1 parent 0253683 commit 5d5c3f0
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions cachelib/allocator/CacheAllocator-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1243,14 +1243,14 @@ bool CacheAllocator<CacheTrait>::moveChainedItem(ChainedItem& oldItem,
template <typename CacheTrait>
void CacheAllocator<CacheTrait>::unlinkItemForEviction(Item& it) {
XDCHECK(it.isMarkedForEviction());
XDCHECK(it.getRefCount() == 0);
XDCHECK_EQ(0, it.getRefCount());
accessContainer_->remove(it);
removeFromMMContainer(it);

// Since we managed to mark the item for eviction we must be the only
// owner of the item.
const auto ref = it.unmarkForEviction();
XDCHECK(ref == 0u);
XDCHECK_EQ(0, ref);
}

template <typename CacheTrait>
Expand Down Expand Up @@ -1289,43 +1289,50 @@ CacheAllocator<CacheTrait>::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());
// markForEviction to make sure no other thead is evicting the item
// nor holding a handle to that item
toRecycle = toRecycle_;
candidate = candidate_;

// 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)
mmContainer.remove(itr);
return;
} else {
++itr;
continue;
}

auto markedForEviction = candidate_->markForEviction();
if (!markedForEviction) {
if (candidate_->hasChainedItem()) {
stats_.evictFailParentAC.inc();
} else {
stats_.evictFailAC.inc();
}
++itr;
continue;
}

++itr;
XDCHECK(toRecycle == nullptr);
XDCHECK(candidate == nullptr);
XDCHECK(candidate_->isMarkedForEviction());
// markForEviction to make sure no other thead is evicting the item
// 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
// 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) {
mmContainer.remove(itr);
}
return;
}
});

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

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

0 comments on commit 5d5c3f0

Please sign in to comment.