@@ -1561,11 +1561,11 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
1561
1561
Item* toRecycle = nullptr ;
1562
1562
Item* toRecycleParent = nullptr ;
1563
1563
Item* candidate = nullptr ;
1564
- WriteHandle headHandle {};
1564
+ WriteHandle parentHandle {};
1565
1565
typename NvmCacheT::PutToken token;
1566
1566
1567
1567
mmContainer.withEvictionIterator ([this , tid, pid, cid, &candidate,
1568
- &toRecycle, &toRecycleParent, &headHandle ,
1568
+ &toRecycle, &toRecycleParent, &parentHandle ,
1569
1569
&searchTries, &mmContainer, &lastTier,
1570
1570
&token](auto && itr) {
1571
1571
if (!itr) {
@@ -1585,10 +1585,8 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
1585
1585
toRecycle_->isChainedItem ()
1586
1586
? &toRecycle_->asChainedItem ().getParentItem (compressor_)
1587
1587
: nullptr ;
1588
- WriteHandle headHandle_{};
1589
1588
WriteHandle parentHandle_{};
1590
1589
Item* candidate_;
1591
- bool isHead = false ;
1592
1590
if (!lastTier && toRecycle_->isChainedItem ()) {
1593
1591
const auto parentKey = toRecycleParent_->getKey ();
1594
1592
auto lock = chainedItemLocks_.tryLockExclusive (parentKey);
@@ -1599,22 +1597,9 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
1599
1597
}
1600
1598
XDCHECK_EQ (&toRecycle_->asChainedItem ().getParentItem (compressor_),
1601
1599
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 ;
1618
1603
}
1619
1604
candidate_ = toRecycle_;
1620
1605
} else if (lastTier && toRecycle_->isChainedItem ()) {
@@ -1633,13 +1618,6 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
1633
1618
} else if ( (lastTier && candidate_->markForEviction ()) ||
1634
1619
(!lastTier && candidate_->markMoving ()) ) {
1635
1620
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
- }
1643
1621
toRecycleParent = toRecycleParent_;
1644
1622
// markForEviction to make sure no other thead is evicting the item
1645
1623
// 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) {
1656
1634
mmContainer.remove (itr);
1657
1635
}
1658
1636
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
+ }
1663
1644
}
1664
1645
1665
1646
if (candidate_->hasChainedItem ()) {
@@ -1686,30 +1667,13 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
1686
1667
// failed to move a chained item - so evict the entire chain
1687
1668
if (candidate->isChainedItem ()) {
1688
1669
// 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 );
1703
1672
candidate->unmarkMoving (); // old candidate was the child item
1673
+ XDCHECK (toRecycleParent->isMoving ());
1704
1674
toRecycle = candidate; // we really want to recycle the child
1705
1675
candidate = toRecycleParent; // but now we evict the chain and in
1706
1676
// doing so recycle the child
1707
- if (headHandle) {
1708
- XDCHECK_EQ (headHandle->getRefCount (),2 );
1709
- headHandle->unmarkMoving ();
1710
- headHandle.reset ();
1711
- XDCHECK (!headHandle);
1712
- }
1713
1677
}
1714
1678
// if insertOrReplace was called during move
1715
1679
// then candidate will not be accessible (failed replace during tryEvict)
@@ -1756,9 +1720,13 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
1756
1720
1757
1721
(*stats_.numWritebacks )[tid][pid][cid].inc ();
1758
1722
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
+ }
1762
1730
}
1763
1731
}
1764
1732
0 commit comments