Skip to content

Commit 9f5dc7c

Browse files
authored
Merge pull request #11 from byrnedj/sync
use transparent sync for item movement
2 parents acdfa0b + d1680ea commit 9f5dc7c

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Diff for: cachelib/allocator/CacheAllocator-inl.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ CacheAllocator<CacheTrait>::insertOrReplace(const ItemHandle& handle) {
11751175
/* Next two methods are used to asynchronously move Item between memory tiers.
11761176
*
11771177
* The thread, which moves Item, allocates new Item in the tier we are moving to
1178-
* and calls moveRegularItemOnEviction() method. This method does the following:
1178+
* and calls moveRegularItemWithSync() method. This method does the following:
11791179
* 1. Create MoveCtx and put it to the movesMap.
11801180
* 2. Update the access container with the new item from the tier we are
11811181
* moving to. This Item has kIncomplete flag set.
@@ -1204,9 +1204,10 @@ bool CacheAllocator<CacheTrait>::addWaitContextForMovingItem(
12041204
}
12051205

12061206
template <typename CacheTrait>
1207+
template <typename P>
12071208
typename CacheAllocator<CacheTrait>::ItemHandle
1208-
CacheAllocator<CacheTrait>::moveRegularItemOnEviction(
1209-
Item& oldItem, ItemHandle& newItemHdl) {
1209+
CacheAllocator<CacheTrait>::moveRegularItemWithSync(
1210+
Item& oldItem, ItemHandle& newItemHdl, P&& predicate) {
12101211
XDCHECK(oldItem.isMoving());
12111212
// TODO: should we introduce new latency tracker. E.g. evictRegularLatency_
12121213
// ??? util::LatencyTracker tracker{stats_.evictRegularLatency_};
@@ -1266,7 +1267,7 @@ CacheAllocator<CacheTrait>::moveRegularItemOnEviction(
12661267
// it is unsafe to replace the old item with a new one, so we should
12671268
// also abort.
12681269
if (!accessContainer_->replaceIf(oldItem, *newItemHdl,
1269-
itemMovingPredicate)) {
1270+
predicate)) {
12701271
return {};
12711272
}
12721273

@@ -1626,8 +1627,7 @@ CacheAllocator<CacheTrait>::tryEvictToNextMemoryTier(
16261627

16271628
if (newItemHdl) {
16281629
XDCHECK_EQ(newItemHdl->getSize(), item.getSize());
1629-
1630-
return moveRegularItemOnEviction(item, newItemHdl);
1630+
return moveRegularItemWithSync(item, newItemHdl, itemMovingPredicate);
16311631
}
16321632
}
16331633

Diff for: cachelib/allocator/CacheAllocator.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,8 @@ class CacheAllocator : public CacheBase {
14101410
//
14111411
// @return true If the move was completed, and the containers were updated
14121412
// successfully.
1413-
ItemHandle moveRegularItemOnEviction(Item& oldItem, ItemHandle& newItemHdl);
1413+
template <typename P>
1414+
ItemHandle moveRegularItemWithSync(Item& oldItem, ItemHandle& newItemHdl, P&& predicate);
14141415

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

0 commit comments

Comments
 (0)