@@ -46,9 +46,7 @@ CacheAllocator<CacheTrait>::CacheAllocator(Config config)
46
46
[this ](Item* it) -> ItemHandle { return acquire (it); })),
47
47
chainedItemLocks_ (config_.chainedItemsLockPower,
48
48
std::make_shared<MurmurHash2>()),
49
- cacheCreationTime_{util::getCurrentTimeSec ()},
50
- nvmCacheState_{config_.cacheDir , config_.isNvmCacheEncryptionEnabled (),
51
- config_.isNvmCacheTruncateAllocSizeEnabled ()} {
49
+ cacheCreationTime_{util::getCurrentTimeSec ()} {
52
50
// TODO(MEMORY_TIER)
53
51
if (std::holds_alternative<FileShmSegmentOpts>(
54
52
memoryTierConfigs[0 ].getShmTypeOpts ())) {
@@ -94,9 +92,7 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemNewT, Config config)
94
92
[this](Item* it) -> ItemHandle { return acquire (it); })),
95
93
chainedItemLocks_(config_.chainedItemsLockPower,
96
94
std::make_shared<MurmurHash2>()),
97
- cacheCreationTime_{util::getCurrentTimeSec ()},
98
- nvmCacheState_{config_.cacheDir , config_.isNvmCacheEncryptionEnabled (),
99
- config_.isNvmCacheTruncateAllocSizeEnabled ()} {
95
+ cacheCreationTime_{util::getCurrentTimeSec ()} {
100
96
initCommon (false );
101
97
shmManager_->removeShm (detail::kShmInfoName ,
102
98
PosixSysVSegmentOpts (config_.isUsingPosixShm ()));
@@ -131,9 +127,7 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemAttachT, Config config)
131
127
[this](Item* it) -> ItemHandle { return acquire (it); })),
132
128
chainedItemLocks_(config_.chainedItemsLockPower,
133
129
std::make_shared<MurmurHash2>()),
134
- cacheCreationTime_{*metadata_.cacheCreationTime_ref ()},
135
- nvmCacheState_{config_.cacheDir , config_.isNvmCacheEncryptionEnabled (),
136
- config_.isNvmCacheTruncateAllocSizeEnabled ()} {
130
+ cacheCreationTime_{*metadata_.cacheCreationTime_ref ()} {
137
131
for (auto pid : *metadata_.compactCachePools_ref ()) {
138
132
isCompactCachePool_[pid] = true ;
139
133
}
@@ -204,7 +198,7 @@ CacheAllocator<CacheTrait>::restoreCCacheManager() {
204
198
205
199
template <typename CacheTrait>
206
200
void CacheAllocator<CacheTrait>::initCommon(bool dramCacheAttached) {
207
- if (config_.nvmConfig . has_value ()) {
201
+ if (config_.isNvmCacheEnabled ()) {
208
202
if (config_.nvmCacheAP ) {
209
203
nvmAdmissionPolicy_ = config_.nvmCacheAP ;
210
204
} else if (config_.rejectFirstAPNumEntries ) {
@@ -227,25 +221,28 @@ void CacheAllocator<CacheTrait>::initCommon(bool dramCacheAttached) {
227
221
228
222
template <typename CacheTrait>
229
223
void CacheAllocator<CacheTrait>::initNvmCache(bool dramCacheAttached) {
230
- if (!config_.nvmConfig . has_value ()) {
224
+ if (!config_.isNvmCacheEnabled ()) {
231
225
return ;
232
226
}
233
227
228
+ nvmCacheState_.emplace (NvmCacheState (config_.cacheDir , config_.isNvmCacheEncryptionEnabled (),
229
+ config_.isNvmCacheTruncateAllocSizeEnabled ()));
230
+
234
231
// for some usecases that create pools, restoring nvmcache when dram cache
235
232
// is not persisted is not supported.
236
233
const bool shouldDrop = config_.dropNvmCacheOnShmNew && !dramCacheAttached;
237
234
238
235
// if we are dealing with persistency, cache directory should be enabled
239
236
const bool truncate = config_.cacheDir .empty () ||
240
- nvmCacheState_.shouldStartFresh () || shouldDrop;
237
+ nvmCacheState_.value (). shouldStartFresh () || shouldDrop;
241
238
if (truncate) {
242
- nvmCacheState_.markTruncated ();
239
+ nvmCacheState_.value (). markTruncated ();
243
240
}
244
241
245
242
nvmCache_ = std::make_unique<NvmCacheT>(*this , *config_.nvmConfig , truncate,
246
243
config_.itemDestructor );
247
244
if (!config_.cacheDir .empty ()) {
248
- nvmCacheState_.clearPrevState ();
245
+ nvmCacheState_.value (). clearPrevState ();
249
246
}
250
247
}
251
248
@@ -3113,7 +3110,7 @@ std::optional<bool> CacheAllocator<CacheTrait>::saveNvmCache() {
3113
3110
return false ;
3114
3111
}
3115
3112
3116
- nvmCacheState_.markSafeShutDown ();
3113
+ nvmCacheState_.value (). markSafeShutDown ();
3117
3114
return true ;
3118
3115
}
3119
3116
@@ -3310,8 +3307,8 @@ GlobalCacheStats CacheAllocator<CacheTrait>::getGlobalCacheStats() const {
3310
3307
3311
3308
const uint64_t currTime = util::getCurrentTimeSec ();
3312
3309
ret.ramUpTime = currTime - cacheCreationTime_;
3313
- ret.nvmUpTime = currTime - nvmCacheState_.getCreationTime ();
3314
3310
ret.nvmCacheEnabled = nvmCache_ ? nvmCache_->isEnabled () : false ;
3311
+ ret.nvmUpTime = currTime - getNVMCacheCreationTime ();
3315
3312
ret.reaperStats = getReaperStats ();
3316
3313
ret.numActiveHandles = getNumActiveHandles ();
3317
3314
0 commit comments