Skip to content

Commit cdf2522

Browse files
igchorvinser52
authored andcommitted
Initial multi-tier support implementation (rebased with NUMA and cs part 2)
fix for compressed ptr (upstream) -> compress from false to true
1 parent 36347e2 commit cdf2522

16 files changed

+513
-263
lines changed

cachelib/allocator/BackgroundMover-inl.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ template <typename CacheT>
4949
void BackgroundMover<CacheT>::setAssignedMemory(
5050
std::vector<MemoryDescriptorType>&& assignedMemory) {
5151
XLOG(INFO, "Class assigned to background worker:");
52-
for (auto [pid, cid] : assignedMemory) {
53-
XLOGF(INFO, "Pid: {}, Cid: {}", pid, cid);
52+
for (auto [tid, pid, cid] : assignedMemory) {
53+
XLOGF(INFO, "Tid: {}, Pid: {}, Cid: {}", tid, pid, cid);
5454
}
5555

5656
mutex_.lock_combine([this, &assignedMemory] {
@@ -68,18 +68,18 @@ void BackgroundMover<CacheT>::checkAndRun() {
6868
auto batches = strategy_->calculateBatchSizes(cache_, assignedMemory);
6969

7070
for (size_t i = 0; i < batches.size(); i++) {
71-
const auto [pid, cid] = assignedMemory[i];
71+
const auto [tid, pid, cid] = assignedMemory[i];
7272
const auto batch = batches[i];
7373

7474
if (batch == 0) {
7575
continue;
7676
}
77-
77+
const auto& mpStats = cache_.getPoolByTid(pid, tid).getStats();
7878
// try moving BATCH items from the class in order to reach free target
79-
auto moved = moverFunc(cache_, pid, cid, batch);
79+
auto moved = moverFunc(cache_, tid, pid, cid, batch);
8080
moves += moved;
81-
movesPerClass_[pid][cid] += moved;
82-
totalBytesMoved_.add(moved * cache_.getPool(pid).getAllocSizes()[cid]);
81+
moves_per_class_[tid][pid][cid] += moved;
82+
totalBytesMoved_.add(moved * mpStats.acStats.at(cid).allocSize );
8383
}
8484

8585
numTraversals_.inc();
@@ -97,19 +97,20 @@ BackgroundMoverStats BackgroundMover<CacheT>::getStats() const noexcept {
9797
}
9898

9999
template <typename CacheT>
100-
std::map<PoolId, std::map<ClassId, uint64_t>>
100+
std::map<TierId, std::map<PoolId, std::map<ClassId, uint64_t>>>
101101
BackgroundMover<CacheT>::getClassStats() const noexcept {
102-
return movesPerClass_;
102+
return moves_per_class_;
103103
}
104104

105105
template <typename CacheT>
106-
size_t BackgroundMover<CacheT>::workerId(PoolId pid,
106+
size_t BackgroundMover<CacheT>::workerId(TierId tid,
107+
PoolId pid,
107108
ClassId cid,
108109
size_t numWorkers) {
109110
XDCHECK(numWorkers);
110111

111112
// TODO: came up with some better sharding (use hashing?)
112-
return (pid + cid) % numWorkers;
113+
return (tid + pid + cid) % numWorkers;
113114
}
114115

115116
} // namespace cachelib

cachelib/allocator/BackgroundMover.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,19 @@ namespace cachelib {
2929
template <typename C>
3030
struct BackgroundMoverAPIWrapper {
3131
static size_t traverseAndEvictItems(C& cache,
32+
unsigned int tid,
3233
unsigned int pid,
3334
unsigned int cid,
3435
size_t batch) {
35-
return cache.traverseAndEvictItems(pid, cid, batch);
36+
return cache.traverseAndEvictItems(tid, pid, cid, batch);
3637
}
3738

3839
static size_t traverseAndPromoteItems(C& cache,
40+
unsigned int tid,
3941
unsigned int pid,
4042
unsigned int cid,
4143
size_t batch) {
42-
return cache.traverseAndPromoteItems(pid, cid, batch);
44+
return cache.traverseAndPromoteItems(tid, pid, cid, batch);
4345
}
4446
};
4547

@@ -62,24 +64,28 @@ class BackgroundMover : public PeriodicWorker {
6264
~BackgroundMover() override;
6365

6466
BackgroundMoverStats getStats() const noexcept;
65-
std::map<PoolId, std::map<ClassId, uint64_t>> getClassStats() const noexcept;
67+
std::map<TierId, std::map<PoolId, std::map<ClassId, uint64_t>>>
68+
getClassStats() const noexcept;
6669

6770
void setAssignedMemory(std::vector<MemoryDescriptorType>&& assignedMemory);
6871

6972
// return id of the worker responsible for promoting/evicting from particlar
7073
// pool and allocation calss (id is in range [0, numWorkers))
71-
static size_t workerId(PoolId pid, ClassId cid, size_t numWorkers);
74+
static size_t workerId(TierId tid, PoolId pid, ClassId cid, size_t numWorkers);
7275

7376
private:
74-
std::map<PoolId, std::map<ClassId, uint64_t>> movesPerClass_;
77+
std::map<TierId, std::map<PoolId, std::map<ClassId, uint64_t>>>
78+
moves_per_class_;
7579
// cache allocator's interface for evicting
7680
using Item = typename Cache::Item;
7781

7882
Cache& cache_;
7983
std::shared_ptr<BackgroundMoverStrategy> strategy_;
8084
MoverDir direction_;
8185

82-
std::function<size_t(Cache&, unsigned int, unsigned int, size_t)> moverFunc;
86+
std::function<size_t(
87+
Cache&, unsigned int, unsigned int, unsigned int, size_t)>
88+
moverFunc;
8389

8490
// implements the actual logic of running the background evictor
8591
void work() override final;

cachelib/allocator/BackgroundMoverStrategy.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ namespace facebook {
2222
namespace cachelib {
2323

2424
struct MemoryDescriptorType {
25-
MemoryDescriptorType(PoolId pid, ClassId cid) : pid_(pid), cid_(cid) {}
25+
MemoryDescriptorType(TierId tid, PoolId pid, ClassId cid) :
26+
tid_(tid), pid_(pid), cid_(cid) {}
27+
TierId tid_;
2628
PoolId pid_;
2729
ClassId cid_;
2830
};

cachelib/allocator/Cache.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ class CacheBase {
9696
// @param poolId The pool id to query
9797
virtual const MemoryPool& getPool(PoolId poolId) const = 0;
9898

99+
// Get the reference to a memory pool using a tier id, for stats purposes
100+
//
101+
// @param poolId The pool id to query
102+
// @param tierId The tier of the pool id
103+
virtual const MemoryPool& getPoolByTid(PoolId poolId, TierId tid) const = 0;
104+
99105
// Get Pool specific stats (regular pools). This includes stats from the
100106
// Memory Pool and also the cache.
101107
//
@@ -106,7 +112,7 @@ class CacheBase {
106112
//
107113
// @param poolId the pool id
108114
// @param classId the class id
109-
virtual ACStats getACStats(PoolId poolId, ClassId classId) const = 0;
115+
virtual ACStats getACStats(TierId tid,PoolId poolId, ClassId classId) const = 0;
110116

111117
// @param poolId the pool id
112118
virtual AllSlabReleaseEvents getAllSlabReleaseEvents(PoolId poolId) const = 0;

0 commit comments

Comments
 (0)