diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-03-14 12:04:30 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-03-14 12:04:30 +0000 |
commit | 28ab766a23032cf35c3a124007775712a4fd033e (patch) | |
tree | 65e49381b94f291c756e3dc6ee01ad168a84f18a /vespalib/src | |
parent | b148d50f3d2bd2711b06618653f277bf84b1eec8 (diff) |
Wire in and test static memory usage for caches.
Diffstat (limited to 'vespalib/src')
-rw-r--r-- | vespalib/src/vespa/vespalib/stllike/cache.h | 17 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/stllike/cache.hpp | 7 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/stllike/lrucache_map.h | 2 |
3 files changed, 18 insertions, 8 deletions
diff --git a/vespalib/src/vespa/vespalib/stllike/cache.h b/vespalib/src/vespa/vespalib/stllike/cache.h index de4841f2284..b823d0001ea 100644 --- a/vespalib/src/vespa/vespalib/stllike/cache.h +++ b/vespalib/src/vespa/vespalib/stllike/cache.h @@ -2,6 +2,7 @@ #pragma once #include "lrucache_map.h" +#include <vespa/vespalib/util/memoryusage.h> #include <atomic> #include <mutex> @@ -63,7 +64,7 @@ public: * @maxBytes is the maximum limit of bytes the store can hold, before eviction starts. */ cache(BackingStore & b, size_t maxBytes); - ~cache(); + ~cache() override; /** * Can be used for controlling max number of elements. */ @@ -81,6 +82,8 @@ public: size_t sizeBytes() const { return _sizeBytes.load(std::memory_order_relaxed); } bool empty() const { return Lru::empty(); } + virtual MemoryUsage getStaticMemoryUsage() const; + /** * This simply erases the object. * This will also erase from backing store. @@ -151,9 +154,9 @@ private: v.store(v.load(std::memory_order_relaxed) + 1, std::memory_order_relaxed); } - Hash _hasher; - SizeK _sizeK; - SizeV _sizeV; + Hash _hasher; + SizeK _sizeK; + SizeV _sizeV; std::atomic<size_t> _maxBytes; std::atomic<size_t> _sizeBytes; mutable std::atomic<size_t> _hit; @@ -165,10 +168,10 @@ private: mutable std::atomic<size_t> _update; mutable std::atomic<size_t> _invalidate; mutable std::atomic<size_t> _lookup; - BackingStore & _store; - mutable std::mutex _hashLock; + BackingStore & _store; + mutable std::mutex _hashLock; /// Striped locks that can be used for having a locked access to the backing store. - std::mutex _addLocks[113]; + std::mutex _addLocks[113]; }; } diff --git a/vespalib/src/vespa/vespalib/stllike/cache.hpp b/vespalib/src/vespa/vespalib/stllike/cache.hpp index bb05d564f1f..9abd4a5e91f 100644 --- a/vespalib/src/vespa/vespalib/stllike/cache.hpp +++ b/vespalib/src/vespa/vespalib/stllike/cache.hpp @@ -63,6 +63,13 @@ cache<P>::cache(BackingStore & b, size_t maxBytes) : { } template< typename P > +MemoryUsage +cache<P>::getStaticMemoryUsage() const { + MemoryUsage usage; + return usage; +} + +template< typename P > bool cache<P>::removeOldest(const value_type & v) { bool remove(Lru::removeOldest(v) || (sizeBytes() >= capacityBytes())); diff --git a/vespalib/src/vespa/vespalib/stllike/lrucache_map.h b/vespalib/src/vespa/vespalib/stllike/lrucache_map.h index 6758b62d2c2..92667171e31 100644 --- a/vespalib/src/vespa/vespalib/stllike/lrucache_map.h +++ b/vespalib/src/vespa/vespalib/stllike/lrucache_map.h @@ -46,7 +46,6 @@ private: using HashTable = typename P::HashTable; using V = typename P::Value; using K = typename P::Key; - using value_type = typename P::value_type; using LV = typename P::LV; using internal_iterator = typename HashTable::iterator; using next_t = typename HashTable::next_t; @@ -55,6 +54,7 @@ protected: static constexpr size_t UNLIMITED = std::numeric_limits<size_t>::max(); public: using insert_result = typename HashTable::insert_result; + using value_type = typename P::value_type; class iterator { public: |