Skip to content

Commit 3b8d87c

Browse files
committed
AC stats multi-tier
1 parent bd80a46 commit 3b8d87c

File tree

7 files changed

+23
-18
lines changed

7 files changed

+23
-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
@@ -2419,9 +2419,10 @@ PoolStats CacheAllocator<CacheTrait>::getPoolStats(PoolId poolId) const {
24192419
}
24202420

24212421
template <typename CacheTrait>
2422-
ACStats CacheAllocator<CacheTrait>::getACStats(PoolId poolId,
2422+
ACStats CacheAllocator<CacheTrait>::getACStats(TierId tid,
2423+
PoolId poolId,
24232424
ClassId classId) const {
2424-
const auto& pool = allocator_[currentTier()]->getPool(poolId);
2425+
const auto& pool = allocator_[tid]->getPool(poolId);
24252426
const auto& ac = pool.getAllocationClass(classId);
24262427
return ac.getStats();
24272428
}

cachelib/allocator/CacheAllocator.h

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

11851185
// return stats for Allocation Class
1186-
ACStats getACStats(PoolId pid, ClassId cid) const override final;
1186+
ACStats getACStats(TierId tid, PoolId pid, ClassId cid) const override final;
11871187

11881188
// return the nvm cache stats map
11891189
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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,14 @@ Stats Cache<Allocator>::getStats() const {
620620
aggregate += poolStats;
621621
}
622622

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

625625
for (size_t pid = 0; pid < pools_.size(); pid++) {
626626
auto cids = cache_->getPoolStats(static_cast<PoolId>(pid)).getClassIds();
627-
for (auto cid : cids)
628-
allocationClassStats[pid][cid] = cache_->getACStats(pid, cid);
627+
for (TierId tid = 0; tid < cache_->getNumTiers(); tid++) {
628+
for (auto cid : cids)
629+
allocationClassStats[tid][pid][cid] = cache_->getACStats(tid, pid, cid);
630+
}
629631
}
630632

631633
const auto cacheStats = cache_->getGlobalCacheStats();

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
@@ -156,24 +156,26 @@ struct Stats {
156156
};
157157

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

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

176-
foreachAC([&](auto pid, auto cid, auto stats) {
178+
foreachAC([&](auto tid, auto pid, auto cid, auto stats) {
177179
auto [allocSizeSuffix, allocSize] = formatMemory(stats.allocSize);
178180

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

0 commit comments

Comments
 (0)