Skip to content

Tracking per-pool usage stats #141

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

Closed
wants to merge 1 commit into from

Conversation

guptask
Copy link
Contributor

@guptask guptask commented May 25, 2022

This per pool size statistics reports the current used space in each memory pool. Pool Usage = PoolStats->poolUsableSize - PoolStats->freeMemoryBytes(). This statistics will be reported in the final report generated by cachebench.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 25, 2022
@therealgymmy
Copy link
Contributor

@guptask: Can you clarify the goal of this change? The change here only exports how many bytes is allocated towards each memory pool. (It doesn't track per allocation class usage).

For pool size, you should already be able to get it via CacheAllocator::getPoolStats(poolId). And then look at PoolStats::poolSize. (https://github.com/facebook/CacheLib/blob/main/cachelib/allocator/CacheStats.h#L154)

For per-allocation-class size, you can refer to PoolStats::numSlabsForClass(classId) (https://github.com/facebook/CacheLib/blob/main/cachelib/allocator/CacheStats.h#L213).

@guptask
Copy link
Contributor Author

guptask commented Jun 1, 2022

@guptask: Can you clarify the goal of this change? The change here only exports how many bytes is allocated towards each memory pool. (It doesn't track per allocation class usage).

For pool size, you should already be able to get it via CacheAllocator::getPoolStats(poolId). And then look at PoolStats::poolSize. (https://github.com/facebook/CacheLib/blob/main/cachelib/allocator/CacheStats.h#L154)

For per-allocation-class size, you can refer to PoolStats::numSlabsForClass(classId) (https://github.com/facebook/CacheLib/blob/main/cachelib/allocator/CacheStats.h#L213).

Are you referring to the poolUsedSize metric ? This metric tracks the capacity of a pool that is currently under use. The purpose of this change is to track how much capacity of each pool is getting utilized.
It is not the same as the PoolStats metrics poolSize or poolUsableSize.
I added the getAllocationSize API to calculate the pool used size as a check in the AllocatorHitStats unit test.

@therealgymmy
Copy link
Contributor

@guptask: memoryPoolSize_[poolId] gives you the size of bytes that have been allocated by the memory pool. It doesn't distinguish between what's allocated for items and what's in freed list inside the pool. Is this what you want? (https://github.com/facebook/CacheLib/blob/main/cachelib/allocator/memory/SlabAllocator.cpp#L362)

You can already get this stat by checking CacheStats::mpStats::allocatedSlabs() (https://github.com/facebook/CacheLib/blob/main/cachelib/allocator/CacheStats.h#L168)

@guptask
Copy link
Contributor Author

guptask commented Jun 3, 2022

@guptask: memoryPoolSize_[poolId] gives you the size of bytes that have been allocated by the memory pool. It doesn't distinguish between what's allocated for items and what's in freed list inside the pool. Is this what you want? (https://github.com/facebook/CacheLib/blob/main/cachelib/allocator/memory/SlabAllocator.cpp#L362)

You can already get this stat by checking CacheStats::mpStats::allocatedSlabs() (https://github.com/facebook/CacheLib/blob/main/cachelib/allocator/CacheStats.h#L168)

I get your point now. The poolUsedSize statistic is supposed to track the pool usage. Based on my understanding now, pool_used_size = Slab::ksize * (MPStats->freeSlabs + class_aggregate of ACStats->usedSlabs).
allocatedSlabs(), on the other hand, equals MPStats->freeSlabs + class_aggregate of ACStats->usedSlabs and ACStats->freeSlabs. Does this look correct to you ?

This is part of the initial step towards the background eviction changes we'll send upstream for reviews later. Exposing this statistic via cachebench allows us to observe the growth and shrinking of pool usage on graphana. This helps with tuning of the eviction policies.

@therealgymmy
Copy link
Contributor

The poolUsedSize statistic is supposed to track the pool usage. Based on my understanding now, pool_used_size = Slab::ksize * (MPStats->freeSlabs + class_aggregate of ACStats->usedSlabs).
allocatedSlabs(), on the other hand, equals MPStats->freeSlabs + class_aggregate of ACStats->usedSlabs and ACStats->freeSlabs. Does this look correct to you ?

@guptask: Hmm I don't fully follow. Do you want to know a memory pool's amount of bytes that are currently allocated for items in cache? If so, you should exclude free memory that are nonetheless "allocated" for this pool. MPStats->freeSlabs and aggregate of ACStats->freeSlabs both are considered free memory. You also want to exclude ACStats->freeAllocs.

You can get all of this by looking at the PoolStats class. You can take the PoolStats->poolUsableSize and subtract from it PoolStats->freeMemoryBytes(). https://github.com/facebook/CacheLib/blob/main/cachelib/allocator/CacheStats.h#L190

The computation of freeMemoryBytes() is in MPStats class, and can be found here: https://github.com/facebook/CacheLib/blob/main/cachelib/allocator/memory/MemoryAllocatorStats.h#L104

@guptask
Copy link
Contributor Author

guptask commented Jun 7, 2022

The poolUsedSize statistic is supposed to track the pool usage. Based on my understanding now, pool_used_size = Slab::ksize * (MPStats->freeSlabs + class_aggregate of ACStats->usedSlabs).
allocatedSlabs(), on the other hand, equals MPStats->freeSlabs + class_aggregate of ACStats->usedSlabs and ACStats->freeSlabs. Does this look correct to you ?

@guptask: Hmm I don't fully follow. Do you want to know a memory pool's amount of bytes that are currently allocated for items in cache? If so, you should exclude free memory that are nonetheless "allocated" for this pool. MPStats->freeSlabs and aggregate of ACStats->freeSlabs both are considered free memory. You also want to exclude ACStats->freeAllocs.

You can get all of this by looking at the PoolStats class. You can take the PoolStats->poolUsableSize and subtract from it PoolStats->freeMemoryBytes(). https://github.com/facebook/CacheLib/blob/main/cachelib/allocator/CacheStats.h#L190

The computation of freeMemoryBytes() is in MPStats class, and can be found here: https://github.com/facebook/CacheLib/blob/main/cachelib/allocator/memory/MemoryAllocatorStats.h#L104

Thanks. I'll update the PR accordingly.

@guptask guptask force-pushed the upstream_per_tier_stats branch from b4579b7 to 1d186de Compare June 16, 2022 11:01
@@ -116,6 +118,12 @@ struct Stats {
<< std::endl;
out << folly::sformat("RAM Evictions : {:,}", numEvictions) << std::endl;

for (auto pid = 0U; pid < poolUsageFraction.size(); pid++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only tracking per-pool usage stats right? Can you update the PR title to reflect this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@facebook-github-bot
Copy link
Contributor

@therealgymmy has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@guptask guptask changed the title Added per pool per class used size metrics Tracking per-pool usage stats Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants