@@ -324,7 +324,9 @@ CacheAllocator<CacheTrait>::allocateInternal(PoolId pid,
324324 const auto requiredSize = Item::getRequiredSize (key, size);
325325
326326 // the allocation class in our memory allocator.
327- const auto cid = allocator_->getAllocationClassId (pid, requiredSize);
327+ const auto cid = allocator_[tid]->getAllocationClassId (pid, requiredSize);
328+ util::RollingLatencyTracker rollTracker{
329+ (*stats_.classAllocLatency )[tid][pid][cid]};
328330
329331 (*stats_.allocAttempts )[pid][cid].inc ();
330332
@@ -402,6 +404,11 @@ CacheAllocator<CacheTrait>::allocateChainedItemInternal(
402404 const auto pid = allocator_->getAllocInfo (parent->getMemory ()).poolId ;
403405 const auto cid = allocator_->getAllocationClassId (pid, requiredSize);
404406
407+ util::RollingLatencyTracker rollTracker{
408+ (*stats_.classAllocLatency )[tid][pid][cid]};
409+
410+ // TODO: per-tier? Right now stats_ are not used in any public periodic
411+ // worker
405412 (*stats_.allocAttempts )[pid][cid].inc ();
406413
407414 void * memory = allocator_->allocate (pid, requiredSize);
@@ -2220,6 +2227,49 @@ PoolStats CacheAllocator<CacheTrait>::getPoolStats(PoolId poolId) const {
22202227 return ret;
22212228}
22222229
2230+ template <typename CacheTrait>
2231+ double CacheAllocator<CacheTrait>::slabsApproxFreePercentage(TierId tid) const {
2232+ return allocator_[tid]->approxFreeSlabsPercentage ();
2233+ }
2234+
2235+ template <typename CacheTrait>
2236+ AllocationClassBaseStat CacheAllocator<CacheTrait>::getAllocationClassStats(
2237+ TierId tid, PoolId pid, ClassId cid) const {
2238+ const auto & ac = allocator_[tid]->getPool (pid).getAllocationClass (cid);
2239+
2240+ AllocationClassBaseStat stats{};
2241+ stats.allocSize = ac.getAllocSize ();
2242+ stats.memorySize = ac.getNumSlabs () * Slab::kSize ;
2243+
2244+ if (slabsApproxFreePercentage (tid) > 0.0 ) {
2245+ auto totalMemory = MemoryAllocator::getMemorySize (memoryTierSize (tid));
2246+ auto freeMemory = static_cast <double >(totalMemory) *
2247+ slabsApproxFreePercentage (tid) / 100.0 ;
2248+
2249+ // amount of free memory which has the same ratio to entire free memory as
2250+ // this allocation class memory size has to used memory
2251+ auto scaledFreeMemory =
2252+ static_cast <size_t >(freeMemory * stats.memorySize / totalMemory);
2253+
2254+ auto acAllocatedMemory = (100.0 - ac.approxFreePercentage ()) / 100.0 *
2255+ ac.getNumSlabs () * Slab::kSize ;
2256+ auto acMaxAvailableMemory =
2257+ ac.getNumSlabs () * Slab::kSize + scaledFreeMemory;
2258+
2259+ if (acMaxAvailableMemory == 0 ) {
2260+ stats.approxFreePercent = 100.0 ;
2261+ } else {
2262+ stats.approxFreePercent =
2263+ 100.0 - 100.0 * acAllocatedMemory / acMaxAvailableMemory;
2264+ }
2265+ } else {
2266+ stats.approxFreePercent = ac.approxFreePercentage ();
2267+ }
2268+ stats.allocLatencyNs = (*stats_.classAllocLatency )[tid][pid][cid];
2269+
2270+ return stats;
2271+ }
2272+
22232273template <typename CacheTrait>
22242274PoolEvictionAgeStats CacheAllocator<CacheTrait>::getPoolEvictionAgeStats(
22252275 PoolId pid, unsigned int slabProjectionLength) const {
0 commit comments