@@ -1452,26 +1452,39 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
14521452 // Keep searching for a candidate until we were able to evict it
14531453 // or until the search limit has been exhausted
14541454 unsigned int searchTries = 0 ;
1455- auto itr = mmContainer.getEvictionIterator ();
14561455 while ((config_.evictionSearchTries == 0 ||
1457- config_.evictionSearchTries > searchTries) &&
1458- itr) {
1456+ config_.evictionSearchTries > searchTries)) {
14591457 ++searchTries;
14601458
1461- Item* toRecycle = itr.get ();
1459+ Item* toRecycle = nullptr ;
1460+ Item* candidate = nullptr ;
14621461
1463- Item* candidate =
1464- toRecycle-> isChainedItem ()
1465- ? &toRecycle-> asChainedItem (). getParentItem (compressor_)
1466- : toRecycle ;
1462+ mmContainer. withEvictionIterator ([ this , & candidate, &toRecycle, &searchTries]( auto &&itr){
1463+ while ((config_. evictionSearchTries == 0 ||
1464+ config_. evictionSearchTries > searchTries) && itr) {
1465+ ++searchTries ;
14671466
1468- // make sure no other thead is evicting the item
1469- if (candidate->getRefCount () != 0 || !candidate->markMoving ()) {
1470- ++itr;
1467+ auto *toRecycle_ = itr.get ();
1468+ auto *candidate_ = toRecycle_->isChainedItem ()
1469+ ? &toRecycle_->asChainedItem ().getParentItem (compressor_)
1470+ : toRecycle_;
1471+
1472+ // make sure no other thead is evicting the item
1473+ if (candidate_->getRefCount () == 0 && candidate_->markMoving ()) {
1474+ toRecycle = toRecycle_;
1475+ candidate = candidate_;
1476+ return ;
1477+ }
1478+
1479+ ++itr;
1480+ }
1481+ });
1482+
1483+ if (!toRecycle)
14711484 continue ;
1472- }
1473-
1474- itr. destroy ( );
1485+
1486+ XDCHECK (toRecycle);
1487+ XDCHECK (candidate );
14751488
14761489 // for chained items, the ownership of the parent can change. We try to
14771490 // evict what we think as parent and see if the eviction of parent
@@ -1525,8 +1538,6 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
15251538 return toRecycle;
15261539 }
15271540 }
1528-
1529- itr.resetToBegin ();
15301541 }
15311542 return nullptr ;
15321543}
0 commit comments