Skip to content

Commit f5b3d08

Browse files
committed
correct handling for expired items in eviction
- we first check if an item is expired under mmContainer lock and if so mark it for eviction so it is recycled back up to allocateInternalTier.
1 parent 964c759 commit f5b3d08

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

cachelib/allocator/CacheAllocator-inl.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,11 +1600,12 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
16001600

16011601
Item* toRecycle = nullptr;
16021602
Item* candidate = nullptr;
1603+
bool isExpired = false;
16031604
typename NvmCacheT::PutToken token;
16041605

16051606
mmContainer.withEvictionIterator([this, tid, pid, cid, &candidate, &toRecycle,
16061607
&searchTries, &mmContainer, &lastTier,
1607-
&token](auto&& itr) {
1608+
&isExpired, &token](auto&& itr) {
16081609
if (!itr) {
16091610
++searchTries;
16101611
(*stats_.evictionAttempts)[tid][pid][cid].inc();
@@ -1633,14 +1634,16 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
16331634

16341635
if (evictToNvmCache && !token_.isValid()) {
16351636
stats_.evictFailConcurrentFill.inc();
1636-
} else if ( (lastTier && candidate_->markForEviction()) ||
1637+
} else if ( ((lastTier || candidate_->isExpired()) &&
1638+
candidate_->markForEviction()) ||
16371639
(!lastTier && candidate_->markMoving(true)) ) {
16381640
XDCHECK(candidate_->isMoving() || candidate_->isMarkedForEviction());
16391641
// markForEviction to make sure no other thead is evicting the item
16401642
// nor holding a handle to that item if this is last tier
16411643
// since we won't be moving the item to the next tier
16421644
toRecycle = toRecycle_;
16431645
candidate = candidate_;
1646+
isExpired = candidate_->isExpired();
16441647
token = std::move(token_);
16451648

16461649
// Check if parent changed for chained items - if yes, we cannot
@@ -1674,7 +1677,7 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
16741677
XDCHECK(toRecycle);
16751678
XDCHECK(candidate);
16761679

1677-
auto evictedToNext = lastTier ? nullptr
1680+
auto evictedToNext = (lastTier || isExpired) ? nullptr
16781681
: tryEvictToNextMemoryTier(*candidate, false);
16791682
if (!evictedToNext) {
16801683
//if insertOrReplace was called during move
@@ -1700,7 +1703,7 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
17001703
// as exclusive since we will not be moving the item to the next tier
17011704
// but rather just evicting all together, no need to
17021705
// markForEvictionWhenMoving
1703-
auto ret = lastTier ? true : candidate->markForEvictionWhenMoving();
1706+
auto ret = (lastTier || isExpired) ? true : candidate->markForEvictionWhenMoving();
17041707
XDCHECK(ret);
17051708

17061709
unlinkItemForEviction(*candidate);
@@ -1805,13 +1808,9 @@ typename CacheAllocator<CacheTrait>::WriteHandle
18051808
CacheAllocator<CacheTrait>::tryEvictToNextMemoryTier(
18061809
TierId tid, PoolId pid, Item& item, bool fromBgThread) {
18071810
XDCHECK(item.isMoving());
1811+
XDCHECK(!item.isExpired());
18081812
XDCHECK(item.getRefCount() == 0);
18091813
if(item.hasChainedItem()) return WriteHandle{}; // TODO: We do not support ChainedItem yet
1810-
if(item.isExpired()) {
1811-
accessContainer_->remove(item);
1812-
item.unmarkMoving();
1813-
return acquire(&item);
1814-
}
18151814

18161815
TierId nextTier = tid; // TODO - calculate this based on some admission policy
18171816
while (++nextTier < getNumTiers()) { // try to evict down to the next memory tiers

0 commit comments

Comments
 (0)