@@ -37,11 +37,11 @@ CacheAllocator<CacheTrait>::CacheAllocator(Config config)
37
37
accessContainer_(std::make_unique<AccessContainer>(
38
38
config_.accessConfig,
39
39
compressor_,
40
- [this ](Item* it) -> ItemHandle { return acquire (it); })),
40
+ [this ](Item* it) -> WriteHandle { return acquire (it); })),
41
41
chainedItemAccessContainer_ (std::make_unique<AccessContainer>(
42
42
config_.chainedItemAccessConfig,
43
43
compressor_,
44
- [this ](Item* it) -> ItemHandle { return acquire (it); })),
44
+ [this ](Item* it) -> WriteHandle { return acquire (it); })),
45
45
chainedItemLocks_ (config_.chainedItemsLockPower,
46
46
std::make_shared<MurmurHash2>()),
47
47
movesMap_(kShards ),
@@ -117,7 +117,7 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemNewT, Config config)
117
117
false, config_.isUsingPosixShm()))
118
118
.addr,
119
119
compressor_,
120
- [this](Item* it) -> ItemHandle { return acquire (it); })),
120
+ [this](Item* it) -> WriteHandle { return acquire (it); })),
121
121
chainedItemAccessContainer_(std::make_unique<AccessContainer>(
122
122
config_.chainedItemAccessConfig,
123
123
shmManager_
@@ -129,7 +129,7 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemNewT, Config config)
129
129
false, config_.isUsingPosixShm()))
130
130
.addr,
131
131
compressor_,
132
- [this](Item* it) -> ItemHandle { return acquire (it); })),
132
+ [this](Item* it) -> WriteHandle { return acquire (it); })),
133
133
chainedItemLocks_(config_.chainedItemsLockPower,
134
134
std::make_shared<MurmurHash2>()),
135
135
movesMap_(kShards ),
@@ -160,14 +160,14 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemAttachT, Config config)
160
160
shmManager_->attachShm(detail::kShmHashTableName , nullptr ,
161
161
ShmSegmentOpts (PageSizeT::NORMAL, false , config_.isUsingPosixShm())),
162
162
compressor_,
163
- [this](Item* it) -> ItemHandle { return acquire (it); })),
163
+ [this](Item* it) -> WriteHandle { return acquire (it); })),
164
164
chainedItemAccessContainer_(std::make_unique<AccessContainer>(
165
165
deserializer_->deserialize<AccessSerializationType>(),
166
166
config_.chainedItemAccessConfig,
167
167
shmManager_->attachShm(detail::kShmChainedItemHashTableName , nullptr ,
168
168
ShmSegmentOpts (PageSizeT::NORMAL, false , config_.isUsingPosixShm())),
169
169
compressor_,
170
- [this](Item* it) -> ItemHandle { return acquire (it); })),
170
+ [this](Item* it) -> WriteHandle { return acquire (it); })),
171
171
chainedItemLocks_(config_.chainedItemsLockPower,
172
172
std::make_shared<MurmurHash2>()),
173
173
movesMap_(kShards ),
@@ -187,53 +187,6 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemAttachT, Config config)
187
187
PosixSysVSegmentOpts (config_.isUsingPosixShm ()));
188
188
}
189
189
190
- template <typename CacheTrait>
191
- CacheAllocator<CacheTrait>::CacheAllocator(
192
- typename CacheAllocator<CacheTrait>::InitMemType type, Config config)
193
- : isOnShm_{type != InitMemType::kNone ? true
194
- : config.memMonitoringEnabled ()},
195
- config_ (config.validate()),
196
- tempShm_(type == InitMemType::kNone && isOnShm_
197
- ? std::make_unique<TempShmMapping>(config_.size)
198
- : nullptr),
199
- shmManager_(type != InitMemType::kNone
200
- ? std::make_unique<ShmManager>(config_.cacheDir,
201
- config_.usePosixShm)
202
- : nullptr),
203
- deserializer_(type == InitMemType::kMemAttach ? createDeserializer()
204
- : nullptr),
205
- metadata_{type == InitMemType::kMemAttach
206
- ? deserializeCacheAllocatorMetadata (*deserializer_)
207
- : serialization::CacheAllocatorMetadata{}},
208
- allocator_ (initAllocator(type)),
209
- compactCacheManager_(type != InitMemType::kMemAttach
210
- ? std::make_unique<CCacheManager>(*allocator_)
211
- : restoreCCacheManager()),
212
- compressor_(createPtrCompressor()),
213
- mmContainers_(type == InitMemType::kMemAttach
214
- ? deserializeMMContainers(*deserializer_, compressor_)
215
- : MMContainers{}),
216
- accessContainer_ (initAccessContainer(
217
- type, detail::kShmHashTableName , config.accessConfig)),
218
- chainedItemAccessContainer_(
219
- initAccessContainer (type,
220
- detail::kShmChainedItemHashTableName ,
221
- config.chainedItemAccessConfig)),
222
- chainedItemLocks_(config_.chainedItemsLockPower,
223
- std::make_shared<MurmurHash2>()),
224
- cacheCreationTime_{
225
- type != InitMemType::kMemAttach
226
- ? util::getCurrentTimeSec ()
227
- : static_cast <uint32_t >(*metadata_.cacheCreationTime ())},
228
- cacheInstanceCreationTime_{type != InitMemType::kMemAttach
229
- ? cacheCreationTime_
230
- : util::getCurrentTimeSec ()},
231
- // Pass in cacheInstnaceCreationTime_ as the current time to keep
232
- // nvmCacheState's current time in sync
233
- nvmCacheState_{cacheInstanceCreationTime_, config_.cacheDir ,
234
- config_.isNvmCacheEncryptionEnabled (),
235
- config_.isNvmCacheTruncateAllocSizeEnabled ()} {}
236
-
237
190
template <typename CacheTrait>
238
191
CacheAllocator<CacheTrait>::~CacheAllocator () {
239
192
XLOG (DBG, " destructing CacheAllocator" );
@@ -333,7 +286,8 @@ void CacheAllocator<CacheTrait>::initNvmCache(bool dramCacheAttached) {
333
286
return ;
334
287
}
335
288
336
- nvmCacheState_.emplace (NvmCacheState (config_.cacheDir , config_.isNvmCacheEncryptionEnabled (),
289
+ nvmCacheState_.emplace (NvmCacheState (cacheCreationTime_, config_.cacheDir ,
290
+ config_.isNvmCacheEncryptionEnabled (),
337
291
config_.isNvmCacheTruncateAllocSizeEnabled ()));
338
292
339
293
// for some usecases that create pools, restoring nvmcache when dram cache
@@ -392,29 +346,6 @@ void CacheAllocator<CacheTrait>::initWorkers() {
392
346
}
393
347
}
394
348
395
- template <typename CacheTrait>
396
- std::unique_ptr<MemoryAllocator> CacheAllocator<CacheTrait>::initAllocator(
397
- InitMemType type) {
398
- if (type == InitMemType::kNone ) {
399
- if (isOnShm_ == true ) {
400
- return std::make_unique<MemoryAllocator>(
401
- getAllocatorConfig (config_), tempShm_->getAddr (), config_.size );
402
- } else {
403
- return std::make_unique<MemoryAllocator>(getAllocatorConfig (config_),
404
- config_.size );
405
- }
406
- } else if (type == InitMemType::kMemNew ) {
407
- return createNewMemoryAllocator ();
408
- } else if (type == InitMemType::kMemAttach ) {
409
- return restoreMemoryAllocator ();
410
- }
411
-
412
- // Invalid type
413
- throw std::runtime_error (folly::sformat (
414
- " Cannot initialize memory allocator, unknown InitMemType: {}." ,
415
- static_cast <int >(type)));
416
- }
417
-
418
349
template <typename CacheTrait>
419
350
std::unique_ptr<typename CacheAllocator<CacheTrait>::AccessContainer>
420
351
CacheAllocator<CacheTrait>::initAccessContainer(InitMemType type,
@@ -475,7 +406,7 @@ CacheAllocator<CacheTrait>::allocate(PoolId poolId,
475
406
}
476
407
477
408
template <typename CacheTrait>
478
- typename CacheAllocator<CacheTrait>::ItemHandle
409
+ typename CacheAllocator<CacheTrait>::WriteHandle
479
410
CacheAllocator<CacheTrait>::allocateInternalTier(TierId tid,
480
411
PoolId pid,
481
412
typename Item::Key key,
@@ -1314,9 +1245,9 @@ bool CacheAllocator<CacheTrait>::addWaitContextForMovingItem(
1314
1245
}
1315
1246
1316
1247
template <typename CacheTrait>
1317
- typename CacheAllocator<CacheTrait>::ItemHandle
1248
+ typename CacheAllocator<CacheTrait>::WriteHandle
1318
1249
CacheAllocator<CacheTrait>::moveRegularItemOnEviction(
1319
- Item& oldItem, ItemHandle & newItemHdl) {
1250
+ Item& oldItem, WriteHandle & newItemHdl) {
1320
1251
XDCHECK (oldItem.isMoving ());
1321
1252
// TODO: should we introduce new latency tracker. E.g. evictRegularLatency_
1322
1253
// ??? util::LatencyTracker tracker{stats_.evictRegularLatency_};
@@ -1348,7 +1279,7 @@ CacheAllocator<CacheTrait>::moveRegularItemOnEviction(
1348
1279
ctx = res.first ->second .get ();
1349
1280
}
1350
1281
1351
- auto resHdl = ItemHandle {};
1282
+ auto resHdl = WriteHandle {};
1352
1283
auto guard = folly::makeGuard ([key, this , ctx, shard, &resHdl]() {
1353
1284
auto & movesMap = getMoveMapForShard (shard);
1354
1285
if (resHdl)
@@ -1390,7 +1321,7 @@ CacheAllocator<CacheTrait>::moveRegularItemOnEviction(
1390
1321
// should be fine for it to be left in an inconsistent state.
1391
1322
config_.moveCb (oldItem, *newItemHdl, nullptr );
1392
1323
} else {
1393
- std::memcpy (newItemHdl->getWritableMemory (), oldItem.getMemory (),
1324
+ std::memcpy (newItemHdl->getMemory (), oldItem.getMemory (),
1394
1325
oldItem.getSize ());
1395
1326
}
1396
1327
@@ -3114,7 +3045,7 @@ void CacheAllocator<CacheTrait>::evictForSlabRelease(
3114
3045
}
3115
3046
3116
3047
template <typename CacheTrait>
3117
- typename CacheAllocator<CacheTrait>::ItemHandle
3048
+ typename CacheAllocator<CacheTrait>::WriteHandle
3118
3049
CacheAllocator<CacheTrait>::evictNormalItem(Item& item,
3119
3050
bool skipIfTokenInvalid) {
3120
3051
XDCHECK (item.isMoving ());
@@ -3134,7 +3065,7 @@ CacheAllocator<CacheTrait>::evictNormalItem(Item& item,
3134
3065
3135
3066
if (skipIfTokenInvalid && evictToNvmCache && !token.isValid ()) {
3136
3067
stats_.evictFailConcurrentFill .inc ();
3137
- return ItemHandle {};
3068
+ return WriteHandle {};
3138
3069
}
3139
3070
3140
3071
// We remove the item from both access and mm containers. It doesn't matter
@@ -3784,16 +3715,16 @@ GlobalCacheStats CacheAllocator<CacheTrait>::getGlobalCacheStats() const {
3784
3715
ret.numItems = accessContainer_->getStats ().numKeys ;
3785
3716
3786
3717
const uint64_t currTime = util::getCurrentTimeSec ();
3787
- ret.cacheInstanceUpTime = currTime - cacheInstanceCreationTime_ ;
3718
+ ret.cacheInstanceUpTime = currTime - cacheCreationTime_ ;
3788
3719
ret.ramUpTime = currTime - cacheCreationTime_;
3789
3720
ret.nvmCacheEnabled = nvmCache_ ? nvmCache_->isEnabled () : false ;
3790
3721
ret.nvmUpTime = currTime - getNVMCacheCreationTime ();
3791
3722
ret.reaperStats = getReaperStats ();
3792
3723
ret.numActiveHandles = getNumActiveHandles ();
3793
3724
3794
- ret.isNewRamCache = cacheCreationTime_ == cacheInstanceCreationTime_ ;
3725
+ ret.isNewRamCache = cacheCreationTime_ == cacheCreationTime_ ;
3795
3726
ret.isNewNvmCache =
3796
- nvmCacheState_.getCreationTime () == cacheInstanceCreationTime_ ;
3727
+ nvmCacheState_.value (). getCreationTime () == cacheCreationTime_ ;
3797
3728
3798
3729
return ret;
3799
3730
}
0 commit comments