Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c0c90d2
Run centos and debian workflows on push and PR
igchor Nov 2, 2021
dbe3fda
Adds createPutToken and switches findEviction
byrnedj Feb 4, 2023
9afcd64
Add memory usage statistics for allocation classes
igchor Jul 6, 2022
eca7d8c
Initial multi-tier support implementation
igchor Sep 28, 2021
664da8d
AC stats multi-tier
byrnedj Jan 17, 2023
3b7bb0c
Tests and fix tier sizing
byrnedj Feb 8, 2023
58e825b
This is the additional multi-tier support needed
guptask Nov 14, 2022
9fc705f
Rolling average alloc latency
guptask Jul 21, 2022
ce0e38a
Rolling average class latency
guptask Jul 21, 2022
e0a8006
MM2Q promotion iterator
byrnedj Aug 9, 2022
bcb2ae2
Multi-tier allocator patch
byrnedj Feb 7, 2023
d4cf1d4
basic multi-tier test based on numa bindings
igchor Dec 30, 2021
6d2fbef
Aadding new configs to hit_ratio/graph_cache_leader_fobj
vinser52 Jan 27, 2022
5bfa1ff
Background data movement for the tiers
byrnedj Oct 21, 2022
1593291
dummy change to trigger container image rebuild
guptask Mar 28, 2023
a171f38
Updated the docker gcc version to 12 (#83)
guptask May 9, 2023
35a17e4
NUMA bindigs support for private memory (#82)
vinser52 May 17, 2023
46d168c
Do not run cachelib-centos-8-5 on PRs (#85)
igchor Jun 6, 2023
7d06531
Add option to insert items to first free tier (#87)
igchor Jun 8, 2023
1521efe
Chained item movement between tiers - sync on the parent item (#84)
byrnedj Jun 28, 2023
3328e4e
edit dockerfile
byrnedj Jul 24, 2023
3c87c49
Track latency of per item eviction/promotion between memory tiers
guptask Jul 28, 2023
795f85b
Update dependencies (#95)
igchor Aug 23, 2023
96d948f
enable DTO build without memcpy changes to cachebench
byrnedj Feb 28, 2024
47d5034
Bckground eviction for multi-tier
byrnedj Feb 28, 2024
efea480
no online eviction option patch
byrnedj Feb 28, 2024
ebfca17
fixes cmake in latest test removal (upstream test build fails - need …
byrnedj May 20, 2024
52618b5
fixes commit for now (should drop once https://github.com/facebook/Ca…
byrnedj May 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Initial multi-tier support implementation
Part 1.
-----------------------------------------
This includes the following:
 - Multi-tier allocator with TierId
 - allocateInternalTier
 - creating multi-tier allocator on shared memory

Other patches can be combined/merged with this patch (such as
multi-tier serialization support and improvements to eviction).
We will name those compatible with Part 1 in later patches.
  • Loading branch information
igchor authored and byrnedj committed May 20, 2024
commit eca7d8ce51e476c03d9be3cd6b0db68f5d18d480
39 changes: 23 additions & 16 deletions cachelib/allocator/BackgroundMover.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ namespace facebook::cachelib {
template <typename C>
struct BackgroundMoverAPIWrapper {
static size_t traverseAndEvictItems(C& cache,
unsigned int tid,
unsigned int pid,
unsigned int cid,
size_t batch) {
return cache.traverseAndEvictItems(pid, cid, batch);
return cache.traverseAndEvictItems(tid, pid, cid, batch);
}

static size_t traverseAndPromoteItems(C& cache,
unsigned int tid,
unsigned int pid,
unsigned int cid,
size_t batch) {
return cache.traverseAndPromoteItems(pid, cid, batch);
return cache.traverseAndPromoteItems(tid, pid, cid, batch);
}
};

Expand All @@ -60,24 +62,28 @@ class BackgroundMover : public PeriodicWorker {
~BackgroundMover() override;

BackgroundMoverStats getStats() const noexcept;
std::map<PoolId, std::map<ClassId, uint64_t>> getClassStats() const noexcept;
std::map<TierId, std::map<PoolId, std::map<ClassId, uint64_t>>>
getClassStats() const noexcept;

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

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

private:
std::map<PoolId, std::map<ClassId, uint64_t>> movesPerClass_;
std::map<TierId, std::map<PoolId, std::map<ClassId, uint64_t>>>
movesPerClass_;
// cache allocator's interface for evicting
using Item = typename Cache::Item;

Cache& cache_;
std::shared_ptr<BackgroundMoverStrategy> strategy_;
MoverDir direction_;

std::function<size_t(Cache&, unsigned int, unsigned int, size_t)> moverFunc;
std::function<size_t(
Cache&, unsigned int, unsigned int, unsigned int, size_t)>
moverFunc;

// implements the actual logic of running the background evictor
void work() override final;
Expand Down Expand Up @@ -123,8 +129,8 @@ template <typename CacheT>
void BackgroundMover<CacheT>::setAssignedMemory(
std::vector<MemoryDescriptorType>&& assignedMemory) {
XLOG(INFO, "Class assigned to background worker:");
for (auto [pid, cid] : assignedMemory) {
XLOGF(INFO, "Pid: {}, Cid: {}", pid, cid);
for (auto [tid, pid, cid] : assignedMemory) {
XLOGF(INFO, "Tid: {}, Pid: {}, Cid: {}", tid, pid, cid);
}

mutex_.lock_combine([this, &assignedMemory] {
Expand All @@ -142,18 +148,18 @@ void BackgroundMover<CacheT>::checkAndRun() {
auto batches = strategy_->calculateBatchSizes(cache_, assignedMemory);

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

if (batch == 0) {
continue;
}

const auto& mpStats = cache_.getPoolByTid(pid, tid).getStats();
// try moving BATCH items from the class in order to reach free target
auto moved = moverFunc(cache_, pid, cid, batch);
auto moved = moverFunc(cache_, tid, pid, cid, batch);
moves += moved;
movesPerClass_[pid][cid] += moved;
totalBytesMoved_.add(moved * cache_.getPool(pid).getAllocSizes()[cid]);
movesPerClass_[tid][pid][cid] += moved;
totalBytesMoved_.add(moved * mpStats.acStats.at(cid).allocSize );
}

numTraversals_.inc();
Expand All @@ -171,18 +177,19 @@ BackgroundMoverStats BackgroundMover<CacheT>::getStats() const noexcept {
}

template <typename CacheT>
std::map<PoolId, std::map<ClassId, uint64_t>>
std::map<TierId, std::map<PoolId, std::map<ClassId, uint64_t>>>
BackgroundMover<CacheT>::getClassStats() const noexcept {
return movesPerClass_;
}

template <typename CacheT>
size_t BackgroundMover<CacheT>::workerId(PoolId pid,
size_t BackgroundMover<CacheT>::workerId(TierId tid,
PoolId pid,
ClassId cid,
size_t numWorkers) {
XDCHECK(numWorkers);

// TODO: came up with some better sharding (use hashing?)
return (pid + cid) % numWorkers;
return (tid + pid + cid) % numWorkers;
}
} // namespace facebook::cachelib
4 changes: 3 additions & 1 deletion cachelib/allocator/BackgroundMoverStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ namespace facebook {
namespace cachelib {

struct MemoryDescriptorType {
MemoryDescriptorType(PoolId pid, ClassId cid) : pid_(pid), cid_(cid) {}
MemoryDescriptorType(TierId tid, PoolId pid, ClassId cid) :
tid_(tid), pid_(pid), cid_(cid) {}
TierId tid_;
PoolId pid_;
ClassId cid_;
};
Expand Down
8 changes: 7 additions & 1 deletion cachelib/allocator/Cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ class CacheBase {
// @param poolId The pool id to query
virtual const MemoryPool& getPool(PoolId poolId) const = 0;

// Get the reference to a memory pool using a tier id, for stats purposes
//
// @param poolId The pool id to query
// @param tierId The tier of the pool id
virtual const MemoryPool& getPoolByTid(PoolId poolId, TierId tid) const = 0;

// Get Pool specific stats (regular pools). This includes stats from the
// Memory Pool and also the cache.
//
Expand All @@ -106,7 +112,7 @@ class CacheBase {
//
// @param poolId the pool id
// @param classId the class id
virtual ACStats getACStats(PoolId poolId, ClassId classId) const = 0;
virtual ACStats getACStats(TierId tid,PoolId poolId, ClassId classId) const = 0;

// @param poolId the pool id
virtual AllSlabReleaseEvents getAllSlabReleaseEvents(PoolId poolId) const = 0;
Expand Down
Loading