From: Mark Nelson Date: Wed, 18 Apr 2018 18:28:50 +0000 (-0500) Subject: cache/lru_cache: high pri pool capacity -> size_t X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c114b475e328ca9f4a15f989b12b6b844cdbdecd;p=rocksdb.git cache/lru_cache: high pri pool capacity -> size_t Signed-off-by: Mark Nelson --- diff --git a/cache/lru_cache.cc b/cache/lru_cache.cc index a7611cac..28b93800 100644 --- a/cache/lru_cache.cc +++ b/cache/lru_cache.cc @@ -251,7 +251,7 @@ void LRUCacheShard::SetCapacity(size_t capacity) { { MutexLock l(&mutex_); capacity_ = capacity; - high_pri_pool_capacity_ = capacity_ * high_pri_pool_ratio_; + ResetHighPriPoolCapacity(); EvictFromLRU(0, &last_reference_list); } // we free the entries here outside of mutex for @@ -293,10 +293,15 @@ bool LRUCacheShard::Ref(Cache::Handle* h) { void LRUCacheShard::SetHighPriPoolRatio(double high_pri_pool_ratio) { MutexLock l(&mutex_); high_pri_pool_ratio_ = high_pri_pool_ratio; - high_pri_pool_capacity_ = capacity_ * high_pri_pool_ratio_; + ResetHighPriPoolCapacity(); MaintainPoolSize(); } +void LRUCacheShard::ResetHighPriPoolCapacity() { + high_pri_pool_capacity_ = + static_cast(capacity_ * high_pri_pool_ratio_); +} + bool LRUCacheShard::Release(Cache::Handle* handle, bool force_erase) { if (handle == nullptr) { return false; diff --git a/cache/lru_cache.h b/cache/lru_cache.h index 60538c5f..d926e7d8 100644 --- a/cache/lru_cache.h +++ b/cache/lru_cache.h @@ -229,6 +229,9 @@ class ALIGN_AS(CACHE_LINE_SIZE) LRUCacheShard : public CacheShard { // holding the mutex_ void EvictFromLRU(size_t charge, autovector* deleted); + // Reset the high-pri pool capacity based on the capacity and ratio. + void ResetHighPriPoolCapacity(); + // Initialized before use. size_t capacity_; @@ -243,7 +246,7 @@ class ALIGN_AS(CACHE_LINE_SIZE) LRUCacheShard : public CacheShard { // High-pri pool size, equals to capacity * high_pri_pool_ratio. // Remember the value to avoid recomputing each time. - double high_pri_pool_capacity_; + size_t high_pri_pool_capacity_; // Dummy head of LRU list. // lru.prev is newest entry, lru.next is oldest entry.