Skip to content

Commit 02ef4a1

Browse files
Jaesoo Leefacebook-github-bot
authored andcommitted
properly support a file-backed nvm cache
Summary: Previously, in order to use a file as the backing store of nvm cache, user needs to create the file with the given size a priori, hurting the usability of the feature. This change fixes it so that the new file with the given size is automatically created if not exist. Also, if the file exists with different size, this change will allow the cachebench to ftruncate or fallocate to the given size automatically. Reviewed By: therealgymmy Differential Revision: D44154281 fbshipit-source-id: c622102d4d67b64da83dcad4fdade66473d70a1f
1 parent bdb1fc6 commit 02ef4a1

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

cachelib/cachebench/cache/Cache-inl.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,24 +124,41 @@ Cache<Allocator>::Cache(const CacheConfig& config,
124124
// already have a file, user provided it. We will also keep it around
125125
// after the tests.
126126
auto path = config_.nvmCachePaths[0];
127-
if (cachelib::util::isDir(path)) {
127+
bool isDir;
128+
try {
129+
isDir = cachelib::util::isDir(path);
130+
} catch (const std::system_error& e) {
131+
XLOGF(INFO, "nvmCachePath {} does not exist", path);
132+
isDir = false;
133+
}
134+
135+
if (isDir) {
128136
const auto uniqueSuffix = folly::sformat("nvmcache_{}_{}", ::getpid(),
129137
folly::Random::rand32());
130138
path = path + "/" + uniqueSuffix;
131139
util::makeDir(path);
132140
nvmCacheFilePath_ = path;
141+
XLOGF(INFO, "Configuring NVM cache: directory {} size {} MB", path,
142+
config_.nvmCacheSizeMB);
133143
nvmConfig.navyConfig.setSimpleFile(path + "/navy_cache",
134144
config_.nvmCacheSizeMB * MB,
135145
true /*truncateFile*/);
136146
} else {
137-
nvmConfig.navyConfig.setSimpleFile(path, config_.nvmCacheSizeMB * MB);
147+
XLOGF(INFO, "Configuring NVM cache: simple file {} size {} MB", path,
148+
config_.nvmCacheSizeMB);
149+
nvmConfig.navyConfig.setSimpleFile(path, config_.nvmCacheSizeMB * MB,
150+
true /* truncateFile */);
138151
}
139152
} else if (config_.nvmCachePaths.size() > 1) {
153+
XLOGF(INFO, "Configuring NVM cache: RAID-0 ({} devices) size {} MB",
154+
config_.nvmCachePaths.size(), config_.nvmCacheSizeMB);
140155
// set up a software raid-0 across each nvm cache path.
141156
nvmConfig.navyConfig.setRaidFiles(config_.nvmCachePaths,
142157
config_.nvmCacheSizeMB * MB);
143158
} else {
144159
// use memory to mock NVM.
160+
XLOGF(INFO, "Configuring NVM cache: memory file size {} MB",
161+
config_.nvmCacheSizeMB);
145162
nvmConfig.navyConfig.setMemoryFile(config_.nvmCacheSizeMB * MB);
146163
}
147164
nvmConfig.navyConfig.setDeviceMetadataSize(config_.nvmCacheMetadataSizeMB *

cachelib/cachebench/runner/CacheStressor.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,14 @@ class CacheStressor : public Stressor {
9898
}
9999
cacheConfig.nvmWriteBytesCallback =
100100
std::bind(&CacheStressor<Allocator>::getNvmBytesWritten, this);
101-
cache_ = std::make_unique<CacheT>(cacheConfig, movingSync,
102-
cacheConfig.cacheDir, config_.touchValue);
101+
try {
102+
cache_ = std::make_unique<CacheT>(
103+
cacheConfig, movingSync, cacheConfig.cacheDir, config_.touchValue);
104+
} catch (const std::exception& e) {
105+
XLOG(INFO) << "Exception while creating cache: " << e.what();
106+
throw;
107+
}
108+
103109
if (config_.opPoolDistribution.size() > cache_->numPools()) {
104110
throw std::invalid_argument(folly::sformat(
105111
"more pools specified in the test than in the cache. "

0 commit comments

Comments
 (0)