@@ -37,11 +37,11 @@ CacheAllocator<CacheTrait>::CacheAllocator(Config config)
3737 accessContainer_(std::make_unique<AccessContainer>(
3838 config_.accessConfig,
3939 compressor_,
40- [this ](Item* it) -> ItemHandle { return acquire (it); })),
40+ [this ](Item* it) -> WriteHandle { return acquire (it); })),
4141 chainedItemAccessContainer_ (std::make_unique<AccessContainer>(
4242 config_.chainedItemAccessConfig,
4343 compressor_,
44- [this ](Item* it) -> ItemHandle { return acquire (it); })),
44+ [this ](Item* it) -> WriteHandle { return acquire (it); })),
4545 chainedItemLocks_ (config_.chainedItemsLockPower,
4646 std::make_shared<MurmurHash2>()),
4747 movesMap_(kShards ),
@@ -117,7 +117,7 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemNewT, Config config)
117117 false, config_.isUsingPosixShm()))
118118 .addr,
119119 compressor_,
120- [this](Item* it) -> ItemHandle { return acquire (it); })),
120+ [this](Item* it) -> WriteHandle { return acquire (it); })),
121121 chainedItemAccessContainer_(std::make_unique<AccessContainer>(
122122 config_.chainedItemAccessConfig,
123123 shmManager_
@@ -129,7 +129,7 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemNewT, Config config)
129129 false, config_.isUsingPosixShm()))
130130 .addr,
131131 compressor_,
132- [this](Item* it) -> ItemHandle { return acquire (it); })),
132+ [this](Item* it) -> WriteHandle { return acquire (it); })),
133133 chainedItemLocks_(config_.chainedItemsLockPower,
134134 std::make_shared<MurmurHash2>()),
135135 movesMap_(kShards ),
@@ -160,14 +160,14 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemAttachT, Config config)
160160 shmManager_->attachShm(detail::kShmHashTableName , nullptr ,
161161 ShmSegmentOpts (PageSizeT::NORMAL, false , config_.isUsingPosixShm())),
162162 compressor_,
163- [this](Item* it) -> ItemHandle { return acquire (it); })),
163+ [this](Item* it) -> WriteHandle { return acquire (it); })),
164164 chainedItemAccessContainer_(std::make_unique<AccessContainer>(
165165 deserializer_->deserialize<AccessSerializationType>(),
166166 config_.chainedItemAccessConfig,
167167 shmManager_->attachShm(detail::kShmChainedItemHashTableName , nullptr ,
168168 ShmSegmentOpts (PageSizeT::NORMAL, false , config_.isUsingPosixShm())),
169169 compressor_,
170- [this](Item* it) -> ItemHandle { return acquire (it); })),
170+ [this](Item* it) -> WriteHandle { return acquire (it); })),
171171 chainedItemLocks_(config_.chainedItemsLockPower,
172172 std::make_shared<MurmurHash2>()),
173173 movesMap_(kShards ),
@@ -187,53 +187,6 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemAttachT, Config config)
187187 PosixSysVSegmentOpts (config_.isUsingPosixShm ()));
188188}
189189
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-
237190template <typename CacheTrait>
238191CacheAllocator<CacheTrait>::~CacheAllocator () {
239192 XLOG (DBG, " destructing CacheAllocator" );
@@ -333,7 +286,8 @@ void CacheAllocator<CacheTrait>::initNvmCache(bool dramCacheAttached) {
333286 return ;
334287 }
335288
336- nvmCacheState_.emplace (NvmCacheState (config_.cacheDir , config_.isNvmCacheEncryptionEnabled (),
289+ nvmCacheState_.emplace (NvmCacheState (cacheCreationTime_, config_.cacheDir ,
290+ config_.isNvmCacheEncryptionEnabled (),
337291 config_.isNvmCacheTruncateAllocSizeEnabled ()));
338292
339293 // for some usecases that create pools, restoring nvmcache when dram cache
@@ -392,29 +346,6 @@ void CacheAllocator<CacheTrait>::initWorkers() {
392346 }
393347}
394348
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-
418349template <typename CacheTrait>
419350std::unique_ptr<typename CacheAllocator<CacheTrait>::AccessContainer>
420351CacheAllocator<CacheTrait>::initAccessContainer(InitMemType type,
@@ -475,7 +406,7 @@ CacheAllocator<CacheTrait>::allocate(PoolId poolId,
475406}
476407
477408template <typename CacheTrait>
478- typename CacheAllocator<CacheTrait>::ItemHandle
409+ typename CacheAllocator<CacheTrait>::WriteHandle
479410CacheAllocator<CacheTrait>::allocateInternalTier(TierId tid,
480411 PoolId pid,
481412 typename Item::Key key,
@@ -1314,9 +1245,9 @@ bool CacheAllocator<CacheTrait>::addWaitContextForMovingItem(
13141245}
13151246
13161247template <typename CacheTrait>
1317- typename CacheAllocator<CacheTrait>::ItemHandle
1248+ typename CacheAllocator<CacheTrait>::WriteHandle
13181249CacheAllocator<CacheTrait>::moveRegularItemOnEviction(
1319- Item& oldItem, ItemHandle & newItemHdl) {
1250+ Item& oldItem, WriteHandle & newItemHdl) {
13201251 XDCHECK (oldItem.isMoving ());
13211252 // TODO: should we introduce new latency tracker. E.g. evictRegularLatency_
13221253 // ??? util::LatencyTracker tracker{stats_.evictRegularLatency_};
@@ -1348,7 +1279,7 @@ CacheAllocator<CacheTrait>::moveRegularItemOnEviction(
13481279 ctx = res.first ->second .get ();
13491280 }
13501281
1351- auto resHdl = ItemHandle {};
1282+ auto resHdl = WriteHandle {};
13521283 auto guard = folly::makeGuard ([key, this , ctx, shard, &resHdl]() {
13531284 auto & movesMap = getMoveMapForShard (shard);
13541285 if (resHdl)
@@ -1390,7 +1321,7 @@ CacheAllocator<CacheTrait>::moveRegularItemOnEviction(
13901321 // should be fine for it to be left in an inconsistent state.
13911322 config_.moveCb (oldItem, *newItemHdl, nullptr );
13921323 } else {
1393- std::memcpy (newItemHdl->getWritableMemory (), oldItem.getMemory (),
1324+ std::memcpy (newItemHdl->getMemory (), oldItem.getMemory (),
13941325 oldItem.getSize ());
13951326 }
13961327
@@ -3114,7 +3045,7 @@ void CacheAllocator<CacheTrait>::evictForSlabRelease(
31143045}
31153046
31163047template <typename CacheTrait>
3117- typename CacheAllocator<CacheTrait>::ItemHandle
3048+ typename CacheAllocator<CacheTrait>::WriteHandle
31183049CacheAllocator<CacheTrait>::evictNormalItem(Item& item,
31193050 bool skipIfTokenInvalid) {
31203051 XDCHECK (item.isMoving ());
@@ -3134,7 +3065,7 @@ CacheAllocator<CacheTrait>::evictNormalItem(Item& item,
31343065
31353066 if (skipIfTokenInvalid && evictToNvmCache && !token.isValid ()) {
31363067 stats_.evictFailConcurrentFill .inc ();
3137- return ItemHandle {};
3068+ return WriteHandle {};
31383069 }
31393070
31403071 // We remove the item from both access and mm containers. It doesn't matter
@@ -3784,16 +3715,16 @@ GlobalCacheStats CacheAllocator<CacheTrait>::getGlobalCacheStats() const {
37843715 ret.numItems = accessContainer_->getStats ().numKeys ;
37853716
37863717 const uint64_t currTime = util::getCurrentTimeSec ();
3787- ret.cacheInstanceUpTime = currTime - cacheInstanceCreationTime_ ;
3718+ ret.cacheInstanceUpTime = currTime - cacheCreationTime_ ;
37883719 ret.ramUpTime = currTime - cacheCreationTime_;
37893720 ret.nvmCacheEnabled = nvmCache_ ? nvmCache_->isEnabled () : false ;
37903721 ret.nvmUpTime = currTime - getNVMCacheCreationTime ();
37913722 ret.reaperStats = getReaperStats ();
37923723 ret.numActiveHandles = getNumActiveHandles ();
37933724
3794- ret.isNewRamCache = cacheCreationTime_ == cacheInstanceCreationTime_ ;
3725+ ret.isNewRamCache = cacheCreationTime_ == cacheCreationTime_ ;
37953726 ret.isNewNvmCache =
3796- nvmCacheState_.getCreationTime () == cacheInstanceCreationTime_ ;
3727+ nvmCacheState_.value (). getCreationTime () == cacheCreationTime_ ;
37973728
37983729 return ret;
37993730}
0 commit comments