61
61
#include " cachelib/allocator/PoolOptimizer.h"
62
62
#include " cachelib/allocator/PoolRebalancer.h"
63
63
#include " cachelib/allocator/PoolResizer.h"
64
+ #include " cachelib/allocator/PrivateMemoryManager.h"
64
65
#include " cachelib/allocator/ReadOnlySharedCacheView.h"
65
66
#include " cachelib/allocator/Reaper.h"
66
67
#include " cachelib/allocator/RebalanceStrategy.h"
@@ -2185,6 +2186,8 @@ class CacheAllocator : public CacheBase {
2185
2186
std::chrono::seconds timeout = std::chrono::seconds{0 });
2186
2187
2187
2188
ShmSegmentOpts createShmCacheOpts (TierId tid);
2189
+ PrivateSegmentOpts createPrivateSegmentOpts (TierId tid);
2190
+ std::unique_ptr<MemoryAllocator> createPrivateAllocator (TierId tid);
2188
2191
std::unique_ptr<MemoryAllocator> createNewMemoryAllocator (TierId tid);
2189
2192
std::unique_ptr<MemoryAllocator> restoreMemoryAllocator (TierId tid);
2190
2193
std::unique_ptr<CCacheManager> restoreCCacheManager (TierId tid);
@@ -2234,7 +2237,7 @@ class CacheAllocator : public CacheBase {
2234
2237
// @throw std::runtime_error if type is invalid
2235
2238
std::vector<std::unique_ptr<MemoryAllocator>> initAllocator (InitMemType type);
2236
2239
2237
- std::vector<std::unique_ptr<MemoryAllocator>> createPrivateAllocator ();
2240
+ std::vector<std::unique_ptr<MemoryAllocator>> createPrivateAllocators ();
2238
2241
std::vector<std::unique_ptr<MemoryAllocator>> createAllocators ();
2239
2242
std::vector<std::unique_ptr<MemoryAllocator>> restoreAllocators ();
2240
2243
@@ -2400,6 +2403,8 @@ class CacheAllocator : public CacheBase {
2400
2403
// is not persisted when cache process exits.
2401
2404
std::unique_ptr<TempShmMapping> tempShm_;
2402
2405
2406
+ std::unique_ptr<PrivateMemoryManager> privMemManager_;
2407
+
2403
2408
std::unique_ptr<ShmManager> shmManager_;
2404
2409
2405
2410
// Deserialize data to restore cache allocator. Used only while attaching to
@@ -2612,6 +2617,9 @@ CacheAllocator<CacheTrait>::CacheAllocator(
2612
2617
tempShm_ (type == InitMemType::kNone && isOnShm_
2613
2618
? std::make_unique<TempShmMapping>(config_.getCacheSize())
2614
2619
: nullptr ),
2620
+ privMemManager_ (type == InitMemType::kNone && !isOnShm_
2621
+ ? std::make_unique<PrivateMemoryManager>()
2622
+ : nullptr ),
2615
2623
shmManager_ (type != InitMemType::kNone
2616
2624
? std::make_unique<ShmManager>(config_.cacheDir,
2617
2625
config_.isUsingPosixShm())
@@ -2674,6 +2682,16 @@ ShmSegmentOpts CacheAllocator<CacheTrait>::createShmCacheOpts(TierId tid) {
2674
2682
return opts;
2675
2683
}
2676
2684
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
+
2677
2695
template <typename CacheTrait>
2678
2696
size_t CacheAllocator<CacheTrait>::memoryTierSize(TierId tid) const {
2679
2697
auto partitions = std::accumulate (config_.memoryTierConfigs .begin (), config_.memoryTierConfigs .end (), 0UL ,
@@ -2685,22 +2703,19 @@ size_t CacheAllocator<CacheTrait>::memoryTierSize(TierId tid) const {
2685
2703
}
2686
2704
2687
2705
template <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) {
2692
2708
if (isOnShm_) {
2693
- allocators. emplace_back ( std::make_unique<MemoryAllocator>(
2709
+ return std::make_unique<MemoryAllocator>(
2694
2710
getAllocatorConfig (config_),
2695
2711
tempShm_->getAddr (),
2696
- config_. getCacheSize () ));
2712
+ memoryTierSize (tid ));
2697
2713
} else {
2698
- allocators. emplace_back ( std::make_unique<MemoryAllocator>(
2714
+ return std::make_unique<MemoryAllocator>(
2699
2715
getAllocatorConfig (config_),
2700
- config_.getCacheSize ()));
2716
+ privMemManager_->createMapping (config_.size , createPrivateSegmentOpts (tid)),
2717
+ memoryTierSize (tid));
2701
2718
}
2702
-
2703
- return allocators;
2704
2719
}
2705
2720
2706
2721
template <typename CacheTrait>
@@ -2729,6 +2744,16 @@ CacheAllocator<CacheTrait>::restoreMemoryAllocator(TierId tid) {
2729
2744
config_.disableFullCoredump );
2730
2745
}
2731
2746
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
+
2732
2757
template <typename CacheTrait>
2733
2758
std::vector<std::unique_ptr<MemoryAllocator>>
2734
2759
CacheAllocator<CacheTrait>::createAllocators() {
@@ -2862,7 +2887,7 @@ std::vector<std::unique_ptr<MemoryAllocator>>
2862
2887
CacheAllocator<CacheTrait>::initAllocator(
2863
2888
InitMemType type) {
2864
2889
if (type == InitMemType::kNone ) {
2865
- return createPrivateAllocator ();
2890
+ return createPrivateAllocators ();
2866
2891
} else if (type == InitMemType::kMemNew ) {
2867
2892
return createAllocators ();
2868
2893
} else if (type == InitMemType::kMemAttach ) {
0 commit comments