Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion cachelib/allocator/BackgroundEvictor-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ BackgroundEvictionStats BackgroundEvictor<CacheT>::getStats() const noexcept {
evicStats.runCount = stats.numTraversals.get();
evicStats.evictionSize = stats.evictionSize.get();
evicStats.totalClasses = stats.totalClasses.get();

evicStats.strategyStats = strategy_->getStats();
return evicStats;
}

Expand Down
1 change: 1 addition & 0 deletions cachelib/allocator/BackgroundEvictor.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct BackgroundEvictorStats {

// item eviction size
AtomicCounter evictionSize{0};

};

// Periodic worker that evicts items from tiers in batches
Expand Down
1 change: 1 addition & 0 deletions cachelib/allocator/BackgroundEvictorStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class BackgroundEvictorStrategy {
public:
virtual std::vector<size_t> calculateBatchSizes(const CacheBase& cache,
std::vector<std::tuple<TierId, PoolId, ClassId>> acVec) = 0;
virtual BackgroundStrategyStats getStats() = 0;
};

} // namespace cachelib
Expand Down
20 changes: 20 additions & 0 deletions cachelib/allocator/CacheStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "cachelib/common/RollingStats.h"
#include "cachelib/common/Time.h"

//#include "cachelib/allocator/BackgroundEvictorStrategy.h"

namespace facebook {
namespace cachelib {

Expand Down Expand Up @@ -300,6 +302,21 @@ struct ReaperStats {
uint64_t avgTraversalTimeMs{0};
};

struct BackgroundStrategyStats {

std::map<uint32_t,double> highEvictionAcWatermarks;

BackgroundStrategyStats& operator+=(const BackgroundStrategyStats& rhs){
for (const auto entry : rhs.highEvictionAcWatermarks) {
auto cid = entry.first;
auto count = entry.second;
highEvictionAcWatermarks[cid] = count;
}
return *this;
}

};

// Eviction Stats
struct BackgroundEvictionStats {
// the number of items this worker evicted by looking at pools/classes stats
Expand All @@ -314,11 +331,14 @@ struct BackgroundEvictionStats {
// eviction size
uint64_t evictionSize{0};

BackgroundStrategyStats strategyStats;

BackgroundEvictionStats& operator+=(const BackgroundEvictionStats& rhs) {
numEvictedItems += rhs.numEvictedItems;
runCount += rhs.runCount;
totalClasses += rhs.totalClasses;
evictionSize += rhs.evictionSize;
strategyStats += rhs.strategyStats;
return *this;
}
};
Expand Down
14 changes: 14 additions & 0 deletions cachelib/allocator/DynamicFreeThresholdStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,19 @@ void DynamicFreeThresholdStrategy::calculateBenefitMig(uint64_t acLatency, unsig
std::get<0>(acBenefits[tid][pid][cid]) = 1 / acLatency;
}

BackgroundStrategyStats DynamicFreeThresholdStrategy::getStats() {
BackgroundStrategyStats s;

auto numClasses = MemoryAllocator::kMaxClasses;
for (int i = 0; i < 1; i++) {
for (int j = 0; j < 1; j++) {
for (int k = 0; k < numClasses; k++) {
s.highEvictionAcWatermarks[k] = std::get<0>( highEvictionAcWatermarks[i][j][k] );
}
}
}
return s;
}

} // namespace cachelib
} // namespace facebook
7 changes: 2 additions & 5 deletions cachelib/allocator/DynamicFreeThresholdStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@ class DynamicFreeThresholdStrategy : public BackgroundEvictorStrategy {
~DynamicFreeThresholdStrategy() {}

std::vector<size_t> calculateBatchSizes(const CacheBase& cache, std::vector<std::tuple<TierId, PoolId, ClassId>> acVec);
//unsigned int tid,
//PoolId pid,
//ClassId cid,
//size_t allocSize,
//size_t acMemorySize);

BackgroundStrategyStats getStats();

private:
double lowEvictionAcWatermark{2.0}; //this threshold is used outside this class and is not adjusted currently
Expand Down
5 changes: 5 additions & 0 deletions cachelib/allocator/FreeThresholdStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,10 @@ std::vector<size_t> FreeThresholdStrategy::calculateBatchSizes(
return batches;
}

BackgroundStrategyStats FreeThresholdStrategy::getStats() {
BackgroundStrategyStats s;
return s;
}

} // namespace cachelib
} // namespace facebook
2 changes: 2 additions & 0 deletions cachelib/allocator/FreeThresholdStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class FreeThresholdStrategy : public BackgroundEvictorStrategy {

std::vector<size_t> calculateBatchSizes(const CacheBase& cache,
std::vector<std::tuple<TierId, PoolId, ClassId>> acVecs);

BackgroundStrategyStats getStats();
private:
double lowEvictionAcWatermark{2.0};
double highEvictionAcWatermark{5.0};
Expand Down
5 changes: 5 additions & 0 deletions cachelib/allocator/PromotionStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ class PromotionStrategy : public BackgroundEvictorStrategy {

return batches;
}

BackgroundStrategyStats getStats() {
BackgroundStrategyStats s;
return s;
}
private:
double promotionAcWatermark{4.0};
uint64_t maxPromotionBatch{40};
Expand Down
1 change: 1 addition & 0 deletions cachelib/cachebench/cache/Cache-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ Stats Cache<Allocator>::getStats() const {
ret.nvmCounters = cache_->getNvmCacheStatsMap();
}

ret.acHighWatermarks = cacheStats.evictionStats.strategyStats.highEvictionAcWatermarks;
ret.backgroundEvictionClasses = cache_->getBackgroundEvictorClassStats();
ret.backgroundPromotionClasses = cache_->getBackgroundPromoterClassStats();

Expand Down
13 changes: 11 additions & 2 deletions cachelib/cachebench/cache/CacheStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ struct Stats {
std::map<uint32_t, uint64_t> backgroundEvictionClasses;
std::map<uint32_t, uint64_t> backgroundPromotionClasses;

std::map<uint32_t, double> acHighWatermarks;

// errors from the nvm engine.
std::unordered_map<std::string, double> nvmErrors;

Expand Down Expand Up @@ -190,13 +192,13 @@ struct Stats {

foreachAC([&](auto tid, auto pid, auto cid, auto stats){
auto [allocSizeSuffix, allocSize] = formatMemory(stats.allocSize);
out << folly::sformat("tid{:2} pid{:2} cid{:4} {:8.2f}{} free: {:4.2f}%",
out << folly::sformat("tid{:2} pid{:2} cid{:4} {:8}{} free: {:4.2f}%",
tid, pid, cid, allocSize, allocSizeSuffix, stats.approxFreePercent) << std::endl;
});

foreachAC([&](auto tid, auto pid, auto cid, auto stats){
auto [allocSizeSuffix, allocSize] = formatMemory(stats.allocSize);
out << folly::sformat("tid{:2} pid{:2} cid{:4} {:8.2f}{} latency: {:8.2f}%",
out << folly::sformat("tid{:2} pid{:2} cid{:4} {:8}{} latency: {:8}",
tid, pid, cid, allocSize, allocSizeSuffix, stats.allocLatencyNs.estimate()) << std::endl;
});
}
Expand Down Expand Up @@ -380,6 +382,13 @@ struct Stats {
}
}

if (!acHighWatermarks.empty() && backgndEvicStats.nEvictedItems > 0 ) {
out << "== Class High Threshold ==" << std::endl;
for (const auto& it : acHighWatermarks) {
out << it.first << " : " << it.second << std::endl;
}
}

if (!backgroundPromotionClasses.empty() && backgndPromoStats.nPromotedItems > 0) {
out << "== Class Background Promotion Counters Map ==" << std::endl;
for (const auto& it : backgroundPromotionClasses) {
Expand Down