Skip to content

Commit 1f94d28

Browse files
committed
Enabled memory tier config API in cachebench
1 parent a50e2fb commit 1f94d28

File tree

4 files changed

+90
-3
lines changed

4 files changed

+90
-3
lines changed

cachelib/cachebench/cache/Cache-inl.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ Cache<Allocator>::Cache(const CacheConfig& config,
8080

8181
allocatorConfig_.setCacheSize(config_.cacheSizeMB * (MB));
8282

83+
if (!cacheDir.empty()) {
84+
allocatorConfig_.cacheDir = cacheDir;
85+
}
86+
87+
if (config_.usePosixShm) {
88+
allocatorConfig_.usePosixForShm();
89+
}
90+
91+
if (!config_.memoryTierConfigs.empty()) {
92+
allocatorConfig_.configureMemoryTiers(config_.memoryTierConfigs);
93+
}
94+
8395
auto cleanupGuard = folly::makeGuard([&] {
8496
if (!nvmCacheFilePath_.empty()) {
8597
util::removePath(nvmCacheFilePath_);
@@ -222,8 +234,7 @@ Cache<Allocator>::Cache(const CacheConfig& config,
222234
allocatorConfig_.cacheName = "cachebench";
223235

224236
bool isRecovered = false;
225-
if (!cacheDir.empty()) {
226-
allocatorConfig_.cacheDir = cacheDir;
237+
if (!allocatorConfig_.cacheDir.empty()) {
227238
try {
228239
cache_ = std::make_unique<Allocator>(Allocator::SharedMemAttach,
229240
allocatorConfig_);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// @nolint instantiates a small cache and runs a quick run of basic operations.
2+
{
3+
"cache_config" : {
4+
"cacheSizeMB" : 512,
5+
"usePosixShm" : false,
6+
"cacheDir" : "/tmp/mem-tiers",
7+
"memoryTiers" : [
8+
{
9+
"ratio": 1,
10+
"memBindNodes": "0"
11+
}
12+
],
13+
"poolRebalanceIntervalSec" : 1,
14+
"moveOnSlabRelease" : false,
15+
16+
"numPools" : 2,
17+
"poolSizes" : [0.3, 0.7]
18+
},
19+
"test_config" : {
20+
"numOps" : 100000,
21+
"numThreads" : 32,
22+
"numKeys" : 1000000,
23+
24+
"keySizeRange" : [1, 8, 64],
25+
"keySizeRangeProbability" : [0.3, 0.7],
26+
27+
"valSizeRange" : [1, 32, 10240, 409200],
28+
"valSizeRangeProbability" : [0.1, 0.2, 0.7],
29+
30+
"getRatio" : 0.15,
31+
"setRatio" : 0.8,
32+
"delRatio" : 0.05,
33+
"keyPoolDistribution": [0.4, 0.6],
34+
"opPoolDistribution" : [0.5, 0.5]
35+
}
36+
}

cachelib/cachebench/util/CacheConfig.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ CacheConfig::CacheConfig(const folly::dynamic& configJson) {
8484

8585
JSONSetVal(configJson, memoryOnlyTTL);
8686

87+
JSONSetVal(configJson, usePosixShm);
88+
if (configJson.count("memoryTiers")) {
89+
for (auto& it : configJson["memoryTiers"]) {
90+
memoryTierConfigs.push_back(MemoryTierConfig(it).getMemoryTierCacheConfig());
91+
}
92+
}
93+
8794
JSONSetVal(configJson, useTraceTimeStamp);
8895
JSONSetVal(configJson, printNvmCounters);
8996
JSONSetVal(configJson, tickerSynchingSeconds);
@@ -95,7 +102,7 @@ CacheConfig::CacheConfig(const folly::dynamic& configJson) {
95102
// if you added new fields to the configuration, update the JSONSetVal
96103
// to make them available for the json configs and increment the size
97104
// below
98-
checkCorrectSize<CacheConfig, 664>();
105+
checkCorrectSize<CacheConfig, 696>();
99106

100107
if (numPools != poolSizes.size()) {
101108
throw std::invalid_argument(folly::sformat(
@@ -124,6 +131,13 @@ std::shared_ptr<RebalanceStrategy> CacheConfig::getRebalanceStrategy() const {
124131
RandomStrategy::Config{static_cast<unsigned int>(rebalanceMinSlabs)});
125132
}
126133
}
134+
135+
MemoryTierConfig::MemoryTierConfig(const folly::dynamic& configJson) {
136+
JSONSetVal(configJson, ratio);
137+
JSONSetVal(configJson, memBindNodes);
138+
139+
checkCorrectSize<MemoryTierConfig, 40>();
140+
}
127141
} // namespace cachebench
128142
} // namespace cachelib
129143
} // namespace facebook

cachelib/cachebench/util/CacheConfig.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ class CacheMonitorFactory {
4141
virtual std::unique_ptr<CacheMonitor> create(Lru2QAllocator& cache) = 0;
4242
};
4343

44+
// Parse memory tiers configuration from JSON config
45+
struct MemoryTierConfig : public JSONConfig {
46+
MemoryTierConfig() {}
47+
48+
explicit MemoryTierConfig(const folly::dynamic& configJson);
49+
50+
// Returns MemoryTierCacheConfig parsed from JSON config
51+
MemoryTierCacheConfig getMemoryTierCacheConfig() {
52+
MemoryTierCacheConfig config = MemoryTierCacheConfig::fromShm();
53+
config.setRatio(ratio);
54+
config.setMemBind(NumaBitMask(memBindNodes));
55+
return config;
56+
}
57+
58+
// Specifies ratio of this memory tier to other tiers
59+
size_t ratio{0};
60+
// Allocate memory only from specified NUMA nodes
61+
std::string memBindNodes{""};
62+
};
63+
4464
struct CacheConfig : public JSONConfig {
4565
// by defaullt, lru allocator. can be set to LRU-2Q.
4666
std::string allocator{"LRU"};
@@ -194,6 +214,12 @@ struct CacheConfig : public JSONConfig {
194214
// Not used when its value is 0. In seconds.
195215
uint32_t memoryOnlyTTL{0};
196216

217+
// Use Posix Shm instead of SysVShm
218+
bool usePosixShm{false};
219+
220+
// Memory tiers configs
221+
std::vector<MemoryTierCacheConfig> memoryTierConfigs{};
222+
197223
// If enabled, we will use the timestamps from the trace file in the ticker
198224
// so that the cachebench will observe time based on timestamps from the trace
199225
// instead of the system time.

0 commit comments

Comments
 (0)