@@ -46,7 +46,9 @@ CacheAllocator<CacheTrait>::CacheAllocator(Config config)
46
46
std::make_shared<MurmurHash2>()),
47
47
movesMap_(kShards ),
48
48
moveLock_(kShards ),
49
- cacheCreationTime_{util::getCurrentTimeSec ()} {
49
+ cacheCreationTime_{util::getCurrentTimeSec ()},
50
+ nvmCacheState_{config_.cacheDir , config_.isNvmCacheEncryptionEnabled (),
51
+ config_.isNvmCacheTruncateAllocSizeEnabled ()} {
50
52
51
53
if (numTiers_ > 1 || std::holds_alternative<FileShmSegmentOpts>(
52
54
memoryTierConfigs[0 ].getShmTypeOpts ())) {
@@ -134,7 +136,9 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemNewT, Config config)
134
136
std::make_shared<MurmurHash2>()),
135
137
movesMap_(kShards ),
136
138
moveLock_(kShards ),
137
- cacheCreationTime_{util::getCurrentTimeSec ()} {
139
+ cacheCreationTime_{util::getCurrentTimeSec ()},
140
+ nvmCacheState_{config_.cacheDir , config_.isNvmCacheEncryptionEnabled (),
141
+ config_.isNvmCacheTruncateAllocSizeEnabled ()} {
138
142
initCommon (false );
139
143
shmManager_->removeShm (detail::kShmInfoName ,
140
144
PosixSysVSegmentOpts (config_.isUsingPosixShm ()));
@@ -172,8 +176,9 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemAttachT, Config config)
172
176
std::make_shared<MurmurHash2>()),
173
177
movesMap_(kShards ),
174
178
moveLock_(kShards ),
175
- cacheCreationTime_{*metadata_.cacheCreationTime_ref ()} {
176
- /* TODO - per tier? */
179
+ cacheCreationTime_{*metadata_.cacheCreationTime_ref ()},
180
+ nvmCacheState_{config_.cacheDir , config_.isNvmCacheEncryptionEnabled (),
181
+ config_.isNvmCacheTruncateAllocSizeEnabled ()} {
177
182
for (auto pid : *metadata_.compactCachePools_ref ()) {
178
183
isCompactCachePool_[pid] = true ;
179
184
}
@@ -256,7 +261,7 @@ CacheAllocator<CacheTrait>::restoreCCacheManager(TierId tid) {
256
261
257
262
template <typename CacheTrait>
258
263
void CacheAllocator<CacheTrait>::initCommon(bool dramCacheAttached) {
259
- if (config_.isNvmCacheEnabled ()) {
264
+ if (config_.nvmConfig . has_value ()) {
260
265
if (config_.nvmCacheAP ) {
261
266
nvmAdmissionPolicy_ = config_.nvmCacheAP ;
262
267
} else if (config_.rejectFirstAPNumEntries ) {
@@ -282,29 +287,25 @@ void CacheAllocator<CacheTrait>::initCommon(bool dramCacheAttached) {
282
287
283
288
template <typename CacheTrait>
284
289
void CacheAllocator<CacheTrait>::initNvmCache(bool dramCacheAttached) {
285
- if (!config_.isNvmCacheEnabled ()) {
290
+ if (!config_.nvmConfig . has_value ()) {
286
291
return ;
287
292
}
288
293
289
- nvmCacheState_.emplace (NvmCacheState (cacheCreationTime_, config_.cacheDir ,
290
- config_.isNvmCacheEncryptionEnabled (),
291
- config_.isNvmCacheTruncateAllocSizeEnabled ()));
292
-
293
294
// for some usecases that create pools, restoring nvmcache when dram cache
294
295
// is not persisted is not supported.
295
296
const bool shouldDrop = config_.dropNvmCacheOnShmNew && !dramCacheAttached;
296
297
297
298
// if we are dealing with persistency, cache directory should be enabled
298
299
const bool truncate = config_.cacheDir .empty () ||
299
- nvmCacheState_.value (). shouldStartFresh () || shouldDrop;
300
+ nvmCacheState_.shouldStartFresh () || shouldDrop;
300
301
if (truncate) {
301
- nvmCacheState_.value (). markTruncated ();
302
+ nvmCacheState_.markTruncated ();
302
303
}
303
304
304
305
nvmCache_ = std::make_unique<NvmCacheT>(*this , *config_.nvmConfig , truncate,
305
306
config_.itemDestructor );
306
307
if (!config_.cacheDir .empty ()) {
307
- nvmCacheState_.value (). clearPrevState ();
308
+ nvmCacheState_.clearPrevState ();
308
309
}
309
310
}
310
311
@@ -3515,7 +3516,7 @@ std::optional<bool> CacheAllocator<CacheTrait>::saveNvmCache() {
3515
3516
return false ;
3516
3517
}
3517
3518
3518
- nvmCacheState_.value (). markSafeShutDown ();
3519
+ nvmCacheState_.markSafeShutDown ();
3519
3520
return true ;
3520
3521
}
3521
3522
@@ -3717,8 +3718,8 @@ GlobalCacheStats CacheAllocator<CacheTrait>::getGlobalCacheStats() const {
3717
3718
const uint64_t currTime = util::getCurrentTimeSec ();
3718
3719
ret.cacheInstanceUpTime = currTime - cacheCreationTime_;
3719
3720
ret.ramUpTime = currTime - cacheCreationTime_;
3721
+ ret.nvmUpTime = currTime - nvmCacheState_.getCreationTime ();
3720
3722
ret.nvmCacheEnabled = nvmCache_ ? nvmCache_->isEnabled () : false ;
3721
- ret.nvmUpTime = currTime - getNVMCacheCreationTime ();
3722
3723
ret.reaperStats = getReaperStats ();
3723
3724
ret.numActiveHandles = getNumActiveHandles ();
3724
3725
0 commit comments