@@ -1481,11 +1481,11 @@ class CacheAllocator : public CacheBase {
14811481 // Given an existing item, allocate a new one for the
14821482 // existing one to later be moved into.
14831483 //
1484- // @param oldItem the item we want to allocate a new item for
1484+ // @param item reference to the item we want to allocate a new item for
14851485 //
14861486 // @return handle to the newly allocated item
14871487 //
1488- WriteHandle allocateNewItemForOldItem (const Item& oldItem );
1488+ WriteHandle allocateNewItemForOldItem (const Item& item );
14891489
14901490 // internal helper that grabs a refcounted handle to the item. This does
14911491 // not record the access to reflect in the mmContainer.
@@ -1544,7 +1544,7 @@ class CacheAllocator : public CacheBase {
15441544 // callback is responsible for copying the contents and fixing the semantics
15451545 // of chained item.
15461546 //
1547- // @param oldItem Reference to the item being moved
1547+ // @param oldItem item being moved
15481548 // @param newItemHdl Reference to the handle of the new item being moved into
15491549 //
15501550 // @return true If the move was completed, and the containers were updated
@@ -1980,18 +1980,14 @@ class CacheAllocator : public CacheBase {
19801980 std::optional<bool > saveNvmCache ();
19811981 void saveRamCache ();
19821982
1983- static bool itemExclusivePredicate (const Item& item) {
1984- return item.getRefCount () == 0 ;
1983+ static bool itemSlabMovePredicate (const Item& item) {
1984+ return item.isMoving () && item. getRefCount () == 0 ;
19851985 }
19861986
19871987 static bool itemExpiryPredicate (const Item& item) {
19881988 return item.getRefCount () == 1 && item.isExpired ();
19891989 }
19901990
1991- static bool parentEvictForSlabReleasePredicate (const Item& item) {
1992- return item.getRefCount () == 1 && !item.isMoving ();
1993- }
1994-
19951991 std::unique_ptr<Deserializer> createDeserializer ();
19961992
19971993 // Execute func on each item. `func` can throw exception but must ensure
@@ -3663,12 +3659,9 @@ CacheAllocator<CacheTrait>::getNextCandidate(PoolId pid,
36633659 ? &toRecycle_->asChainedItem ().getParentItem (compressor_)
36643660 : toRecycle_;
36653661
3666- const bool evictToNvmCache = shouldWriteToNvmCache (*candidate_);
3667- auto putToken = evictToNvmCache
3668- ? nvmCache_->createPutToken (candidate_->getKey ())
3669- : typename NvmCacheT::PutToken{};
3662+ auto putToken = createPutToken (*candidate_);
36703663
3671- if (evictToNvmCache && !putToken.isValid ()) {
3664+ if (shouldWriteToNvmCache (*candidate_) && !putToken.isValid ()) {
36723665 stats_.evictFailConcurrentFill .inc ();
36733666 ++itr;
36743667 continue ;
@@ -4291,13 +4284,13 @@ std::vector<std::string> CacheAllocator<CacheTrait>::dumpEvictionIterator(
42914284 std::vector<std::string> content;
42924285
42934286 auto & mm = *mmContainers_[pid][cid];
4294- auto evictItr = mm. getEvictionIterator ();
4295- size_t i = 0 ;
4296- while (evictItr && i < numItems) {
4297- content.push_back (evictItr ->toString ());
4298- ++evictItr ;
4299- ++i;
4300- }
4287+
4288+ mm. withEvictionIterator ([&content, numItems]( auto && itr) {
4289+ while (itr && content. size () < numItems) {
4290+ content.push_back (itr ->toString ());
4291+ ++itr ;
4292+ }
4293+ });
43014294
43024295 return content;
43034296}
@@ -4942,6 +4935,7 @@ bool CacheAllocator<CacheTrait>::moveForSlabRelease(Item& oldItem) {
49424935template <typename CacheTrait>
49434936typename CacheAllocator<CacheTrait>::WriteHandle
49444937CacheAllocator<CacheTrait>::allocateNewItemForOldItem(const Item& oldItem) {
4938+ XDCHECK (oldItem.isMoving ());
49454939 if (oldItem.isChainedItem ()) {
49464940 const Item& parentItem = oldItem.asChainedItem ().getParentItem (compressor_);
49474941
@@ -4955,7 +4949,7 @@ CacheAllocator<CacheTrait>::allocateNewItemForOldItem(const Item& oldItem) {
49554949 XDCHECK_EQ (newItemHdl->getSize (), oldChainedItem.getSize ());
49564950 XDCHECK_EQ (reinterpret_cast <uintptr_t >(&parentItem),
49574951 reinterpret_cast <uintptr_t >(
4958- &oldChainedItem .getParentItem (compressor_)));
4952+ &newItemHdl-> asChainedItem () .getParentItem (compressor_)));
49594953
49604954 return newItemHdl;
49614955 }
0 commit comments