@@ -49,9 +49,7 @@ CacheAllocator<CacheTrait>::CacheAllocator(Config config)
49
49
[this ](Item* it) -> ItemHandle { return acquire (it); })),
50
50
chainedItemLocks_ (config_.chainedItemsLockPower,
51
51
std::make_shared<MurmurHash2>()),
52
- cacheCreationTime_{util::getCurrentTimeSec ()},
53
- nvmCacheState_{config_.cacheDir , config_.isNvmCacheEncryptionEnabled (),
54
- config_.isNvmCacheTruncateAllocSizeEnabled ()} {
52
+ cacheCreationTime_{util::getCurrentTimeSec ()} {
55
53
// TODO(MEMORY_TIER)
56
54
if (std::holds_alternative<FileShmSegmentOpts>(
57
55
memoryTierConfigs[0 ].getShmTypeOpts ())) {
@@ -97,9 +95,7 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemNewT, Config config)
97
95
[this](Item* it) -> ItemHandle { return acquire (it); })),
98
96
chainedItemLocks_(config_.chainedItemsLockPower,
99
97
std::make_shared<MurmurHash2>()),
100
- cacheCreationTime_{util::getCurrentTimeSec ()},
101
- nvmCacheState_{config_.cacheDir , config_.isNvmCacheEncryptionEnabled (),
102
- config_.isNvmCacheTruncateAllocSizeEnabled ()} {
98
+ cacheCreationTime_{util::getCurrentTimeSec ()} {
103
99
initCommon (false );
104
100
shmManager_->removeShm (detail::kShmInfoName ,
105
101
PosixSysVSegmentOpts (config_.isUsingPosixShm ()));
@@ -134,9 +130,7 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemAttachT, Config config)
134
130
[this](Item* it) -> ItemHandle { return acquire (it); })),
135
131
chainedItemLocks_(config_.chainedItemsLockPower,
136
132
std::make_shared<MurmurHash2>()),
137
- cacheCreationTime_{*metadata_.cacheCreationTime_ref ()},
138
- nvmCacheState_{config_.cacheDir , config_.isNvmCacheEncryptionEnabled (),
139
- config_.isNvmCacheTruncateAllocSizeEnabled ()} {
133
+ cacheCreationTime_{*metadata_.cacheCreationTime_ref ()} {
140
134
for (auto pid : *metadata_.compactCachePools_ref ()) {
141
135
isCompactCachePool_[pid] = true ;
142
136
}
@@ -207,7 +201,7 @@ CacheAllocator<CacheTrait>::restoreCCacheManager() {
207
201
208
202
template <typename CacheTrait>
209
203
void CacheAllocator<CacheTrait>::initCommon(bool dramCacheAttached) {
210
- if (config_.nvmConfig . has_value ()) {
204
+ if (config_.isNvmCacheEnabled ()) {
211
205
if (config_.nvmCacheAP ) {
212
206
nvmAdmissionPolicy_ = config_.nvmCacheAP ;
213
207
} else if (config_.rejectFirstAPNumEntries ) {
@@ -230,24 +224,27 @@ void CacheAllocator<CacheTrait>::initCommon(bool dramCacheAttached) {
230
224
231
225
template <typename CacheTrait>
232
226
void CacheAllocator<CacheTrait>::initNvmCache(bool dramCacheAttached) {
233
- if (!config_.nvmConfig . has_value ()) {
227
+ if (!config_.isNvmCacheEnabled ()) {
234
228
return ;
235
229
}
236
230
231
+ nvmCacheState_.emplace (NvmCacheState (config_.cacheDir , config_.isNvmCacheEncryptionEnabled (),
232
+ config_.isNvmCacheTruncateAllocSizeEnabled ()));
233
+
237
234
// for some usecases that create pools, restoring nvmcache when dram cache
238
235
// is not persisted is not supported.
239
236
const bool shouldDrop = config_.dropNvmCacheOnShmNew && !dramCacheAttached;
240
237
241
238
// if we are dealing with persistency, cache directory should be enabled
242
239
const bool truncate = config_.cacheDir .empty () ||
243
- nvmCacheState_.shouldStartFresh () || shouldDrop;
240
+ nvmCacheState_.value (). shouldStartFresh () || shouldDrop;
244
241
if (truncate) {
245
- nvmCacheState_.markTruncated ();
242
+ nvmCacheState_.value (). markTruncated ();
246
243
}
247
244
248
245
nvmCache_ = std::make_unique<NvmCacheT>(*this , *config_.nvmConfig , truncate);
249
246
if (!config_.cacheDir .empty ()) {
250
- nvmCacheState_.clearPrevState ();
247
+ nvmCacheState_.value (). clearPrevState ();
251
248
}
252
249
}
253
250
@@ -3057,7 +3054,7 @@ std::optional<bool> CacheAllocator<CacheTrait>::saveNvmCache() {
3057
3054
return false ;
3058
3055
}
3059
3056
3060
- nvmCacheState_.markSafeShutDown ();
3057
+ nvmCacheState_.value (). markSafeShutDown ();
3061
3058
return true ;
3062
3059
}
3063
3060
@@ -3252,8 +3249,8 @@ GlobalCacheStats CacheAllocator<CacheTrait>::getGlobalCacheStats() const {
3252
3249
3253
3250
const uint64_t currTime = util::getCurrentTimeSec ();
3254
3251
ret.ramUpTime = currTime - cacheCreationTime_;
3255
- ret.nvmUpTime = currTime - nvmCacheState_.getCreationTime ();
3256
3252
ret.nvmCacheEnabled = nvmCache_ ? nvmCache_->isEnabled () : false ;
3253
+ ret.nvmUpTime = currTime - getNVMCacheCreationTime ();
3257
3254
ret.reaperStats = getReaperStats ();
3258
3255
ret.numActiveHandles = getNumActiveHandles ();
3259
3256
0 commit comments