@@ -1561,11 +1561,11 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
15611561 Item* toRecycle = nullptr ;
15621562 Item* toRecycleParent = nullptr ;
15631563 Item* candidate = nullptr ;
1564- WriteHandle headHandle {};
1564+ WriteHandle parentHandle {};
15651565 typename NvmCacheT::PutToken token;
15661566
15671567 mmContainer.withEvictionIterator ([this , tid, pid, cid, &candidate,
1568- &toRecycle, &toRecycleParent, &headHandle ,
1568+ &toRecycle, &toRecycleParent, &parentHandle ,
15691569 &searchTries, &mmContainer, &lastTier,
15701570 &token](auto && itr) {
15711571 if (!itr) {
@@ -1585,10 +1585,8 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
15851585 toRecycle_->isChainedItem ()
15861586 ? &toRecycle_->asChainedItem ().getParentItem (compressor_)
15871587 : nullptr ;
1588- WriteHandle headHandle_{};
15891588 WriteHandle parentHandle_{};
15901589 Item* candidate_;
1591- bool isHead = false ;
15921590 if (!lastTier && toRecycle_->isChainedItem ()) {
15931591 const auto parentKey = toRecycleParent_->getKey ();
15941592 auto lock = chainedItemLocks_.tryLockExclusive (parentKey);
@@ -1599,22 +1597,9 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
15991597 }
16001598 XDCHECK_EQ (&toRecycle_->asChainedItem ().getParentItem (compressor_),
16011599 toRecycleParent_);
1602- headHandle_ = findChainedItem (*toRecycleParent_);
1603- if (headHandle_) {
1604- if (headHandle_.get () == toRecycle_) {
1605- // we don't need to mark head handle as moving
1606- headHandle_.reset ();
1607- isHead = true ;
1608- } else {
1609- bool marked = headHandle_->markMoving ();
1610- if (!marked) {
1611- ++itr;
1612- continue ;
1613- }
1614- }
1615- } else {
1616- ++itr;
1617- continue ;
1600+ if (!toRecycleParent_->markMoving ()) {
1601+ ++itr;
1602+ continue ;
16181603 }
16191604 candidate_ = toRecycle_;
16201605 } else if (lastTier && toRecycle_->isChainedItem ()) {
@@ -1633,13 +1618,6 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
16331618 } else if ( (lastTier && candidate_->markForEviction ()) ||
16341619 (!lastTier && candidate_->markMoving ()) ) {
16351620 XDCHECK (candidate_->isMoving () || candidate_->isMarkedForEviction ());
1636- if (isHead) {
1637- XDCHECK (!headHandle);
1638- }
1639- if (headHandle_) {
1640- XDCHECK (headHandle_->isMoving ());
1641- headHandle = std::move (headHandle_);
1642- }
16431621 toRecycleParent = toRecycleParent_;
16441622 // markForEviction to make sure no other thead is evicting the item
16451623 // nor holding a handle to that item if this is last tier
@@ -1656,10 +1634,13 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
16561634 mmContainer.remove (itr);
16571635 }
16581636 return ;
1659- } else if (headHandle_) {
1660- XDCHECK (headHandle_->isMoving ());
1661- headHandle_->unmarkMoving ();
1662- wakeUpWaiters (*headHandle_,std::move (headHandle_));
1637+ } else if (!lastTier && toRecycle_->isChainedItem ()) {
1638+ XDCHECK (toRecycleParent_->isMoving ());
1639+ toRecycleParent_->unmarkMoving ();
1640+ auto parentHandle_ = acquire (toRecycleParent_);
1641+ if (parentHandle_) {
1642+ wakeUpWaiters (*toRecycleParent_,std::move (parentHandle_));
1643+ }
16631644 }
16641645
16651646 if (candidate_->hasChainedItem ()) {
@@ -1686,30 +1667,13 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
16861667 // failed to move a chained item - so evict the entire chain
16871668 if (candidate->isChainedItem ()) {
16881669 // candidate should be parent now
1689- if (headHandle) {
1690- XDCHECK_EQ ( &headHandle->asChainedItem ().getParentItem (compressor_),
1691- toRecycleParent );
1692- XDCHECK_EQ ( &candidate->asChainedItem ().getParentItem (compressor_),
1693- toRecycleParent );
1694- }
1695- bool marked = toRecycleParent->markMoving ();
1696- while (!marked) {
1697- // we have a candidated marked moving and we failed to mark the parent
1698- // we can't evict this item since we failed to allocate in next tier
1699- // we might have to
1700- marked = toRecycleParent->markMoving ();
1701- }
1702- XDCHECK (marked);
1670+ XDCHECK_EQ ( &candidate->asChainedItem ().getParentItem (compressor_),
1671+ toRecycleParent );
17031672 candidate->unmarkMoving (); // old candidate was the child item
1673+ XDCHECK (toRecycleParent->isMoving ());
17041674 toRecycle = candidate; // we really want to recycle the child
17051675 candidate = toRecycleParent; // but now we evict the chain and in
17061676 // doing so recycle the child
1707- if (headHandle) {
1708- XDCHECK_EQ (headHandle->getRefCount (),2 );
1709- headHandle->unmarkMoving ();
1710- headHandle.reset ();
1711- XDCHECK (!headHandle);
1712- }
17131677 }
17141678 // if insertOrReplace was called during move
17151679 // then candidate will not be accessible (failed replace during tryEvict)
@@ -1756,9 +1720,13 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
17561720
17571721 (*stats_.numWritebacks )[tid][pid][cid].inc ();
17581722 wakeUpWaiters (*candidate, std::move (evictedToNext));
1759- if (headHandle) {
1760- headHandle->unmarkMoving ();
1761- wakeUpWaiters (*headHandle,std::move (headHandle));
1723+ if (toRecycleParent) {
1724+ XDCHECK (toRecycleParent->isMoving ());
1725+ toRecycleParent->unmarkMoving ();
1726+ auto parentHandle = acquire (toRecycleParent);
1727+ if (parentHandle) {
1728+ wakeUpWaiters (*toRecycleParent,std::move (parentHandle));
1729+ }
17621730 }
17631731 }
17641732
0 commit comments