Skip to content

Commit b61397e

Browse files
byrnedjvinser52
authored andcommitted
use transparent sync for item movement
1 parent 4a6307f commit b61397e

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

cachelib/allocator/CacheAllocator-inl.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ CacheAllocator<CacheTrait>::insertOrReplace(const WriteHandle& handle) {
11931193
/* Next two methods are used to asynchronously move Item between memory tiers.
11941194
*
11951195
* The thread, which moves Item, allocates new Item in the tier we are moving to
1196-
* and calls moveRegularItemOnEviction() method. This method does the following:
1196+
* and calls moveRegularItemWithSync() method. This method does the following:
11971197
* 1. Create MoveCtx and put it to the movesMap.
11981198
* 2. Update the access container with the new item from the tier we are
11991199
* moving to. This Item has kIncomplete flag set.
@@ -1222,9 +1222,10 @@ bool CacheAllocator<CacheTrait>::addWaitContextForMovingItem(
12221222
}
12231223

12241224
template <typename CacheTrait>
1225+
template <typename P>
12251226
typename CacheAllocator<CacheTrait>::WriteHandle
1226-
CacheAllocator<CacheTrait>::moveRegularItemOnEviction(
1227-
Item& oldItem, WriteHandle& newItemHdl) {
1227+
CacheAllocator<CacheTrait>::moveRegularItemWithSync(
1228+
Item& oldItem, WriteHandle& newItemHdl, P&& predicate) {
12281229
XDCHECK(oldItem.isMoving());
12291230
// TODO: should we introduce new latency tracker. E.g. evictRegularLatency_
12301231
// ??? util::LatencyTracker tracker{stats_.evictRegularLatency_};
@@ -1284,7 +1285,7 @@ CacheAllocator<CacheTrait>::moveRegularItemOnEviction(
12841285
// it is unsafe to replace the old item with a new one, so we should
12851286
// also abort.
12861287
if (!accessContainer_->replaceIf(oldItem, *newItemHdl,
1287-
itemMovingPredicate)) {
1288+
predicate)) {
12881289
return {};
12891290
}
12901291

@@ -1652,14 +1653,14 @@ CacheAllocator<CacheTrait>::tryEvictToNextMemoryTier(
16521653

16531654
if (newItemHdl) {
16541655
XDCHECK_EQ(newItemHdl->getSize(), item.getSize());
1655-
1656-
return moveRegularItemOnEviction(item, newItemHdl);
1656+
return moveRegularItemWithSync(item, newItemHdl, itemMovingPredicate);
16571657
}
16581658
}
16591659

16601660
return {};
16611661
}
16621662

1663+
16631664
template <typename CacheTrait>
16641665
typename CacheAllocator<CacheTrait>::WriteHandle
16651666
CacheAllocator<CacheTrait>::tryEvictToNextMemoryTier(Item& item) {

cachelib/allocator/CacheAllocator.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,8 @@ class CacheAllocator : public CacheBase {
14981498
//
14991499
// @return true If the move was completed, and the containers were updated
15001500
// successfully.
1501-
WriteHandle moveRegularItemOnEviction(Item& oldItem, WriteHandle& newItemHdl);
1501+
template <typename P>
1502+
WriteHandle moveRegularItemWithSync(Item& oldItem, WriteHandle& newItemHdl, P&& predicate);
15021503

15031504
// Moves a regular item to a different slab. This should only be used during
15041505
// slab release after the item's moving bit has been set. The user supplied

0 commit comments

Comments
 (0)