Skip to content

Commit 3cc41bd

Browse files
committed
AC stats multi-tier
1 parent 2529f0a commit 3cc41bd

File tree

7 files changed

+22
-18
lines changed

7 files changed

+22
-18
lines changed

cachelib/allocator/Cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class CacheBase {
106106
//
107107
// @param poolId the pool id
108108
// @param classId the class id
109-
virtual ACStats getACStats(PoolId poolId, ClassId classId) const = 0;
109+
virtual ACStats getACStats(TierId tid, PoolId poolId, ClassId classId) const = 0;
110110

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

cachelib/allocator/CacheAllocator-inl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,9 +2442,10 @@ PoolStats CacheAllocator<CacheTrait>::getPoolStats(PoolId poolId) const {
24422442
}
24432443

24442444
template <typename CacheTrait>
2445-
ACStats CacheAllocator<CacheTrait>::getACStats(PoolId poolId,
2445+
ACStats CacheAllocator<CacheTrait>::getACStats(TierId tid,
2446+
PoolId poolId,
24462447
ClassId classId) const {
2447-
const auto& pool = allocator_[currentTier()]->getPool(poolId);
2448+
const auto& pool = allocator_[tid]->getPool(poolId);
24482449
const auto& ac = pool.getAllocationClass(classId);
24492450
return ac.getStats();
24502451
}

cachelib/allocator/CacheAllocator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ class CacheAllocator : public CacheBase {
11901190
CacheMemoryStats getCacheMemoryStats() const override final;
11911191

11921192
// return stats for Allocation Class
1193-
ACStats getACStats(PoolId pid, ClassId cid) const override final;
1193+
ACStats getACStats(TierId tid, PoolId pid, ClassId cid) const override final;
11941194

11951195
// return the nvm cache stats map
11961196
util::StatsMap getNvmCacheStatsMap() const override final;

cachelib/allocator/tests/CacheBaseTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class CacheBaseTest : public CacheBase, public SlabAllocatorTestBase {
3434
bool isObjectCache() const override { return false; }
3535
const MemoryPool& getPool(PoolId) const override { return memoryPool_; }
3636
PoolStats getPoolStats(PoolId) const override { return PoolStats(); }
37-
ACStats getACStats(PoolId, ClassId) const { return ACStats(); };
37+
ACStats getACStats(TierId, PoolId, ClassId) const { return ACStats(); };
3838
AllSlabReleaseEvents getAllSlabReleaseEvents(PoolId) const override {
3939
return AllSlabReleaseEvents{};
4040
}

cachelib/cachebench/cache/Cache-inl.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,14 +643,15 @@ Stats Cache<Allocator>::getStats() const {
643643
aggregate += poolStats;
644644
}
645645

646-
std::map<PoolId, std::map<ClassId, ACStats>> allocationClassStats{};
646+
std::map<TierId, std::map<PoolId, std::map<ClassId, ACStats>>> allocationClassStats{};
647647

648648
for (size_t pid = 0; pid < pools_.size(); pid++) {
649649
PoolId poolId = static_cast<PoolId>(pid);
650650
auto poolStats = cache_->getPoolStats(poolId);
651651
auto cids = poolStats.getClassIds();
652-
for (auto [cid, stats] : poolStats.mpStats.acStats) {
653-
allocationClassStats[poolId][cid] = stats;
652+
for (TierId tid = 0; tid < cache_->getNumTiers(); tid++) {
653+
for (auto cid : cids)
654+
allocationClassStats[tid][pid][cid] = cache_->getACStats(tid, pid, cid);
654655
}
655656
}
656657

cachelib/cachebench/cache/Cache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ class Cache {
325325
// return the stats for the pool.
326326
PoolStats getPoolStats(PoolId pid) const { return cache_->getPoolStats(pid); }
327327

328-
ACStats getACStats(PoolId pid, ClassId cid) const {
329-
return cache_->getACStats(pid, cid);
328+
ACStats getACStats(TierId tid, PoolId pid, ClassId cid) const {
329+
return cache_->getACStats(tid, pid, cid);
330330
}
331331

332332
// return the total number of inconsistent operations detected since start.

cachelib/cachebench/cache/CacheStats.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct Stats {
101101
uint64_t invalidDestructorCount{0};
102102
int64_t unDestructedItemCount{0};
103103

104-
std::map<PoolId, std::map<ClassId, ACStats>> allocationClassStats;
104+
std::map<TierId, std::map<PoolId, std::map<ClassId, ACStats>>> allocationClassStats;
105105

106106
// populate the counters related to nvm usage. Cache implementation can decide
107107
// what to populate since not all of those are interesting when running
@@ -155,24 +155,26 @@ struct Stats {
155155
};
156156

157157
auto foreachAC = [&](auto cb) {
158-
for (auto& pidStat : allocationClassStats) {
159-
for (auto& cidStat : pidStat.second) {
160-
cb(pidStat.first, cidStat.first, cidStat.second);
158+
for (auto& tidStat : allocationClassStats) {
159+
for (auto& pidStat : tidStat.second) {
160+
for (auto& cidStat : pidStat.second) {
161+
cb(tidStat.first, pidStat.first, cidStat.first, cidStat.second);
162+
}
161163
}
162164
}
163165
};
164166

165-
foreachAC([&](auto pid, auto cid, auto stats) {
167+
foreachAC([&](auto tid, auto pid, auto cid, auto stats) {
166168
auto [allocSizeSuffix, allocSize] = formatMemory(stats.allocSize);
167169
auto [memorySizeSuffix, memorySize] =
168170
formatMemory(stats.totalAllocatedSize());
169-
out << folly::sformat("pid{:2} cid{:4} {:8.2f}{} memorySize: {:8.2f}{}",
170-
pid, cid, allocSize, allocSizeSuffix, memorySize,
171+
out << folly::sformat("tid{:2} pid{:2} cid{:4} {:8.2f}{} memorySize: {:8.2f}{}",
172+
tid, pid, cid, allocSize, allocSizeSuffix, memorySize,
171173
memorySizeSuffix)
172174
<< std::endl;
173175
});
174176

175-
foreachAC([&](auto pid, auto cid, auto stats) {
177+
foreachAC([&](auto tid, auto pid, auto cid, auto stats) {
176178
auto [allocSizeSuffix, allocSize] = formatMemory(stats.allocSize);
177179

178180
// If the pool is not full, extrapolate usageFraction for AC assuming it

0 commit comments

Comments
 (0)