Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-tier CacheLib part 1 #356

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add memory usage statistics for allocation classes
This includes printing:
- allocSize
- allocated memory size
- memory usage fraction
  • Loading branch information
igchor authored and byrnedj committed Dec 10, 2024
commit 56bb608ada1c97e42fa9d564b23d4cc15bfa899a
6 changes: 6 additions & 0 deletions cachelib/allocator/Cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 117,12 @@ class CacheBase {
// @param poolId the pool id
virtual PoolStats getPoolStats(PoolId poolId) const = 0;

// Get Allocation Class specific stats.
//
// @param poolId the pool id
// @param classId the class id
virtual ACStats getACStats(PoolId poolId, ClassId classId) const = 0;

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

Expand Down
11 changes: 11 additions & 0 deletions cachelib/allocator/CacheAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 1284,9 @@ class CacheAllocator : public CacheBase {
// return cache's memory usage stats
CacheMemoryStats getCacheMemoryStats() const override final;

// return stats for Allocation Class
ACStats getACStats(PoolId pid, ClassId cid) const override final;

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

Expand Down Expand Up @@ -4979,6 4982,14 @@ PoolStats CacheAllocator<CacheTrait>::getPoolStats(PoolId poolId) const {
return ret;
}

template <typename CacheTrait>
ACStats CacheAllocator<CacheTrait>::getACStats(PoolId poolId,
ClassId classId) const {
const auto& pool = allocator_->getPool(poolId);
const auto& ac = pool.getAllocationClass(classId);
return ac.getStats();
}

template <typename CacheTrait>
PoolEvictionAgeStats CacheAllocator<CacheTrait>::getPoolEvictionAgeStats(
PoolId pid, unsigned int slabProjectionLength) const {
Expand Down
11 changes: 11 additions & 0 deletions cachelib/allocator/memory/MemoryAllocatorStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 56,17 @@ struct ACStats {
constexpr size_t getTotalFreeMemory() const noexcept {
return Slab::kSize * freeSlabs freeAllocs * allocSize;
}

constexpr double usageFraction() const noexcept {
if (usedSlabs == 0)
return 0.0;

return activeAllocs / (usedSlabs * allocsPerSlab);
}

constexpr size_t totalAllocatedSize() const noexcept {
return activeAllocs * allocSize;
}
};

// structure to query stats corresponding to a MemoryPool
Expand Down
1 change: 1 addition & 0 deletions cachelib/allocator/tests/CacheBaseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 34,7 @@ class CacheBaseTest : public CacheBase, public SlabAllocatorTestBase {
bool isObjectCache() const override { return false; }
const MemoryPool& getPool(PoolId) const override { return memoryPool_; }
PoolStats getPoolStats(PoolId) const override { return PoolStats(); }
ACStats getACStats(PoolId, ClassId) const { return ACStats(); };
AllSlabReleaseEvents getAllSlabReleaseEvents(PoolId) const override {
return AllSlabReleaseEvents{};
}
Expand Down
4 changes: 4 additions & 0 deletions cachelib/cachebench/cache/Cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 326,10 @@ class Cache {
// return the stats for the pool.
PoolStats getPoolStats(PoolId pid) const { return cache_->getPoolStats(pid); }

ACStats getACStats(PoolId pid, ClassId cid) const {
return cache_->getACStats(pid, cid);
}

// return the total number of inconsistent operations detected since start.
unsigned int getInconsistencyCount() const {
return inconsistencyCount_.load(std::memory_order_relaxed);
Expand Down
14 changes: 4 additions & 10 deletions cachelib/cachebench/cache/CacheStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 172,7 @@ struct Stats {
foreachAC(allocationClassStats, [&](auto pid, auto cid, auto stats) {
auto [allocSizeSuffix, allocSize] = formatMemory(stats.allocSize);
auto [memorySizeSuffix, memorySize] =
formatMemory(stats.activeAllocs * stats.allocSize);
formatMemory(stats.totalAllocatedSize());
out << folly::sformat("pid{:2} cid{:4} {:8.2f}{} memorySize: {:8.2f}{}",
pid, cid, allocSize, allocSizeSuffix, memorySize,
memorySizeSuffix)
Expand All @@ -184,15 184,9 @@ struct Stats {

// If the pool is not full, extrapolate usageFraction for AC assuming it
// will grow at the same rate. This value will be the same for all ACs.
double acUsageFraction;
if (poolUsageFraction[pid] < 1.0) {
acUsageFraction = poolUsageFraction[pid];
} else if (stats.usedSlabs == 0) {
acUsageFraction = 0.0;
} else {
acUsageFraction =
stats.activeAllocs / (stats.usedSlabs * stats.allocsPerSlab);
}
auto acUsageFraction = (poolUsageFraction[pid] < 1.0)
? poolUsageFraction[pid]
: stats.usageFraction();

out << folly::sformat(
"pid{:2} cid{:4} {:8.2f}{} usageFraction: {:4.2f}", pid, cid,
Expand Down