diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-03-14 12:34:58 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-03-14 12:34:58 +0000 |
commit | 1e0598be29be3f42809ea84303129ffe2301ef3c (patch) | |
tree | e960be7ae2c0bfb46e2cba75936244c8f5d0702a | |
parent | 28ab766a23032cf35c3a124007775712a4fd033e (diff) |
Track static cache usage
4 files changed, 21 insertions, 4 deletions
diff --git a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp index c496472bdfa..a552573470e 100644 --- a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp +++ b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp @@ -564,8 +564,8 @@ TEST("Control static memory usage") { VisitCacheStore vcs(DocumentStore::Config::UpdateStrategy::UPDATE); IDocumentStore &ds = vcs.getStore(); vespalib::MemoryUsage usage = ds.getMemoryUsage(); - EXPECT_EQUAL(74116u, usage.allocatedBytes()); - EXPECT_EQUAL(392u, usage.usedBytes()); + EXPECT_EQUAL(83700u, usage.allocatedBytes()); + EXPECT_EQUAL(10072u, usage.usedBytes()); } TEST("test the update cache strategy") { diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp index d7c1a400b1e..dcd38d1fd04 100644 --- a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp +++ b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp @@ -262,6 +262,18 @@ VisitCache::Cache::onRemove(const K & key) { vespalib::MemoryUsage VisitCache::Cache::getStaticMemoryUsage() const { vespalib::MemoryUsage usage = Parent::getStaticMemoryUsage(); + auto cacheGuard = getGuard(); + size_t baseSelf = sizeof(_lid2Id) + sizeof(_id2KeySet); + usage.incAllocatedBytes(baseSelf); + usage.incAllocatedBytes(_lid2Id.capacity() * sizeof(LidUniqueKeySetId::value_type)); + usage.incAllocatedBytes(_id2KeySet.capacity() * sizeof(IdKeySetMap::value_type)); + usage.incUsedBytes(baseSelf); + usage.incAllocatedBytes(_lid2Id.size() * sizeof(LidUniqueKeySetId::value_type)); + usage.incUsedBytes(_id2KeySet.size() * sizeof(IdKeySetMap::value_type)); + for (const auto & entry: _id2KeySet) { + usage.incAllocatedBytes(entry.second.getKeys().capacity() * sizeof(uint32_t)); + usage.incUsedBytes(entry.second.getKeys().size() * sizeof(uint32_t)); + } return usage; } diff --git a/vespalib/src/vespa/vespalib/stllike/cache.h b/vespalib/src/vespa/vespalib/stllike/cache.h index b823d0001ea..907fbdd54c9 100644 --- a/vespalib/src/vespa/vespalib/stllike/cache.h +++ b/vespalib/src/vespa/vespalib/stllike/cache.h @@ -127,7 +127,7 @@ public: protected: using UniqueLock = std::unique_lock<std::mutex>; - UniqueLock getGuard(); + UniqueLock getGuard() const; void invalidate(const UniqueLock & guard, const K & key); bool hasKey(const UniqueLock & guard, const K & key) const; private: diff --git a/vespalib/src/vespa/vespalib/stllike/cache.hpp b/vespalib/src/vespa/vespalib/stllike/cache.hpp index 9abd4a5e91f..8e449fcfca4 100644 --- a/vespalib/src/vespa/vespalib/stllike/cache.hpp +++ b/vespalib/src/vespa/vespalib/stllike/cache.hpp @@ -66,6 +66,11 @@ template< typename P > MemoryUsage cache<P>::getStaticMemoryUsage() const { MemoryUsage usage; + auto cacheGuard = getGuard(); + usage.incAllocatedBytes(sizeof(*this)); + usage.incAllocatedBytes(Lru::capacity()*sizeof(typename Lru::value_type)); + usage.incUsedBytes(sizeof(*this)); + usage.incUsedBytes(Lru::size()*sizeof(typename Lru::value_type)); return usage; } @@ -81,7 +86,7 @@ cache<P>::removeOldest(const value_type & v) { template< typename P > std::unique_lock<std::mutex> -cache<P>::getGuard() { +cache<P>::getGuard() const { return UniqueLock(_hashLock); } |