@@ -65,7 +65,8 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemNewT, Config config)
6565 AccessContainer::getRequiredSize (
6666 config_.accessConfig.getNumBuckets()),
6767 nullptr,
68- ShmSegmentOpts(config_.accessConfig.getPageSize()))
68+ ShmSegmentOpts(config_.accessConfig.getPageSize(),
69+ false, config_.usePosixShm))
6970 .addr,
7071 compressor_,
7172 [this](Item* it) -> ItemHandle { return acquire (it); })),
@@ -76,7 +77,8 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemNewT, Config config)
7677 AccessContainer::getRequiredSize (
7778 config_.chainedItemAccessConfig.getNumBuckets()),
7879 nullptr,
79- ShmSegmentOpts(config_.accessConfig.getPageSize()))
80+ ShmSegmentOpts(config_.accessConfig.getPageSize(),
81+ false, config_.usePosixShm))
8082 .addr,
8183 compressor_,
8284 [this](Item* it) -> ItemHandle { return acquire (it); })),
@@ -86,7 +88,8 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemNewT, Config config)
8688 nvmCacheState_{config_.cacheDir , config_.isNvmCacheEncryptionEnabled (),
8789 config_.isNvmCacheTruncateAllocSizeEnabled ()} {
8890 initCommon (false );
89- shmManager_->removeShm (detail::kShmInfoName );
91+ shmManager_->removeShm (detail::kShmInfoName ,
92+ PosixSysVSegmentOpts (config_.usePosixShm ));
9093}
9194
9295template <typename CacheTrait>
@@ -104,13 +107,15 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemAttachT, Config config)
104107 accessContainer_(std::make_unique<AccessContainer>(
105108 deserializer_->deserialize<AccessSerializationType>(),
106109 config_.accessConfig,
107- shmManager_->attachShm(detail::kShmHashTableName ),
110+ shmManager_->attachShm(detail::kShmHashTableName , nullptr ,
111+ ShmSegmentOpts (PageSizeT::NORMAL, false , config_.usePosixShm)),
108112 compressor_,
109113 [this](Item* it) -> ItemHandle { return acquire (it); })),
110114 chainedItemAccessContainer_(std::make_unique<AccessContainer>(
111115 deserializer_->deserialize<AccessSerializationType>(),
112116 config_.chainedItemAccessConfig,
113- shmManager_->attachShm (detail::kShmChainedItemHashTableName ),
117+ shmManager_->attachShm(detail::kShmChainedItemHashTableName , nullptr ,
118+ ShmSegmentOpts (PageSizeT::NORMAL, false , config_.usePosixShm)),
114119 compressor_,
115120 [this](Item* it) -> ItemHandle { return acquire (it); })),
116121 chainedItemLocks_(config_.chainedItemsLockPower,
@@ -127,7 +132,8 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemAttachT, Config config)
127132 // We will create a new info shm segment on shutDown(). If we don't remove
128133 // this info shm segment here and the new info shm segment's size is larger
129134 // than this one, creating new one will fail.
130- shmManager_->removeShm (detail::kShmInfoName );
135+ shmManager_->removeShm (detail::kShmInfoName ,
136+ PosixSysVSegmentOpts (config_.usePosixShm ));
131137}
132138
133139template <typename CacheTrait>
@@ -145,6 +151,7 @@ std::unique_ptr<MemoryAllocator>
145151CacheAllocator<CacheTrait>::createNewMemoryAllocator() {
146152 ShmSegmentOpts opts;
147153 opts.alignment = sizeof (Slab);
154+ opts.typeOpts = PosixSysVSegmentOpts (config_.usePosixShm );
148155 return std::make_unique<MemoryAllocator>(
149156 getAllocatorConfig (config_),
150157 shmManager_
@@ -159,6 +166,7 @@ std::unique_ptr<MemoryAllocator>
159166CacheAllocator<CacheTrait>::restoreMemoryAllocator() {
160167 ShmSegmentOpts opts;
161168 opts.alignment = sizeof (Slab);
169+ opts.typeOpts = PosixSysVSegmentOpts (config_.usePosixShm );
162170 return std::make_unique<MemoryAllocator>(
163171 deserializer_->deserialize <MemoryAllocator::SerializationType>(),
164172 shmManager_
@@ -263,7 +271,8 @@ void CacheAllocator<CacheTrait>::initWorkers() {
263271
264272template <typename CacheTrait>
265273std::unique_ptr<Deserializer> CacheAllocator<CacheTrait>::createDeserializer() {
266- auto infoAddr = shmManager_->attachShm (detail::kShmInfoName );
274+ auto infoAddr = shmManager_->attachShm (detail::kShmInfoName , nullptr ,
275+ ShmSegmentOpts (PageSizeT::NORMAL, false , config_.usePosixShm ));
267276 return std::make_unique<Deserializer>(
268277 reinterpret_cast <uint8_t *>(infoAddr.addr ),
269278 reinterpret_cast <uint8_t *>(infoAddr.addr ) + infoAddr.size );
@@ -3097,8 +3106,11 @@ void CacheAllocator<CacheTrait>::saveRamCache() {
30973106 std::unique_ptr<folly::IOBuf> ioBuf = serializedBuf.move ();
30983107 ioBuf->coalesce ();
30993108
3100- void * infoAddr =
3101- shmManager_->createShm (detail::kShmInfoName , ioBuf->length ()).addr ;
3109+ ShmSegmentOpts opts;
3110+ opts.typeOpts = PosixSysVSegmentOpts (config_.usePosixShm );
3111+
3112+ void * infoAddr = shmManager_->createShm (detail::kShmInfoName , ioBuf->length (),
3113+ nullptr , opts).addr ;
31023114 Serializer serializer (reinterpret_cast <uint8_t *>(infoAddr),
31033115 reinterpret_cast <uint8_t *>(infoAddr) + ioBuf->length ());
31043116 serializer.writeToBuffer (std::move (ioBuf));
@@ -3444,7 +3456,7 @@ bool CacheAllocator<CacheTrait>::stopReaper(std::chrono::seconds timeout) {
34443456
34453457template <typename CacheTrait>
34463458bool CacheAllocator<CacheTrait>::cleanupStrayShmSegments(
3447- const std::string& cacheDir, bool posix) {
3459+ const std::string& cacheDir, bool posix /* TODO(SHM_FILE): const std::vector<CacheMemoryTierConfig>& config */ ) {
34483460 if (util::getStatIfExists (cacheDir, nullptr ) && util::isDir (cacheDir)) {
34493461 try {
34503462 // cache dir exists. clean up only if there are no other processes
@@ -3463,6 +3475,12 @@ bool CacheAllocator<CacheTrait>::cleanupStrayShmSegments(
34633475 ShmManager::removeByName (cacheDir, detail::kShmHashTableName , posix);
34643476 ShmManager::removeByName (cacheDir, detail::kShmChainedItemHashTableName ,
34653477 posix);
3478+
3479+ // TODO(SHM_FILE): try to nuke segments of differente types (which require
3480+ // extra info)
3481+ // for (auto &tier : config) {
3482+ // ShmManager::removeByName(cacheDir, tierShmName, config_.memoryTiers[i].opts);
3483+ // }
34663484 }
34673485 return true ;
34683486}
0 commit comments