Skip to content

Commit 1521efe

Browse files
committed
Chained item movement between tiers - sync on the parent item (#84)
* Chained item movement between tiers - currently sync on the parent item for moving. - updated tests accordingly, note that we can no longer swap parent item if chained item is being moved for slab release. * added some debug checks around chained item check * fix slab release behavior if no movecb
1 parent 7d06531 commit 1521efe

File tree

8 files changed

+225
-71
lines changed

8 files changed

+225
-71
lines changed

cachelib/allocator/CacheAllocator.h

Lines changed: 176 additions & 54 deletions
Large diffs are not rendered by default.

cachelib/allocator/tests/BaseAllocatorTest.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4916,7 +4916,7 @@ class BaseAllocatorTest : public AllocatorTest<AllocatorT> {
49164916

49174917
std::memcpy(newItem.getMemory(), oldItem.getMemory(), oldItem.getSize());
49184918
++numMoves;
4919-
});
4919+
}, {}, 1000000 /* lots of moving tries */);
49204920

49214921
AllocatorT alloc(config);
49224922
const size_t numBytes = alloc.getCacheMemoryStats().ramCacheSize;
@@ -4957,15 +4957,15 @@ class BaseAllocatorTest : public AllocatorTest<AllocatorT> {
49574957
}
49584958

49594959
/* sleep override */
4960-
std::this_thread::sleep_for(std::chrono::milliseconds(100));
4960+
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
49614961
}
49624962
};
49634963

49644964
// Release 5 slabs
49654965
auto releaseFn = [&] {
49664966
for (unsigned int i = 0; i < 5;) {
49674967
/* sleep override */
4968-
std::this_thread::sleep_for(std::chrono::milliseconds(100));
4968+
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
49694969

49704970
ClassId cid = static_cast<ClassId>(i);
49714971
alloc.releaseSlab(pid, cid, SlabReleaseMode::kRebalance);
@@ -5125,7 +5125,7 @@ class BaseAllocatorTest : public AllocatorTest<AllocatorT> {
51255125
auto releaseFn = [&] {
51265126
for (unsigned int i = 0; i < 5;) {
51275127
/* sleep override */
5128-
std::this_thread::sleep_for(std::chrono::milliseconds(100));
5128+
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
51295129

51305130
ClassId cid = static_cast<ClassId>(i);
51315131
alloc.releaseSlab(pid, cid, SlabReleaseMode::kRebalance);
@@ -5968,7 +5968,6 @@ class BaseAllocatorTest : public AllocatorTest<AllocatorT> {
59685968
EXPECT_EQ(nullptr,
59695969
util::allocateAccessible(alloc, poolId, "large", largeSize));
59705970

5971-
std::this_thread::sleep_for(std::chrono::seconds{1});
59725971
// trigger the slab rebalance
59735972
EXPECT_EQ(nullptr,
59745973
util::allocateAccessible(alloc, poolId, "large", largeSize));

cachelib/allocator/tests/RebalanceStrategyTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ class RebalanceStrategyTest : public testing::Test {
214214
config.poolRebalancerFreeAllocThreshold = 20;
215215

216216
initAllocatorConfigForStrategy(config, LruTailAge);
217+
//TODO: why does this fail with orig. value of 8?
218+
//on upstream this fails too, it always reports 4 instead
219+
//of the original test value, which is 8 expected slabs
217220
doWork(config, true, 8);
218221
}
219222

cachelib/allocator/tests/RefCountTest.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,6 @@ void RefCountTest::testMarkForEvictionAndMoving() {
209209
ASSERT_EQ(ret, 0);
210210
}
211211

212-
{
213-
// cannot mark moving when ref count > 0
214-
RefcountWithFlags ref;
215-
ref.markInMMContainer();
216-
217-
ref.incRef();
218-
219-
ASSERT_FALSE(ref.markMoving());
220-
}
221-
222212
{
223213
// cannot mark for eviction when ref count > 0
224214
RefcountWithFlags ref;

cachelib/allocator/tests/SimpleRebalancingTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class SimpleRebalanceTest : public testing::Test {
104104

105105
// Sleep for 2 seconds to let the rebalancing work
106106
/* sleep override */
107-
std::this_thread::sleep_for(std::chrono::seconds(3));
107+
std::this_thread::sleep_for(std::chrono::seconds(10));
108108

109109
// Evicted keys shouldn't be in the allocator anymore
110110
ASSERT_FALSE(evictedKeys.empty());

cachelib/cachebench/runner/CacheStressor.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class CacheStressor : public Stressor {
7777
std::unique_lock<folly::SharedMutex> lock;
7878

7979
CacheStressSyncObj(CacheStressor& s, std::string itemKey)
80-
: lock{s.chainedItemAcquireUniqueLock(itemKey)} {}
80+
: lock{s.chainedItemTryAcquireUniqueLock(itemKey)} {}
8181
};
8282
movingSync = [this](typename CacheT::Item::Key key) {
8383
return std::make_unique<CacheStressSyncObj>(*this, key.str());
@@ -247,6 +247,10 @@ class CacheStressor : public Stressor {
247247
using Lock = std::unique_lock<folly::SharedMutex>;
248248
return lockEnabled_ ? Lock{getLock(key)} : Lock{};
249249
}
250+
auto chainedItemTryAcquireUniqueLock(Key key) {
251+
using Lock = std::unique_lock<folly::SharedMutex>;
252+
return lockEnabled_ ? Lock{getLock(key), std::try_to_lock} : Lock{};
253+
}
250254

251255
// populate the input item handle according to the stress setup.
252256
void populateItem(WriteHandle& handle, const std::string& itemValue = "") {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// @nolint like default.json, but moves items during slab release instead of evicting them.
2+
{
3+
"cache_config" : {
4+
"cacheSizeMB" : 2248,
5+
"cacheDir": "/tmp/mem-tier5",
6+
"memoryTiers" : [
7+
{
8+
"ratio": 1,
9+
"memBindNodes": 0
10+
}, {
11+
"ratio": 1,
12+
"memBindNodes": 0
13+
}
14+
],
15+
"poolRebalanceIntervalSec" : 1,
16+
"moveOnSlabRelease" : true,
17+
"rebalanceMinSlabs" : 2,
18+
"evictorThreads": 2,
19+
"promoterThreads": 2
20+
},
21+
"test_config" :
22+
{
23+
"preallocateCache" : true,
24+
"numOps" : 20000000,
25+
"numThreads" : 32,
26+
"numKeys" : 250000,
27+
"generator": "online",
28+
"keySizeRange" : [1, 8, 32, 64, 128, 256, 512],
29+
"keySizeRangeProbability" : [0.1, 0.1, 0.2, 0.2, 0.3, 0.1],
30+
"valSizeRange" : [1, 128, 512, 1024, 4096, 10240, 20480, 40960, 60000],
31+
"valSizeRangeProbability" : [0.1, 0.1, 0.1, 0.2, 0.2, 0.1, 0.1, 0.1],
32+
"getRatio" : 0.70,
33+
"setRatio" : 0.30
34+
}
35+
}

run_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ fi
1313

1414
../bin/cachebench --json_test_config ../test_configs/consistency/navy.json
1515
../bin/cachebench --json_test_config ../test_configs/consistency/navy-multi-tier.json
16+
../bin/cachebench --json_test_config ../test_configs/small_moving_bg.json

0 commit comments

Comments
 (0)