Skip to content

Commit 68e6639

Browse files
igchorbyrnedj
authored andcommitted
Create token before marking item as exclusive
1 parent 7aed493 commit 68e6639

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

cachelib/allocator/CacheAllocator-inl.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,13 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
15901590
? &toRecycle_->asChainedItem().getParentItem(compressor_)
15911591
: toRecycle_;
15921592

1593-
if (shouldWriteToNvmCache(*candidate_) && !token.isValid()) {
1593+
if (lastTier) {
1594+
// if it's last tier, the item will be evicted
1595+
// need to create put token before marking it exclusive
1596+
token = createPutToken(*candidate_);
1597+
}
1598+
1599+
if (lastTier && shouldWriteToNvmCache(*candidate_) && !token.isValid()) {
15941600
stats_.evictFailConcurrentFill.inc();
15951601
} else if ( (lastTier && candidate_->markExclusive()) ||
15961602
(!lastTier && candidate_->markMoving(true)) ) {
@@ -1634,8 +1640,9 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
16341640
auto evictedToNext = lastTier ? nullptr
16351641
: tryEvictToNextMemoryTier(*candidate, false /* from BgThread */);
16361642
if (!evictedToNext) {
1637-
token = createPutToken(*candidate);
1638-
1643+
if (!token.isValid()) {
1644+
token = createPutToken(*candidate);
1645+
}
16391646
// tryEvictToNextMemoryTier should only fail if allocation of the new item fails
16401647
// in that case, it should be still possible to mark item as exclusive.
16411648
//

0 commit comments

Comments
 (0)