Skip to content

Commit 7d105a7

Browse files
igchorbyrnedj
authored andcommitted
Create token before marking item as exclusive
1 parent e4ce2e7 commit 7d105a7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

cachelib/allocator/CacheAllocator-inl.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,8 +1540,13 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
15401540
? &toRecycle_->asChainedItem().getParentItem(compressor_)
15411541
: toRecycle_;
15421542

1543-
token = createPutToken(*candidate_);
1544-
if (shouldWriteToNvmCache(*candidate_) && !token.isValid()) {
1543+
if (lastTier) {
1544+
// if it's last tier, the item will be evicted
1545+
// need to create put token before marking it exclusive
1546+
token = createPutToken(*candidate_);
1547+
}
1548+
1549+
if (lastTier && shouldWriteToNvmCache(*candidate_) && !token.isValid()) {
15451550
stats_.evictFailConcurrentFill.inc();
15461551
} else if ( (lastTier && candidate_->markForEviction()) ||
15471552
(!lastTier && candidate_->markMoving(true)) ) {
@@ -1584,8 +1589,9 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
15841589
auto evictedToNext = lastTier ? nullptr
15851590
: tryEvictToNextMemoryTier(*candidate);
15861591
if (!evictedToNext) {
1587-
token = createPutToken(*candidate);
1588-
1592+
if (!token.isValid()) {
1593+
token = createPutToken(*candidate);
1594+
}
15891595
// tryEvictToNextMemoryTier should only fail if allocation of the new item fails
15901596
// in that case, it should be still possible to mark item as exclusive.
15911597
//

0 commit comments

Comments
 (0)