6161#include  " cachelib/allocator/PoolOptimizer.h" 
6262#include  " cachelib/allocator/PoolRebalancer.h" 
6363#include  " cachelib/allocator/PoolResizer.h" 
64+ #include  " cachelib/allocator/PrivateMemoryManager.h" 
6465#include  " cachelib/allocator/ReadOnlySharedCacheView.h" 
6566#include  " cachelib/allocator/Reaper.h" 
6667#include  " cachelib/allocator/RebalanceStrategy.h" 
@@ -2185,6 +2186,8 @@ class CacheAllocator : public CacheBase {
21852186                  std::chrono::seconds timeout = std::chrono::seconds{0 });
21862187
21872188  ShmSegmentOpts createShmCacheOpts (TierId tid);
2189+   PrivateSegmentOpts createPrivateSegmentOpts (TierId tid);
2190+   std::unique_ptr<MemoryAllocator> createPrivateAllocator (TierId tid);
21882191  std::unique_ptr<MemoryAllocator> createNewMemoryAllocator (TierId tid);
21892192  std::unique_ptr<MemoryAllocator> restoreMemoryAllocator (TierId tid);
21902193  std::unique_ptr<CCacheManager> restoreCCacheManager (TierId tid);
@@ -2234,7 +2237,7 @@ class CacheAllocator : public CacheBase {
22342237  //  @throw std::runtime_error if type is invalid
22352238  std::vector<std::unique_ptr<MemoryAllocator>> initAllocator (InitMemType type);
22362239
2237-   std::vector<std::unique_ptr<MemoryAllocator>> createPrivateAllocator ();
2240+   std::vector<std::unique_ptr<MemoryAllocator>> createPrivateAllocators ();
22382241  std::vector<std::unique_ptr<MemoryAllocator>> createAllocators ();
22392242  std::vector<std::unique_ptr<MemoryAllocator>> restoreAllocators ();
22402243
@@ -2400,6 +2403,8 @@ class CacheAllocator : public CacheBase {
24002403  //  is not persisted when cache process exits.
24012404  std::unique_ptr<TempShmMapping> tempShm_;
24022405
2406+   std::unique_ptr<PrivateMemoryManager> privMemManager_;
2407+ 
24032408  std::unique_ptr<ShmManager> shmManager_;
24042409
24052410  //  Deserialize data to restore cache allocator. Used only while attaching to
@@ -2612,6 +2617,9 @@ CacheAllocator<CacheTrait>::CacheAllocator(
26122617      tempShm_ (type == InitMemType::kNone  && isOnShm_
26132618                   ? std::make_unique<TempShmMapping>(config_.getCacheSize())
26142619                   : nullptr ),
2620+       privMemManager_ (type == InitMemType::kNone  && !isOnShm_
2621+                           ? std::make_unique<PrivateMemoryManager>()
2622+                           : nullptr ),
26152623      shmManager_ (type != InitMemType::kNone 
26162624                      ? std::make_unique<ShmManager>(config_.cacheDir,
26172625                                                     config_.isUsingPosixShm())
@@ -2674,6 +2682,16 @@ ShmSegmentOpts CacheAllocator<CacheTrait>::createShmCacheOpts(TierId tid) {
26742682  return  opts;
26752683}
26762684
2685+ template  <typename  CacheTrait>
2686+ PrivateSegmentOpts CacheAllocator<CacheTrait>::createPrivateSegmentOpts(TierId tid) {
2687+   PrivateSegmentOpts opts;
2688+   opts.alignment  = sizeof (Slab);
2689+   auto  memoryTierConfigs = config_.getMemoryTierConfigs ();
2690+   opts.memBindNumaNodes  = memoryTierConfigs[tid].getMemBind ();
2691+ 
2692+   return  opts;
2693+ }
2694+ 
26772695template  <typename  CacheTrait>
26782696size_t  CacheAllocator<CacheTrait>::memoryTierSize(TierId tid) const  {
26792697  auto  partitions = std::accumulate (config_.memoryTierConfigs .begin (), config_.memoryTierConfigs .end (), 0UL ,
@@ -2685,22 +2703,19 @@ size_t CacheAllocator<CacheTrait>::memoryTierSize(TierId tid) const {
26852703}
26862704
26872705template  <typename  CacheTrait>
2688- std::vector<std::unique_ptr<MemoryAllocator>>
2689- CacheAllocator<CacheTrait>::createPrivateAllocator() {
2690-   std::vector<std::unique_ptr<MemoryAllocator>> allocators;
2691- 
2706+ std::unique_ptr<MemoryAllocator>
2707+ CacheAllocator<CacheTrait>::createPrivateAllocator(TierId tid) {
26922708  if  (isOnShm_) {
2693-     allocators. emplace_back ( std::make_unique<MemoryAllocator>(
2709+     return   std::make_unique<MemoryAllocator>(
26942710                            getAllocatorConfig (config_),
26952711                            tempShm_->getAddr (),
2696-                             config_. getCacheSize () ));
2712+                             memoryTierSize (tid ));
26972713  } else  {
2698-     allocators. emplace_back ( std::make_unique<MemoryAllocator>(
2714+     return   std::make_unique<MemoryAllocator>(
26992715                            getAllocatorConfig (config_),
2700-                             config_.getCacheSize ()));
2716+                             privMemManager_->createMapping (config_.size , createPrivateSegmentOpts (tid)),
2717+                             memoryTierSize (tid));
27012718  }
2702- 
2703-   return  allocators;
27042719}
27052720
27062721template  <typename  CacheTrait>
@@ -2729,6 +2744,16 @@ CacheAllocator<CacheTrait>::restoreMemoryAllocator(TierId tid) {
27292744      config_.disableFullCoredump );
27302745}
27312746
2747+ template  <typename  CacheTrait>
2748+ std::vector<std::unique_ptr<MemoryAllocator>>
2749+ CacheAllocator<CacheTrait>::createPrivateAllocators() {
2750+   std::vector<std::unique_ptr<MemoryAllocator>> allocators;
2751+   for  (int  tid = 0 ; tid < getNumTiers (); tid++) {
2752+     allocators.emplace_back (createPrivateAllocator (tid));
2753+   }
2754+   return  allocators;
2755+ }
2756+ 
27322757template  <typename  CacheTrait>
27332758std::vector<std::unique_ptr<MemoryAllocator>>
27342759CacheAllocator<CacheTrait>::createAllocators() {
@@ -2862,7 +2887,7 @@ std::vector<std::unique_ptr<MemoryAllocator>>
28622887CacheAllocator<CacheTrait>::initAllocator(
28632888    InitMemType type) {
28642889  if  (type == InitMemType::kNone ) {
2865-     return  createPrivateAllocator ();
2890+     return  createPrivateAllocators ();
28662891  } else  if  (type == InitMemType::kMemNew ) {
28672892    return  createAllocators ();
28682893  } else  if  (type == InitMemType::kMemAttach ) {
0 commit comments