Skip to content

Commit 0843c6f

Browse files
committed
updates
2 parents daf1793 + 6006cc8 commit 0843c6f

File tree

6 files changed

+64
-2
lines changed

6 files changed

+64
-2
lines changed

cachelib/allocator/BackgroundEvictor-inl.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,32 @@ void BackgroundEvictor<CacheT>::work() {
6363
template <typename CacheT>
6464
void BackgroundEvictor<CacheT>::checkAndRun(PoolId pid) {
6565
const auto& mpStats = cache_.getPoolByTid(pid,tid_).getStats();
66+
unsigned int evictions = 0;
67+
unsigned int classes = 0;
6668
for (auto& cid : mpStats.classIds) {
69+
classes++;
6770
auto batch = strategy_->calculateBatchSize(cache_,tid_,pid,cid);
68-
if (!batch)
71+
if (!batch) {
6972
continue;
73+
}
7074

7175
stats.evictionSize.add(batch);
7276
//try evicting BATCH items from the class in order to reach free target
7377
auto evicted =
7478
BackgroundEvictorAPIWrapper<CacheT>::traverseAndEvictItems(cache_,
7579
tid_,pid,cid,batch);
76-
stats.numEvictedItems.add(evicted);
80+
81+
evictions += evicted;
82+
const size_t cid_id = (size_t)mpStats.acStats.at(cid).allocSize;
83+
auto it = evictions_per_class_.find(cid_id);
84+
if (it != evictions_per_class_.end()) {
85+
it->second += evicted;
86+
} else {
87+
evictions_per_class_[cid_id] = 0;
88+
}
7789
}
90+
stats.numEvictedItems.add(evictions);
91+
stats.numClasses.add(classes);
7892
stats.numTraversals.inc();
7993
}
8094

@@ -84,10 +98,16 @@ BackgroundEvictionStats BackgroundEvictor<CacheT>::getStats() const noexcept {
8498
evicStats.numEvictedItems = stats.numEvictedItems.get();
8599
evicStats.numEvictedItemsFromSchedule = stats.numEvictedItemsFromSchedule.get();
86100
evicStats.numTraversals = stats.numTraversals.get();
101+
evicStats.numClasses = stats.numClasses.get();
87102
evicStats.evictionSize = stats.evictionSize.get();
88103

89104
return evicStats;
90105
}
91106

107+
template <typename CacheT>
108+
std::map<uint32_t,uint64_t> BackgroundEvictor<CacheT>::getClassStats() const noexcept {
109+
return evictions_per_class_;
110+
}
111+
92112
} // namespace cachelib
93113
} // namespace facebook

cachelib/allocator/BackgroundEvictor.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ struct BackgroundEvictorStats {
4949
// traversals
5050
AtomicCounter numTraversals{0};
5151

52+
// total number of classes
53+
AtomicCounter numClasses{0};
54+
5255
// item eviction size
5356
AtomicCounter evictionSize{0};
5457
};
@@ -76,6 +79,8 @@ class BackgroundEvictor : public PeriodicWorker {
7679

7780
BackgroundEvictionStats getStats() const noexcept;
7881

82+
std::map<uint32_t,uint64_t> getClassStats() const noexcept;
83+
7984
private:
8085
// cache allocator's interface for evicting
8186

@@ -91,6 +96,8 @@ class BackgroundEvictor : public PeriodicWorker {
9196
void checkAndRun(PoolId pid);
9297

9398
BackgroundEvictorStats stats;
99+
100+
std::map<uint32_t,uint64_t> evictions_per_class_;
94101
};
95102
} // namespace cachelib
96103
} // namespace facebook

cachelib/allocator/CacheAllocator.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,11 @@ class CacheAllocator : public CacheBase {
10481048
auto stats = backgroundEvictor_ ? backgroundEvictor_->getStats() : BackgroundEvictionStats{};
10491049
return stats;
10501050
}
1051+
1052+
std::map<uint32_t,uint64_t> getBackgroundEvictorClassStats() const {
1053+
auto stats = backgroundEvictor_ ? backgroundEvictor_->getClassStats() : std::map<uint32_t,uint64_t>();
1054+
return stats;
1055+
}
10511056

10521057
// return the LruType of an item
10531058
typename MMType::LruType getItemLruType(const Item& item) const;

cachelib/allocator/CacheStats.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ struct BackgroundEvictionStats {
296296
// number of times we went executed the thread //TODO: is this def correct?
297297
uint64_t numTraversals{0};
298298

299+
// total number of classes
300+
uint64_t numClasses{0};
301+
299302
// eviction size
300303
uint64_t evictionSize{0};
301304
};

cachelib/cachebench/cache/Cache-inl.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ Cache<Allocator>::Cache(const CacheConfig& config,
5959
allocatorConfig_.enablePoolRebalancing(
6060
config_.getRebalanceStrategy(),
6161
std::chrono::seconds(config_.poolRebalanceIntervalSec));
62+
63+
//for another day
64+
//allocatorConfig_.enablePoolOptimizer(
65+
// config_.getPoolOptimizerStrategy(),
66+
// std::chrono::seconds(config_.poolOptimizerIntervalSec));
6267

6368
allocatorConfig_.enableBackgroundEvictor(
6469
config_.getBackgroundEvictorStrategy(),
@@ -539,6 +544,12 @@ Stats Cache<Allocator>::getStats() const {
539544
ret.numCacheGets = cacheStats.numCacheGets;
540545
ret.numCacheGetMiss = cacheStats.numCacheGetMiss;
541546
ret.numRamDestructorCalls = cacheStats.numRamDestructorCalls;
547+
548+
ret.numBackgroundEvictions = cacheStats.backgroundEvictorStats.numEvictedItems;
549+
ret.numBackgroundEvictionsFromSchedule = cacheStats.backgroundEvictorStats.numEvictedItemsFromSchedule;
550+
ret.numBackgroundEvictorRuns = cacheStats.backgroundEvictorStats.numTraversals;
551+
ret.numClasses = cacheStats.backgroundEvictorStats.numClasses;
552+
542553
ret.numNvmGets = cacheStats.numNvmGets;
543554
ret.numNvmGetMiss = cacheStats.numNvmGetMiss;
544555
ret.numNvmGetCoalesced = cacheStats.numNvmGetCoalesced;
@@ -581,6 +592,8 @@ Stats Cache<Allocator>::getStats() const {
581592
ret.nvmCounters = cache_->getNvmCacheStatsMap();
582593
}
583594

595+
ret.backgroundEvictionClasses = cache_->getBackgroundEvictorClassStats();
596+
584597
// nvm stats from navy
585598
if (!isRamOnly() && !navyStats.empty()) {
586599
auto lookup = [&navyStats](const std::string& key) {

cachelib/cachebench/cache/CacheStats.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ struct BackgroundEvictionStats {
3636
// number of times we went executed the thread //TODO: is this def correct?
3737
uint64_t nTraversals{0};
3838

39+
// number of classes searched
40+
uint64_t nClasses{0};
41+
3942
// size of evicted items
4043
uint64_t evictionSize;
4144
};
@@ -116,6 +119,8 @@ struct Stats {
116119
// what to populate since not all of those are interesting when running
117120
// cachebench.
118121
std::unordered_map<std::string, double> nvmCounters;
122+
123+
std::map<uint32_t, uint64_t> backgroundEvictionClasses;
119124

120125
// errors from the nvm engine.
121126
std::unordered_map<std::string, double> nvmErrors;
@@ -138,6 +143,8 @@ struct Stats {
138143
backgndEvicStats.nEvictedItemsFromSchedule) << std::endl;
139144
out << folly::sformat("Tier 0 Background Traversals : {:,}",
140145
backgndEvicStats.nTraversals) << std::endl;
146+
out << folly::sformat("Tier 0 Classes searched : {:,}",
147+
backgndEvicStats.nClasses) << std::endl;
141148
out << folly::sformat("Tier 0 Background Evicted Size : {:,}",
142149
backgndEvicStats.evictionSize) << std::endl;
143150

@@ -298,6 +305,13 @@ struct Stats {
298305
out << it.first << " : " << it.second << std::endl;
299306
}
300307
}
308+
309+
if (!backgroundEvictionClasses.empty()) {
310+
out << "== Class Background Eviction Counters Map ==" << std::endl;
311+
for (const auto& it : backgroundEvictionClasses) {
312+
out << it.first << " : " << it.second << std::endl;
313+
}
314+
}
301315

302316
if (numRamDestructorCalls > 0 || numNvmDestructorCalls > 0) {
303317
out << folly::sformat("Destructor executed from RAM {}, from NVM {}",

0 commit comments

Comments
 (0)