From 5eaeb45c36b074e7c5052fc3d37f2e23e69aea25 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 6 Mar 2018 14:50:33 -0600 Subject: [PATCH] cache/lru_cache: expose usage/capacity for high priority pool. Signed-off-by: Mark Nelson --- cache/lru_cache.cc | 26 ++++++++++++++++++++++++++ cache/lru_cache.h | 18 +++++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/cache/lru_cache.cc b/cache/lru_cache.cc index b655b335f..adefc6551 100644 --- a/cache/lru_cache.cc +++ b/cache/lru_cache.cc @@ -458,6 +458,16 @@ size_t LRUCacheShard::GetPinnedUsage() const { return usage_ - lru_usage_; } +size_t LRUCacheShard::GetHighPriPoolCapacity() { + MutexLock l(&mutex_); + return high_pri_pool_capacity_; +} + +size_t LRUCacheShard::GetHighPriPoolUsage() { + MutexLock l(&mutex_); + return high_pri_pool_usage_; +} + std::string LRUCacheShard::GetPrintableOptions() const { const int kBufferSize = 200; char buffer[kBufferSize]; @@ -518,6 +528,22 @@ size_t LRUCache::TEST_GetLRUSize() { return lru_size_of_all_shards; } +size_t LRUCache::GetHighPriPoolCapacity() { + size_t size = 0; + for (int i = 0; i < num_shards_; i++) { + size += shards_[i].GetHighPriPoolCapacity(); + } + return size; +} + +size_t LRUCache::GetHighPriPoolUsage() { + size_t size = 0; + for (int i = 0; i < num_shards_; i++) { + size += shards_[i].GetHighPriPoolUsage(); + } + return size; +} + double LRUCache::GetHighPriPoolRatio() { double result = 0.0; if (num_shards_ > 0) { diff --git a/cache/lru_cache.h b/cache/lru_cache.h index b325fb4cf..3ec4ea594 100644 --- a/cache/lru_cache.h +++ b/cache/lru_cache.h @@ -198,11 +198,15 @@ class ALIGN_AS(CACHE_LINE_SIZE) LRUCacheShard : public CacheShard { void TEST_GetLRUList(LRUHandle** lru, LRUHandle** lru_low_pri); - // Retrieves number of elements in LRU, for unit test purpose only - // not threadsafe + // Retrieves number of elements in LRU, for unit test purpose only + // not threadsafe size_t TEST_GetLRUSize(); - // Retrives high pri pool ratio + // Retrieve pool capacities and usages. Protected with mutex_. + size_t GetHighPriPoolCapacity(); + size_t GetHighPriPoolUsage(); + + // Retrives high pri pool ratio double GetHighPriPoolRatio(); // Overloading to aligned it to cache line size @@ -294,9 +298,13 @@ class LRUCache : public ShardedCache { virtual uint32_t GetHash(Handle* handle) const override; virtual void DisownData() override; - // Retrieves number of elements in LRU, for unit test purpose only + // Retrieves number of elements in LRU, for unit test purpose only size_t TEST_GetLRUSize(); - // Retrives high pri pool ratio + // Retrieves high pri pool ratio + size_t GetHighPriPoolCapacity(); + // Retrieves high pri pool capacty + size_t GetHighPriPoolUsage(); + // Retrieves high pri pool ratio double GetHighPriPoolRatio(); private: -- 2.47.3