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