@@ -1641,7 +1641,13 @@ typename CacheAllocator<CacheTrait>::WriteHandle
1641
1641
CacheAllocator<CacheTrait>::tryEvictToNextMemoryTier(
1642
1642
TierId tid, PoolId pid, Item& item) {
1643
1643
if (item.isChainedItem ()) return {}; // TODO: We do not support ChainedItem yet
1644
- if (item.isExpired ()) return acquire (&item);
1644
+ if (item.isExpired ()) {
1645
+ auto handle = removeIf (item, [](const Item& it) {
1646
+ return it.getRefCount () == 0 ;
1647
+ });
1648
+
1649
+ if (handle) { return handle; }
1650
+ }
1645
1651
1646
1652
TierId nextTier = tid; // TODO - calculate this based on some admission policy
1647
1653
while (++nextTier < getNumTiers ()) { // try to evict down to the next memory tiers
@@ -3067,16 +3073,12 @@ CacheAllocator<CacheTrait>::evictNormalItem(Item& item,
3067
3073
// We remove the item from both access and mm containers. It doesn't matter
3068
3074
// if someone else calls remove on the item at this moment, the item cannot
3069
3075
// be freed as long as we have the moving bit set.
3070
- auto handle = accessContainer_->removeIf (item, std::move (predicate));
3071
-
3076
+ auto handle = removeIf (item, std::move (predicate));
3072
3077
if (!handle) {
3073
3078
return handle;
3074
3079
}
3075
3080
3076
- XDCHECK_EQ (reinterpret_cast <uintptr_t >(handle.get ()),
3077
- reinterpret_cast <uintptr_t >(&item));
3078
3081
XDCHECK_EQ (1u , handle->getRefCount ());
3079
- removeFromMMContainer (item);
3080
3082
3081
3083
// now that we are the only handle and we actually removed something from
3082
3084
// the RAM cache, we enqueue it to nvmcache.
@@ -3188,6 +3190,21 @@ CacheAllocator<CacheTrait>::evictChainedItemForSlabRelease(ChainedItem& child) {
3188
3190
return parentHandle;
3189
3191
}
3190
3192
3193
+ template <typename CacheTrait>
3194
+ template <typename Fn>
3195
+ typename CacheAllocator<CacheTrait>::WriteHandle
3196
+ CacheAllocator<CacheTrait>::removeIf(Item& item, Fn&& predicate) {
3197
+ auto handle = accessContainer_->removeIf (item, std::forward<Fn>(predicate));
3198
+
3199
+ if (handle) {
3200
+ XDCHECK_EQ (reinterpret_cast <uintptr_t >(handle.get ()),
3201
+ reinterpret_cast <uintptr_t >(&item));
3202
+ removeFromMMContainer (item);
3203
+ }
3204
+
3205
+ return handle;
3206
+ }
3207
+
3191
3208
template <typename CacheTrait>
3192
3209
bool CacheAllocator<CacheTrait>::removeIfExpired(const ReadHandle& handle) {
3193
3210
if (!handle) {
@@ -3196,14 +3213,7 @@ bool CacheAllocator<CacheTrait>::removeIfExpired(const ReadHandle& handle) {
3196
3213
3197
3214
// We remove the item from both access and mm containers.
3198
3215
// We want to make sure the caller is the only one holding the handle.
3199
- auto removedHandle =
3200
- accessContainer_->removeIf (*(handle.getInternal ()), itemExpiryPredicate);
3201
- if (removedHandle) {
3202
- removeFromMMContainer (*(handle.getInternal ()));
3203
- return true ;
3204
- }
3205
-
3206
- return false ;
3216
+ return (bool )removeIf (*(handle.getInternal ()), itemExpiryPredicate);
3207
3217
}
3208
3218
3209
3219
template <typename CacheTrait>
0 commit comments