Skip to content

Commit

Permalink
refactored background batch eviction and added DSA support
Browse files Browse the repository at this point in the history
  • Loading branch information
guptask committed Oct 4, 2023
1 parent 2041678 commit 93d507a
Show file tree
Hide file tree
Showing 17 changed files with 472 additions and 25 deletions.
7 changes: 4 additions & 3 deletions cachelib/allocator/BackgroundMover-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ template <typename CacheT>
BackgroundMover<CacheT>::BackgroundMover(
Cache& cache,
std::shared_ptr<BackgroundMoverStrategy> strategy,
MoverDir direction)
: cache_(cache), strategy_(strategy), direction_(direction) {
MoverDir direction,
bool dsaEnabled)
: cache_(cache), strategy_(strategy), direction_(direction), dsaEnabled_(dsaEnabled) {
if (direction_ == MoverDir::Evict) {
moverFunc = BackgroundMoverAPIWrapper<CacheT>::traverseAndEvictItems;
} else if (direction_ == MoverDir::Promote) {
Expand Down Expand Up @@ -93,7 +94,7 @@ void BackgroundMover<CacheT>::checkAndRun() {
}

// try moving BATCH items from the class in order to reach free target
auto moved = moverFunc(cache_, tid, pid, cid, batch);
auto moved = moverFunc(cache_, tid, pid, cid, batch, dsaEnabled_);
moves += moved;
moves_per_class_[assignedMemory[i]] += moved;
}
Expand Down
16 changes: 10 additions & 6 deletions cachelib/allocator/BackgroundMover.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ struct BackgroundMoverAPIWrapper {
unsigned int tid,
unsigned int pid,
unsigned int cid,
size_t batch) {
return cache.traverseAndEvictItems(tid, pid, cid, batch);
size_t batch,
bool dsaEnabled) {
return cache.traverseAndEvictItems(tid, pid, cid, batch, dsaEnabled);
}

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

Expand All @@ -61,7 +63,8 @@ class BackgroundMover : public PeriodicWorker {
// (promoted vs. evicted and how much)
BackgroundMover(Cache& cache,
std::shared_ptr<BackgroundMoverStrategy> strategy,
MoverDir direction_);
MoverDir direction,
bool dsaEnabled = false);

~BackgroundMover() override;

Expand Down Expand Up @@ -101,9 +104,10 @@ class BackgroundMover : public PeriodicWorker {
Cache& cache_;
std::shared_ptr<BackgroundMoverStrategy> strategy_;
MoverDir direction_;
bool dsaEnabled_{false};

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

// implements the actual logic of running the background evictor
Expand Down
2 changes: 2 additions & 0 deletions cachelib/allocator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ target_link_libraries(cachelib_allocator PUBLIC
cachelib_navy
cachelib_common
cachelib_shm
dml
dl
)

if ((CMAKE_SYSTEM_NAME STREQUAL Linux) AND
Expand Down
11 changes: 11 additions & 0 deletions cachelib/allocator/Cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,21 @@ void CacheBase::updateGlobalCacheStats(const std::string& statPrefix) const {

visitEstimates(uploadStatsNanoToMicro, stats.allocateLatencyNs,
statPrefix + "allocate.latency_us");

visitEstimates(uploadStatsNanoToMicro, stats.bgEvictLatencyNs,
statPrefix + "background.eviction.latency_us");
visitEstimates(uploadStatsNanoToMicro, stats.evictDmlLargeItemWaitLatencyNs,
statPrefix + "background.eviction.dml.large_item_wait.latency_us");
visitEstimates(uploadStatsNanoToMicro, stats.evictDmlSmallItemWaitLatencyNs,
statPrefix + "background.eviction.dml.small_item_wait.latency_us");

visitEstimates(uploadStatsNanoToMicro, stats.bgPromoteLatencyNs,
statPrefix + "background.promotion.latency_us");
visitEstimates(uploadStatsNanoToMicro, stats.promoteDmlLargeItemWaitLatencyNs,
statPrefix + "background.promotion.dml.large_item_wait.latency_us");
visitEstimates(uploadStatsNanoToMicro, stats.promoteDmlSmallItemWaitLatencyNs,
statPrefix + "background.promotion.dml.small_item_wait.latency_us");

visitEstimates(uploadStatsNanoToMicro, stats.moveChainedLatencyNs,
statPrefix + "move.chained.latency_us");
visitEstimates(uploadStatsNanoToMicro, stats.moveRegularLatencyNs,
Expand Down
Loading

0 comments on commit 93d507a

Please sign in to comment.