|
|
|
@ -148,13 +148,13 @@ class LRUHandleTable { |
|
|
|
|
|
|
|
|
|
// The table consists of an array of buckets where each bucket is
|
|
|
|
|
// a linked list of cache entries that hash into the bucket.
|
|
|
|
|
LRUHandle** list_; |
|
|
|
|
uint32_t length_; |
|
|
|
|
uint32_t elems_; |
|
|
|
|
LRUHandle** list_; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// A single shard of sharded cache.
|
|
|
|
|
class LRUCacheShard : public CacheShard { |
|
|
|
|
class ALIGN_AS(CACHE_LINE_SIZE) LRUCacheShard : public CacheShard { |
|
|
|
|
public: |
|
|
|
|
LRUCacheShard(); |
|
|
|
|
virtual ~LRUCacheShard(); |
|
|
|
@ -202,6 +202,11 @@ class LRUCacheShard : public CacheShard { |
|
|
|
|
// not threadsafe
|
|
|
|
|
size_t TEST_GetLRUSize(); |
|
|
|
|
|
|
|
|
|
// Overloading to aligned it to cache line size
|
|
|
|
|
void* operator new(size_t); |
|
|
|
|
|
|
|
|
|
void operator delete(void *); |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
void LRU_Remove(LRUHandle* e); |
|
|
|
|
void LRU_Insert(LRUHandle* e); |
|
|
|
@ -223,12 +228,6 @@ class LRUCacheShard : public CacheShard { |
|
|
|
|
// Initialized before use.
|
|
|
|
|
size_t capacity_; |
|
|
|
|
|
|
|
|
|
// Memory size for entries residing in the cache
|
|
|
|
|
size_t usage_; |
|
|
|
|
|
|
|
|
|
// Memory size for entries residing only in the LRU list
|
|
|
|
|
size_t lru_usage_; |
|
|
|
|
|
|
|
|
|
// Memory size for entries in high-pri pool.
|
|
|
|
|
size_t high_pri_pool_usage_; |
|
|
|
|
|
|
|
|
@ -242,11 +241,6 @@ class LRUCacheShard : public CacheShard { |
|
|
|
|
// Remember the value to avoid recomputing each time.
|
|
|
|
|
double high_pri_pool_capacity_; |
|
|
|
|
|
|
|
|
|
// mutex_ protects the following state.
|
|
|
|
|
// We don't count mutex_ as the cache's internal state so semantically we
|
|
|
|
|
// don't mind mutex_ invoking the non-const actions.
|
|
|
|
|
mutable port::Mutex mutex_; |
|
|
|
|
|
|
|
|
|
// Dummy head of LRU list.
|
|
|
|
|
// lru.prev is newest entry, lru.next is oldest entry.
|
|
|
|
|
// LRU contains items which can be evicted, ie reference only by cache
|
|
|
|
@ -255,7 +249,29 @@ class LRUCacheShard : public CacheShard { |
|
|
|
|
// Pointer to head of low-pri pool in LRU list.
|
|
|
|
|
LRUHandle* lru_low_pri_; |
|
|
|
|
|
|
|
|
|
// ------------^^^^^^^^^^^^^-----------
|
|
|
|
|
// Not frequently modified data members
|
|
|
|
|
// ------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// We separate data members that are updated frequently from the ones that
|
|
|
|
|
// are not frequently updated so that they don't share the same cache line
|
|
|
|
|
// which will lead into false cache sharing
|
|
|
|
|
//
|
|
|
|
|
// ------------------------------------
|
|
|
|
|
// Frequently modified data members
|
|
|
|
|
// ------------vvvvvvvvvvvvv-----------
|
|
|
|
|
LRUHandleTable table_; |
|
|
|
|
|
|
|
|
|
// Memory size for entries residing in the cache
|
|
|
|
|
size_t usage_; |
|
|
|
|
|
|
|
|
|
// Memory size for entries residing only in the LRU list
|
|
|
|
|
size_t lru_usage_; |
|
|
|
|
|
|
|
|
|
// mutex_ protects the following state.
|
|
|
|
|
// We don't count mutex_ as the cache's internal state so semantically we
|
|
|
|
|
// don't mind mutex_ invoking the non-const actions.
|
|
|
|
|
mutable port::Mutex mutex_; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
class LRUCache : public ShardedCache { |
|
|
|
|