@@ -68,7 +68,8 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemNewT, Config config)
6868                          AccessContainer::getRequiredSize (
6969                              config_.accessConfig.getNumBuckets()),
7070                          nullptr,
71-                           ShmSegmentOpts(config_.accessConfig.getPageSize()))
71+                           ShmSegmentOpts(config_.accessConfig.getPageSize(),
72+                               false, config_.usePosixShm))
7273              .addr,
7374          compressor_,
7475          [this](Item* it) -> ItemHandle { return  acquire (it); })),
@@ -79,7 +80,8 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemNewT, Config config)
7980                          AccessContainer::getRequiredSize (
8081                              config_.chainedItemAccessConfig.getNumBuckets()),
8182                          nullptr,
82-                           ShmSegmentOpts(config_.accessConfig.getPageSize()))
83+                           ShmSegmentOpts(config_.accessConfig.getPageSize(),
84+                               false, config_.usePosixShm))
8385              .addr,
8486          compressor_,
8587          [this](Item* it) -> ItemHandle { return  acquire (it); })),
@@ -89,7 +91,8 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemNewT, Config config)
8991      nvmCacheState_{config_.cacheDir , config_.isNvmCacheEncryptionEnabled (),
9092                     config_.isNvmCacheTruncateAllocSizeEnabled ()} {
9193  initCommon (false );
92-   shmManager_->removeShm (detail::kShmInfoName );
94+   shmManager_->removeShm (detail::kShmInfoName ,
95+     PosixSysVSegmentOpts (config_.usePosixShm ));
9396}
9497
9598template  <typename  CacheTrait>
@@ -107,13 +110,15 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemAttachT, Config config)
107110      accessContainer_(std::make_unique<AccessContainer>(
108111          deserializer_->deserialize<AccessSerializationType>(),
109112          config_.accessConfig,
110-           shmManager_->attachShm(detail::kShmHashTableName ),
113+           shmManager_->attachShm(detail::kShmHashTableName , nullptr ,
114+             ShmSegmentOpts (PageSizeT::NORMAL, false , config_.usePosixShm)),
111115          compressor_,
112116          [this](Item* it) -> ItemHandle { return  acquire (it); })),
113117      chainedItemAccessContainer_(std::make_unique<AccessContainer>(
114118          deserializer_->deserialize<AccessSerializationType>(),
115119          config_.chainedItemAccessConfig,
116-           shmManager_->attachShm (detail::kShmChainedItemHashTableName ),
120+           shmManager_->attachShm(detail::kShmChainedItemHashTableName , nullptr ,
121+             ShmSegmentOpts (PageSizeT::NORMAL, false , config_.usePosixShm)),
117122          compressor_,
118123          [this](Item* it) -> ItemHandle { return  acquire (it); })),
119124      chainedItemLocks_(config_.chainedItemsLockPower,
@@ -130,7 +135,8 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemAttachT, Config config)
130135  //  We will create a new info shm segment on shutDown(). If we don't remove
131136  //  this info shm segment here and the new info shm segment's size is larger
132137  //  than this one, creating new one will fail.
133-   shmManager_->removeShm (detail::kShmInfoName );
138+   shmManager_->removeShm (detail::kShmInfoName ,
139+     PosixSysVSegmentOpts (config_.usePosixShm ));
134140}
135141
136142template  <typename  CacheTrait>
@@ -148,6 +154,7 @@ std::unique_ptr<MemoryAllocator>
148154CacheAllocator<CacheTrait>::createNewMemoryAllocator() {
149155  ShmSegmentOpts opts;
150156  opts.alignment  = sizeof (Slab);
157+   opts.typeOpts  = PosixSysVSegmentOpts (config_.usePosixShm );
151158  return  std::make_unique<MemoryAllocator>(
152159      getAllocatorConfig (config_),
153160      shmManager_
@@ -162,6 +169,7 @@ std::unique_ptr<MemoryAllocator>
162169CacheAllocator<CacheTrait>::restoreMemoryAllocator() {
163170  ShmSegmentOpts opts;
164171  opts.alignment  = sizeof (Slab);
172+   opts.typeOpts  = PosixSysVSegmentOpts (config_.usePosixShm );
165173  return  std::make_unique<MemoryAllocator>(
166174      deserializer_->deserialize <MemoryAllocator::SerializationType>(),
167175      shmManager_
@@ -265,7 +273,8 @@ void CacheAllocator<CacheTrait>::initWorkers() {
265273
266274template  <typename  CacheTrait>
267275std::unique_ptr<Deserializer> CacheAllocator<CacheTrait>::createDeserializer() {
268-   auto  infoAddr = shmManager_->attachShm (detail::kShmInfoName );
276+   auto  infoAddr = shmManager_->attachShm (detail::kShmInfoName , nullptr ,
277+             ShmSegmentOpts (PageSizeT::NORMAL, false , config_.usePosixShm ));
269278  return  std::make_unique<Deserializer>(
270279      reinterpret_cast <uint8_t *>(infoAddr.addr ),
271280      reinterpret_cast <uint8_t *>(infoAddr.addr ) + infoAddr.size );
@@ -3041,8 +3050,11 @@ void CacheAllocator<CacheTrait>::saveRamCache() {
30413050  std::unique_ptr<folly::IOBuf> ioBuf = serializedBuf.move ();
30423051  ioBuf->coalesce ();
30433052
3044-   void * infoAddr =
3045-       shmManager_->createShm (detail::kShmInfoName , ioBuf->length ()).addr ;
3053+   ShmSegmentOpts opts;
3054+   opts.typeOpts  = PosixSysVSegmentOpts (config_.usePosixShm );
3055+ 
3056+   void * infoAddr = shmManager_->createShm (detail::kShmInfoName , ioBuf->length (),
3057+       nullptr , opts).addr ;
30463058  Serializer serializer (reinterpret_cast <uint8_t *>(infoAddr),
30473059                        reinterpret_cast <uint8_t *>(infoAddr) + ioBuf->length ());
30483060  serializer.writeToBuffer (std::move (ioBuf));
@@ -3386,7 +3398,7 @@ bool CacheAllocator<CacheTrait>::stopReaper(std::chrono::seconds timeout) {
33863398
33873399template  <typename  CacheTrait>
33883400bool  CacheAllocator<CacheTrait>::cleanupStrayShmSegments(
3389-      const  std::string& cacheDir, bool  posix) {
3401+   const  std::string& cacheDir, bool  posix  /* TODO(SHM_FILE): const std::vector<CacheMemoryTierConfig>& config  */ 
33903402  if  (util::getStatIfExists (cacheDir, nullptr ) && util::isDir (cacheDir)) {
33913403    try  {
33923404      //  cache dir exists. clean up only if there are no other processes
@@ -3405,6 +3417,12 @@ bool CacheAllocator<CacheTrait>::cleanupStrayShmSegments(
34053417    ShmManager::removeByName (cacheDir, detail::kShmHashTableName , posix);
34063418    ShmManager::removeByName (cacheDir, detail::kShmChainedItemHashTableName ,
34073419                             posix);
3420+ 
3421+     //  TODO(SHM_FILE): try to nuke segments of differente types (which require
3422+     //  extra info)
3423+     //  for (auto &tier : config) {
3424+     //    ShmManager::removeByName(cacheDir, tierShmName, config_.memoryTiers[i].opts);
3425+     //  }
34083426  }
34093427  return  true ;
34103428}
0 commit comments