![]() |
CernVM-FS
2.12.0
|
#include <lru.h>
Classes | |
struct | CacheEntry |
class | ListEntry |
class | ListEntryContent |
class | ListEntryHead |
class | MemoryAllocator |
Public Member Functions | |
LruCache (const unsigned cache_size, const Key &empty_key, uint32_t(*hasher)(const Key &key), perf::StatisticsTemplate statistics) | |
virtual | ~LruCache () |
virtual bool | Insert (const Key &key, const Value &value) |
virtual void | Update (const Key &key) |
virtual bool | UpdateValue (const Key &key, const Value &value) |
virtual bool | Lookup (const Key &key, Value *value, bool update_lru=true) |
virtual bool | Forget (const Key &key) |
virtual void | Drop () |
void | Pause () |
void | Resume () |
bool | IsFull () const |
bool | IsEmpty () const |
Counters | counters () |
virtual void | FilterBegin () |
virtual void | FilterGet (Key *key, Value *value) |
virtual bool | FilterNext () |
virtual void | FilterDelete () |
virtual void | FilterEnd () |
Static Public Member Functions | |
static double | GetEntrySize () |
Protected Attributes | |
Counters | counters_ |
Private Types | |
typedef ListEntryContent< Key > | ConcreteListEntryContent |
typedef MemoryAllocator < ConcreteListEntryContent > | ConcreteMemoryAllocator |
Private Member Functions | |
bool | DoLookup (const Key &key, CacheEntry *entry) |
void | Touch (const CacheEntry &entry) |
void | DeleteOldest () |
void | Lock () |
void | Unlock () |
![]() | |
SingleCopy () | |
Private Attributes | |
bool | pause_ |
unsigned int | cache_gauge_ |
const unsigned int | cache_size_ |
ConcreteMemoryAllocator | allocator_ |
ListEntryHead< Key > | lru_list_ |
SmallHashFixed< Key, CacheEntry > | cache_ |
ListEntry< Key > * | filter_entry_ |
pthread_mutex_t | lock_ |
Template class to create a LRU cache
Key | type of the key values |
Value | type of the value values |
|
private |
|
private |
|
inline |
|
inlinevirtual |
|
inline |
|
inlineprivate |
Deletes the least recently used entry from the cache.
Definition at line 823 of file lru.h.
Referenced by lru::LruCache< shash::Any, MemoryBuffer >::Insert().
|
inlineprivate |
this just performs a lookup in the cache WITHOUT changing the LRU order
key | the key to perform a lookup on |
entry | a pointer to the entry structure |
Definition at line 806 of file lru.h.
Referenced by lru::LruCache< shash::Any, MemoryBuffer >::FilterGet(), lru::LruCache< shash::Any, MemoryBuffer >::Forget(), lru::LruCache< shash::Any, MemoryBuffer >::Insert(), lru::LruCache< shash::Any, MemoryBuffer >::Lookup(), lru::LruCache< shash::Any, MemoryBuffer >::Update(), and lru::LruCache< shash::Any, MemoryBuffer >::UpdateValue().
|
inlinevirtual |
Clears all elements from the cache. All memory of internal data structures will be freed but data of cache entries may stay in use, we do not call delete on any user data.
Reimplemented in lru::Md5PathCache, lru::PathCache, and lru::InodeCache.
Definition at line 697 of file lru.h.
Referenced by lru::InodeCache::Drop(), lru::PathCache::Drop(), and lru::Md5PathCache::Drop().
|
inlinevirtual |
Prepares for in-order iteration of the cache entries to perform a filter operation. To ensure consistency, the LruCache must be locked for the duration of the filter operation.
Definition at line 739 of file lru.h.
Referenced by MemoryKvStore::ShrinkTo().
|
inlinevirtual |
Delete the current cache list entry
Definition at line 773 of file lru.h.
Referenced by MemoryKvStore::ShrinkTo().
|
inlinevirtual |
Finish filtering the entries and unlock the cache
Definition at line 789 of file lru.h.
Referenced by MemoryKvStore::ShrinkTo().
|
inlinevirtual |
Get the current key and value for the filter operation
key | Address to write the key |
value | Address to write the value |
Definition at line 750 of file lru.h.
Referenced by MemoryKvStore::ShrinkTo().
|
inlinevirtual |
Advance to the next entry in the list
Definition at line 764 of file lru.h.
Referenced by MemoryKvStore::ShrinkTo().
|
inlinevirtual |
Forgets about a specific cache entry
key | the key to delete from the cache |
Reimplemented in lru::Md5PathCache.
Definition at line 669 of file lru.h.
Referenced by MemoryKvStore::DoDelete(), and lru::Md5PathCache::Forget().
|
inlinestatic |
Definition at line 535 of file lru.h.
Referenced by PluginRamCache::PluginRamCache().
|
inlinevirtual |
Insert a new key-value pair to the list. If the cache is already full, the least recently used object is removed; afterwards the new object is inserted. If the object is already present it is updated and moved back to the end of the list
key | the key where the value is saved |
value | the value of the cache entry |
Reimplemented in lru::Md5PathCache, lru::PathCache, and lru::InodeCache.
Definition at line 556 of file lru.h.
Referenced by MemoryKvStore::DoCommit(), MemoryKvStore::IncRef(), lru::InodeCache::Insert(), lru::PathCache::Insert(), lru::Md5PathCache::Insert(), and MemoryKvStore::Unref().
|
inline |
Definition at line 724 of file lru.h.
Referenced by lru::LruCache< shash::Any, MemoryBuffer >::DeleteOldest().
|
inline |
Definition at line 723 of file lru.h.
Referenced by lru::LruCache< shash::Any, MemoryBuffer >::Insert().
|
inlineprivate |
Locks the cache (thread safety).
Definition at line 836 of file lru.h.
Referenced by lru::LruCache< shash::Any, MemoryBuffer >::counters(), lru::LruCache< shash::Any, MemoryBuffer >::Drop(), lru::LruCache< shash::Any, MemoryBuffer >::FilterBegin(), lru::LruCache< shash::Any, MemoryBuffer >::Forget(), lru::LruCache< shash::Any, MemoryBuffer >::Insert(), lru::LruCache< shash::Any, MemoryBuffer >::Lookup(), lru::LruCache< shash::Any, MemoryBuffer >::Pause(), lru::LruCache< shash::Any, MemoryBuffer >::Resume(), lru::LruCache< shash::Any, MemoryBuffer >::Update(), and lru::LruCache< shash::Any, MemoryBuffer >::UpdateValue().
|
inlinevirtual |
Retrieve an element from the cache. If the element was found, it will be marked as 'recently used' and returned
key | the key to perform a lookup on |
value | (out) here the result is saved (not touch in case of miss) |
Reimplemented in lru::Md5PathCache, lru::PathCache, and lru::InodeCache.
Definition at line 640 of file lru.h.
Referenced by MemoryKvStore::Contains(), MemoryKvStore::DoCommit(), MemoryKvStore::DoDelete(), MemoryKvStore::GetRefcount(), MemoryKvStore::GetSize(), MemoryKvStore::IncRef(), lru::InodeCache::Lookup(), lru::PathCache::Lookup(), lru::Md5PathCache::Lookup(), MemoryKvStore::OnBlockMove(), MemoryKvStore::Read(), and MemoryKvStore::Unref().
|
inline |
Definition at line 711 of file lru.h.
Referenced by TalkManager::MainResponder(), and FuseRemounter::TryFinish().
|
inline |
Definition at line 717 of file lru.h.
Referenced by TalkManager::MainResponder(), and FuseRemounter::TryFinish().
|
inlineprivate |
Touch an entry. The entry will be moved to the back of the LRU list to mark it as 'recently used'... this saves the entry from being deleted
entry | the CacheEntry to be touched (CacheEntry is the internal wrapper data structure) |
Definition at line 816 of file lru.h.
Referenced by lru::LruCache< shash::Any, MemoryBuffer >::Insert(), lru::LruCache< shash::Any, MemoryBuffer >::Lookup(), and lru::LruCache< shash::Any, MemoryBuffer >::Update().
|
inlineprivate |
Unlocks the cache (thread safety).
Definition at line 845 of file lru.h.
Referenced by lru::LruCache< shash::Any, MemoryBuffer >::counters(), lru::LruCache< shash::Any, MemoryBuffer >::Drop(), lru::LruCache< shash::Any, MemoryBuffer >::FilterEnd(), lru::LruCache< shash::Any, MemoryBuffer >::Forget(), lru::LruCache< shash::Any, MemoryBuffer >::Insert(), lru::LruCache< shash::Any, MemoryBuffer >::Lookup(), lru::LruCache< shash::Any, MemoryBuffer >::Pause(), lru::LruCache< shash::Any, MemoryBuffer >::Resume(), lru::LruCache< shash::Any, MemoryBuffer >::Update(), and lru::LruCache< shash::Any, MemoryBuffer >::UpdateValue().
|
inlinevirtual |
|
inlinevirtual |
Changes the value of an entry in the LRU cache without updating the LRU order.
Definition at line 612 of file lru.h.
Referenced by MemoryKvStore::OnBlockMove().
|
private |
Definition at line 856 of file lru.h.
Referenced by lru::LruCache< shash::Any, MemoryBuffer >::Drop(), lru::LruCache< shash::Any, MemoryBuffer >::FilterDelete(), lru::LruCache< shash::Any, MemoryBuffer >::Forget(), and lru::LruCache< shash::Any, MemoryBuffer >::LruCache().
|
private |
Definition at line 866 of file lru.h.
Referenced by lru::LruCache< shash::Any, MemoryBuffer >::counters(), lru::LruCache< shash::Any, MemoryBuffer >::DeleteOldest(), lru::LruCache< shash::Any, MemoryBuffer >::DoLookup(), lru::LruCache< shash::Any, MemoryBuffer >::Drop(), lru::LruCache< shash::Any, MemoryBuffer >::FilterDelete(), lru::LruCache< shash::Any, MemoryBuffer >::Forget(), lru::LruCache< shash::Any, MemoryBuffer >::Insert(), lru::LruCache< shash::Any, MemoryBuffer >::LruCache(), and lru::LruCache< shash::Any, MemoryBuffer >::UpdateValue().
|
private |
Definition at line 854 of file lru.h.
Referenced by lru::LruCache< shash::Any, MemoryBuffer >::DeleteOldest(), lru::LruCache< shash::Any, MemoryBuffer >::Drop(), lru::LruCache< shash::Any, MemoryBuffer >::FilterDelete(), lru::LruCache< shash::Any, MemoryBuffer >::Forget(), lru::LruCache< shash::Any, MemoryBuffer >::Insert(), lru::LruCache< shash::Any, MemoryBuffer >::IsEmpty(), and lru::LruCache< shash::Any, MemoryBuffer >::IsFull().
|
private |
Definition at line 855 of file lru.h.
Referenced by lru::LruCache< shash::Any, MemoryBuffer >::IsFull(), and lru::LruCache< shash::Any, MemoryBuffer >::LruCache().
|
protected |
Definition at line 796 of file lru.h.
Referenced by lru::LruCache< shash::Any, MemoryBuffer >::counters(), lru::LruCache< shash::Any, MemoryBuffer >::DeleteOldest(), lru::LruCache< shash::Any, MemoryBuffer >::Drop(), lru::LruCache< shash::Any, MemoryBuffer >::FilterDelete(), lru::LruCache< shash::Any, MemoryBuffer >::Forget(), lru::LruCache< shash::Any, MemoryBuffer >::Insert(), lru::LruCache< shash::Any, MemoryBuffer >::Lookup(), lru::LruCache< shash::Any, MemoryBuffer >::LruCache(), lru::LruCache< shash::Any, MemoryBuffer >::Update(), and lru::LruCache< shash::Any, MemoryBuffer >::UpdateValue().
|
private |
Definition at line 868 of file lru.h.
Referenced by lru::LruCache< shash::Any, MemoryBuffer >::FilterBegin(), lru::LruCache< shash::Any, MemoryBuffer >::FilterDelete(), lru::LruCache< shash::Any, MemoryBuffer >::FilterEnd(), lru::LruCache< shash::Any, MemoryBuffer >::FilterGet(), lru::LruCache< shash::Any, MemoryBuffer >::FilterNext(), and lru::LruCache< shash::Any, MemoryBuffer >::LruCache().
|
private |
Mutex to make cache thread safe.
Definition at line 870 of file lru.h.
Referenced by lru::LruCache< shash::Any, MemoryBuffer >::Lock(), lru::LruCache< shash::Any, MemoryBuffer >::LruCache(), lru::LruCache< shash::Any, MemoryBuffer >::Unlock(), and lru::LruCache< shash::Any, MemoryBuffer >::~LruCache().
|
private |
A doubly linked list to keep track of the least recently used data entries. New entries get pushed back to the list. If an entry is touched it is moved to the back of the list again. If the cache gets too long, the first element (the oldest) gets deleted to obtain some space.
Definition at line 865 of file lru.h.
Referenced by lru::LruCache< shash::Any, MemoryBuffer >::DeleteOldest(), lru::LruCache< shash::Any, MemoryBuffer >::Drop(), lru::LruCache< shash::Any, MemoryBuffer >::FilterBegin(), lru::LruCache< shash::Any, MemoryBuffer >::Insert(), and lru::LruCache< shash::Any, MemoryBuffer >::Touch().
|
private |
Temporarily stops the cache in order to avoid poisoning
Definition at line 851 of file lru.h.
Referenced by lru::LruCache< shash::Any, MemoryBuffer >::Forget(), lru::LruCache< shash::Any, MemoryBuffer >::Insert(), lru::LruCache< shash::Any, MemoryBuffer >::Lookup(), lru::LruCache< shash::Any, MemoryBuffer >::Pause(), lru::LruCache< shash::Any, MemoryBuffer >::Resume(), lru::LruCache< shash::Any, MemoryBuffer >::Update(), and lru::LruCache< shash::Any, MemoryBuffer >::UpdateValue().