diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-06-22 12:47:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-22 12:47:29 +0200 |
commit | 93ca669d40868468a26f32b96bef90b088ef9e17 (patch) | |
tree | e5edce298dce7e5af519bcc07ab938fd5dbf30ae | |
parent | 67fe9c6d3ee4ec4ef07596f3da27b1e291a2189d (diff) | |
parent | 4ad0b1877788473d6e6cd004b3300dbe4e0e0147 (diff) |
Merge pull request #27509 from vespa-engine/balder/move-count-internal-strucures-cache-structures-correctly
Balder/move count internal strucures cache structures correctly
4 files changed, 51 insertions, 48 deletions
diff --git a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp index 2bf2a38b7e6..0d64683b4a6 100644 --- a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp +++ b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp @@ -565,7 +565,7 @@ TEST("Control static memory usage") { IDocumentStore &ds = vcs.getStore(); vespalib::MemoryUsage usage = ds.getMemoryUsage(); constexpr size_t mutex_size = sizeof(std::mutex) * 2 * (113 + 1); // sizeof(std::mutex) is platform dependent - EXPECT_EQUAL(74572 + mutex_size, usage.allocatedBytes()); + EXPECT_EQUAL(74668 + mutex_size, usage.allocatedBytes()); EXPECT_EQUAL(944u + mutex_size, usage.usedBytes()); } @@ -575,29 +575,29 @@ TEST("test the update cache strategy") { for (size_t i(1); i <= 10; i++) { vcs.write(i); } - TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 0, 0, 0)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 0, 0, 28)); vcs.verifyRead(7); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 1, 1, 221)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 1, 1, 241)); vcs.write(8); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 1, 1, 221)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 1, 1, 241)); vcs.write(7, 17); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 1, 1, 282)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 1, 1, 302)); vcs.verifyRead(7); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 1, 1, 1, 282)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 1, 1, 1, 302)); vcs.remove(8); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 1, 1, 1, 282)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 1, 1, 1, 302)); vcs.remove(7); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 1, 1, 0, 0)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 1, 1, 0, 28)); vcs.write(7); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 1, 1, 0, 0)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 1, 1, 0, 28)); vcs.verifyRead(7); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 1, 2, 1, 221)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 1, 2, 1, 241)); vcs.write(7, 17); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 1, 2, 1, 282)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 1, 2, 1, 302)); vcs.recreate(); IDocumentStore & ds2 = vcs.getStore(); vcs.verifyRead(7); - TEST_DO(verifyCacheStats(ds2.getCacheStats(), 0, 1, 1, 282)); + TEST_DO(verifyCacheStats(ds2.getCacheStats(), 0, 1, 1, 302)); } TEST("test the invalidate cache strategy") { @@ -606,23 +606,23 @@ TEST("test the invalidate cache strategy") { for (size_t i(1); i <= 10; i++) { vcs.write(i); } - TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 0, 0, 0)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 0, 0, 28)); vcs.verifyRead(7); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 1, 1, 221)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 1, 1, 241)); vcs.write(8); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 1, 1, 221)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 1, 1, 241)); vcs.write(7); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 1, 0, 0)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 1, 0, 28)); vcs.verifyRead(7); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 2, 1, 221)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 2, 1, 241)); vcs.remove(8); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 2, 1, 221)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 2, 1, 241)); vcs.remove(7); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 2, 0, 0)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 2, 0, 28)); vcs.write(7); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 2, 0, 0)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 2, 0, 28)); vcs.verifyRead(7); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 3, 1, 221)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 3, 1, 241)); } TEST("test that the integrated visit cache works.") { @@ -631,12 +631,12 @@ TEST("test that the integrated visit cache works.") { for (size_t i(1); i <= 100; i++) { vcs.write(i); } - TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 0, 0, 0)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 0, 0, 28)); for (size_t i(1); i <= 100; i++) { vcs.verifyRead(i); } - constexpr size_t BASE_SZ = 20594; + constexpr size_t BASE_SZ = 20602; TEST_DO(verifyCacheStats(ds.getCacheStats(), 0, 100, 100, BASE_SZ)); for (size_t i(1); i <= 100; i++) { vcs.verifyRead(i); @@ -646,32 +646,32 @@ TEST("test that the integrated visit cache works.") { vcs.verifyVisit({7,9,17,19,67,88}, false); TEST_DO(verifyCacheStats(ds.getCacheStats(), 100, 100, 100, BASE_SZ)); vcs.verifyVisit({7,9,17,19,67,88}, true); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 100, 101, 101, BASE_SZ+557)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 100, 101, 101, BASE_SZ+16)); vcs.verifyVisit({7,9,17,19,67,88}, true); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 101, 101, BASE_SZ+557)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 101, 101, BASE_SZ+16)); vcs.rewrite(8); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 101, 100, BASE_SZ+328)); // From the individual cache. + TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 101, 100, BASE_SZ-197)); // From the individual cache. vcs.rewrite(7); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 101, 98, BASE_SZ-442)); // From the both caches. + TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 101, 98, BASE_SZ-166)); // From the both caches. vcs.verifyVisit({7,9,17,19,67,88}, true); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 102, 99, BASE_SZ+130)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 102, 99, BASE_SZ-410)); vcs.verifyVisit({7,9,17,19,67,88,89}, true); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 103, 99, BASE_SZ+180)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 103, 99, BASE_SZ-406)); vcs.rewrite(17); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 103, 97, BASE_SZ-671)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 103, 97, BASE_SZ-391)); vcs.verifyVisit({7,9,17,19,67,88,89}, true); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 104, 98, BASE_SZ-20)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 104, 98, BASE_SZ-611)); vcs.remove(17); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 104, 97, BASE_SZ-671)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 104, 97, BASE_SZ-391)); vcs.verifyVisit({7,9,17,19,67,88,89}, {7,9,19,67,88,89}, true); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 105, 98, BASE_SZ-70)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 105, 98, BASE_SZ-611)); vcs.verifyVisit({41, 42}, true); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 106, 99, BASE_SZ+230)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 106, 99, BASE_SZ-611)); vcs.verifyVisit({43, 44}, true); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 107, 100, BASE_SZ+540)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 107, 100, BASE_SZ-611)); vcs.verifyVisit({41, 42, 43, 44}, true); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 108, 99, BASE_SZ+360)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 108, 99, BASE_SZ-611)); } TEST("testWriteRead") { diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp index b61cf49c438..322d0eb341b 100644 --- a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp +++ b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp @@ -165,6 +165,7 @@ public: CompressedBlobSet readSet(const KeySet & keys); void removeKey(uint32_t key); vespalib::MemoryUsage getStaticMemoryUsage() const override; + CacheStats get_stats() const override; private: void locateAndInvalidateOtherSubsets(const UniqueLock & cacheGuard, const KeySet & keys); using IdSet = vespalib::hash_set<uint64_t>; @@ -267,7 +268,8 @@ VisitCache::remove(uint32_t key) { CacheStats VisitCache::getCacheStats() const { - return _cache->get_stats(); + CacheStats stats = _cache->get_stats(); + return stats; } VisitCache::Cache::Cache(BackingStore & b, size_t maxBytes) : @@ -306,19 +308,22 @@ 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.incUsedBytes(_lid2Id.size() * sizeof(LidUniqueKeySetId::value_type)); - usage.incUsedBytes(_id2KeySet.size() * sizeof(IdKeySetMap::value_type)); + return usage; +} + +CacheStats +VisitCache::Cache::get_stats() const { + CacheStats stats = Parent::get_stats(); + auto cacheGuard = getGuard(); + stats.memory_used += _lid2Id.capacity() * sizeof(LidUniqueKeySetId::value_type); + stats.memory_used += _id2KeySet.capacity() * 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)); + stats.memory_used = entry.second.getKeys().capacity() * sizeof(uint32_t); } - return usage; + return stats; } } diff --git a/vespalib/src/vespa/vespalib/stllike/cache.h b/vespalib/src/vespa/vespalib/stllike/cache.h index f7456cda197..97ba23aba65 100644 --- a/vespalib/src/vespa/vespalib/stllike/cache.h +++ b/vespalib/src/vespa/vespalib/stllike/cache.h @@ -110,7 +110,7 @@ public: */ bool hasKey(const K & key) const; - CacheStats get_stats() const; + virtual CacheStats get_stats() const; size_t getHit() const { return _hit.load(std::memory_order_relaxed); } size_t getMiss() const { return _miss.load(std::memory_order_relaxed); } diff --git a/vespalib/src/vespa/vespalib/stllike/cache.hpp b/vespalib/src/vespa/vespalib/stllike/cache.hpp index 4e7736c9e5f..f767cf9812c 100644 --- a/vespalib/src/vespa/vespalib/stllike/cache.hpp +++ b/vespalib/src/vespa/vespalib/stllike/cache.hpp @@ -61,9 +61,7 @@ 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; } |