Skip to content

Commit 945a383

Browse files
committed
use transparent sync for item movement
1 parent 2e9d98f commit 945a383

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

cachelib/allocator/CacheAllocator-inl.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ CacheAllocator<CacheTrait>::insertOrReplace(const WriteHandle& handle) {
12011201
/* Next two methods are used to asynchronously move Item between memory tiers.
12021202
*
12031203
* The thread, which moves Item, allocates new Item in the tier we are moving to
1204-
* and calls moveRegularItemOnEviction() method. This method does the following:
1204+
* and calls moveRegularItemWithSync() method. This method does the following:
12051205
* 1. Create MoveCtx and put it to the movesMap.
12061206
* 2. Update the access container with the new item from the tier we are
12071207
* moving to. This Item has kIncomplete flag set.
@@ -1230,9 +1230,10 @@ bool CacheAllocator<CacheTrait>::addWaitContextForMovingItem(
12301230
}
12311231

12321232
template <typename CacheTrait>
1233+
template <typename P>
12331234
typename CacheAllocator<CacheTrait>::WriteHandle
1234-
CacheAllocator<CacheTrait>::moveRegularItemOnEviction(
1235-
Item& oldItem, WriteHandle& newItemHdl) {
1235+
CacheAllocator<CacheTrait>::moveRegularItemWithSync(
1236+
Item& oldItem, WriteHandle& newItemHdl, P&& predicate) {
12361237
XDCHECK(oldItem.isExclusive());
12371238
// TODO: should we introduce new latency tracker. E.g. evictRegularLatency_
12381239
// ??? util::LatencyTracker tracker{stats_.evictRegularLatency_};
@@ -1292,7 +1293,7 @@ CacheAllocator<CacheTrait>::moveRegularItemOnEviction(
12921293
// it is unsafe to replace the old item with a new one, so we should
12931294
// also abort.
12941295
if (!accessContainer_->replaceIf(oldItem, *newItemHdl,
1295-
itemExclusivePredicate)) {
1296+
predicate)) {
12961297
return {};
12971298
}
12981299

@@ -1649,14 +1650,14 @@ CacheAllocator<CacheTrait>::tryEvictToNextMemoryTier(
16491650

16501651
if (newItemHdl) {
16511652
XDCHECK_EQ(newItemHdl->getSize(), item.getSize());
1652-
1653-
return moveRegularItemOnEviction(item, newItemHdl);
1653+
return moveRegularItemWithSync(item, newItemHdl, itemExclusivePredicate);
16541654
}
16551655
}
16561656

16571657
return {};
16581658
}
16591659

1660+
16601661
template <typename CacheTrait>
16611662
typename CacheAllocator<CacheTrait>::WriteHandle
16621663
CacheAllocator<CacheTrait>::tryEvictToNextMemoryTier(Item& item) {

cachelib/allocator/CacheAllocator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,8 @@ class CacheAllocator : public CacheBase {
15511551
//
15521552
// @return true If the move was completed, and the containers were updated
15531553
// successfully.
1554-
WriteHandle moveRegularItemOnEviction(Item& oldItem, WriteHandle& newItemHdl);
1554+
template <typename P>
1555+
WriteHandle moveRegularItemWithSync(Item& oldItem, WriteHandle& newItemHdl, P&& predicate);
15551556

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

cachelib/allocator/CacheStats.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct SizeVerify {};
5353

5454
void Stats::populateGlobalCacheStats(GlobalCacheStats& ret) const {
5555
#ifndef SKIP_SIZE_VERIFY
56-
SizeVerify<sizeof(Stats)> a = SizeVerify<16176>{};
56+
SizeVerify<sizeof(Stats)> a = SizeVerify<16192>{};
5757
std::ignore = a;
5858
#endif
5959
ret.numCacheGets = numCacheGets.get();

0 commit comments

Comments
 (0)