@@ -1562,26 +1562,39 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
15621562 // Keep searching for a candidate until we were able to evict it
15631563 // or until the search limit has been exhausted
15641564 unsigned int searchTries = 0 ;
1565- auto itr = mmContainer.getEvictionIterator ();
15661565 while ((config_.evictionSearchTries == 0 ||
1567- config_.evictionSearchTries > searchTries) &&
1568- itr) {
1566+ config_.evictionSearchTries > searchTries)) {
15691567 ++searchTries;
15701568
1571- Item* toRecycle = itr.get ();
1569+ Item* toRecycle = nullptr ;
1570+ Item* candidate = nullptr ;
15721571
1573- Item* candidate =
1574- toRecycle-> isChainedItem ()
1575- ? &toRecycle-> asChainedItem (). getParentItem (compressor_)
1576- : toRecycle ;
1572+ mmContainer. withEvictionIterator ([ this , & candidate, &toRecycle, &searchTries]( auto &&itr){
1573+ while ((config_. evictionSearchTries == 0 ||
1574+ config_. evictionSearchTries > searchTries) && itr) {
1575+ ++searchTries ;
15771576
1578- // make sure no other thead is evicting the item
1579- if (candidate->getRefCount () != 0 || !candidate->markMoving ()) {
1580- ++itr;
1577+ auto *toRecycle_ = itr.get ();
1578+ auto *candidate_ = toRecycle_->isChainedItem ()
1579+ ? &toRecycle_->asChainedItem ().getParentItem (compressor_)
1580+ : toRecycle_;
1581+
1582+ // make sure no other thead is evicting the item
1583+ if (candidate_->getRefCount () == 0 && candidate_->markMoving ()) {
1584+ toRecycle = toRecycle_;
1585+ candidate = candidate_;
1586+ return ;
1587+ }
1588+
1589+ ++itr;
1590+ }
1591+ });
1592+
1593+ if (!toRecycle)
15811594 continue ;
1582- }
1583-
1584- itr. destroy ( );
1595+
1596+ XDCHECK (toRecycle);
1597+ XDCHECK (candidate );
15851598
15861599 // for chained items, the ownership of the parent can change. We try to
15871600 // evict what we think as parent and see if the eviction of parent
@@ -1635,8 +1648,6 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
16351648 return toRecycle;
16361649 }
16371650 }
1638-
1639- itr.resetToBegin ();
16401651 }
16411652 return nullptr ;
16421653}
0 commit comments