@@ -1482,27 +1482,40 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
14821482 // Keep searching for a candidate until we were able to evict it
14831483 // or until the search limit has been exhausted
14841484 unsigned int searchTries = 0 ;
1485- auto itr = mmContainer.getEvictionIterator ();
14861485 while ((config_.evictionSearchTries == 0 ||
1487- config_.evictionSearchTries > searchTries) &&
1488- itr) {
1486+ config_.evictionSearchTries > searchTries)) {
14891487 ++searchTries;
14901488 (*stats_.evictionAttempts )[pid][cid].inc ();
14911489
1492- Item* toRecycle = itr.get ();
1490+ Item* toRecycle = nullptr ;
1491+ Item* candidate = nullptr ;
14931492
1494- Item* candidate =
1495- toRecycle-> isChainedItem ()
1496- ? &toRecycle-> asChainedItem (). getParentItem (compressor_)
1497- : toRecycle ;
1493+ mmContainer. withEvictionIterator ([ this , & candidate, &toRecycle, &searchTries]( auto &&itr){
1494+ while ((config_. evictionSearchTries == 0 ||
1495+ config_. evictionSearchTries > searchTries) && itr) {
1496+ ++searchTries ;
14981497
1499- // make sure no other thead is evicting the item
1500- if (candidate->getRefCount () != 0 || !candidate->markMoving ()) {
1501- ++itr;
1498+ auto *toRecycle_ = itr.get ();
1499+ auto *candidate_ = toRecycle_->isChainedItem ()
1500+ ? &toRecycle_->asChainedItem ().getParentItem (compressor_)
1501+ : toRecycle_;
1502+
1503+ // make sure no other thead is evicting the item
1504+ if (candidate_->getRefCount () == 0 && candidate_->markMoving ()) {
1505+ toRecycle = toRecycle_;
1506+ candidate = candidate_;
1507+ return ;
1508+ }
1509+
1510+ ++itr;
1511+ }
1512+ });
1513+
1514+ if (!toRecycle)
15021515 continue ;
1503- }
1504-
1505- itr. destroy ( );
1516+
1517+ XDCHECK (toRecycle);
1518+ XDCHECK (candidate );
15061519
15071520 // for chained items, the ownership of the parent can change. We try to
15081521 // evict what we think as parent and see if the eviction of parent
@@ -1563,8 +1576,6 @@ CacheAllocator<CacheTrait>::findEviction(TierId tid, PoolId pid, ClassId cid) {
15631576 return toRecycle;
15641577 }
15651578 }
1566-
1567- itr.resetToBegin ();
15681579 }
15691580 return nullptr ;
15701581}
0 commit comments