aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-03-14 12:04:30 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-03-14 12:04:30 +0000
commit28ab766a23032cf35c3a124007775712a4fd033e (patch)
tree65e49381b94f291c756e3dc6ee01ad168a84f18a
parentb148d50f3d2bd2711b06618653f277bf84b1eec8 (diff)
Wire in and test static memory usage for caches.
-rw-r--r--searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp32
-rw-r--r--searchlib/src/vespa/searchlib/docstore/documentstore.cpp5
-rw-r--r--searchlib/src/vespa/searchlib/docstore/visitcache.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/docstore/visitcache.h4
-rw-r--r--vespalib/src/vespa/vespalib/stllike/cache.h17
-rw-r--r--vespalib/src/vespa/vespalib/stllike/cache.hpp7
-rw-r--r--vespalib/src/vespa/vespalib/stllike/lrucache_map.h2
7 files changed, 51 insertions, 22 deletions
diff --git a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp
index 687f3624b44..c496472bdfa 100644
--- a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp
+++ b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp
@@ -497,20 +497,20 @@ private:
}
bool allowVisitCaching() const override { return _allowVisitCaching; }
private:
- VisitCacheStore &_vcs;
- vespalib::hash_set<uint32_t> _expected;
- vespalib::hash_set<uint32_t> _actual;
- bool _allowVisitCaching;
+ VisitCacheStore &_vcs;
+ vespalib::hash_set<uint32_t> _expected;
+ vespalib::hash_set<uint32_t> _actual;
+ bool _allowVisitCaching;
};
- DirectoryHandler _myDir;
- document::DocumentTypeRepo _repo;
- LogDocumentStore::Config _config;
- DummyFileHeaderContext _fileHeaderContext;
- vespalib::ThreadStackExecutor _executor;
- MyTlSyncer _tlSyncer;
+ DirectoryHandler _myDir;
+ document::DocumentTypeRepo _repo;
+ LogDocumentStore::Config _config;
+ DummyFileHeaderContext _fileHeaderContext;
+ vespalib::ThreadStackExecutor _executor;
+ MyTlSyncer _tlSyncer;
std::unique_ptr<LogDocumentStore> _datastore;
- std::map<uint32_t, Document::UP> _inserted;
- SerialNum _serial;
+ std::map<uint32_t, Document::UP> _inserted;
+ SerialNum _serial;
};
VisitCacheStore::VerifyVisitor::VerifyVisitor(VisitCacheStore & vcs, std::vector<uint32_t> lids, bool allowCaching)
@@ -560,6 +560,14 @@ verifyCacheStats(CacheStats cs, size_t hits, size_t misses, size_t elements, siz
EXPECT_GREATER_EQUAL(memory_used+20, cs.memory_used);
}
+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());
+}
+
TEST("test the update cache strategy") {
VisitCacheStore vcs(DocumentStore::Config::UpdateStrategy::UPDATE);
IDocumentStore & ds = vcs.getStore();
diff --git a/searchlib/src/vespa/searchlib/docstore/documentstore.cpp b/searchlib/src/vespa/searchlib/docstore/documentstore.cpp
index 1e04b7c61db..368dd31678d 100644
--- a/searchlib/src/vespa/searchlib/docstore/documentstore.cpp
+++ b/searchlib/src/vespa/searchlib/docstore/documentstore.cpp
@@ -428,7 +428,10 @@ DocumentStore::getStorageStats() const
vespalib::MemoryUsage
DocumentStore::getMemoryUsage() const
{
- return _backingStore.getMemoryUsage();
+ vespalib::MemoryUsage usage = _backingStore.getMemoryUsage();
+ usage.merge(_cache->getStaticMemoryUsage());
+ usage.merge(_visitCache->getStaticMemoryUsage());
+ return usage;
}
std::vector<DataStoreFileChunkStats>
diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp
index 60c08c281df..d7c1a400b1e 100644
--- a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp
+++ b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp
@@ -259,4 +259,10 @@ VisitCache::Cache::onRemove(const K & key) {
_id2KeySet.erase(key.getKeys().front());
}
+vespalib::MemoryUsage
+VisitCache::Cache::getStaticMemoryUsage() const {
+ vespalib::MemoryUsage usage = Parent::getStaticMemoryUsage();
+ return usage;
+}
+
}
diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.h b/searchlib/src/vespa/searchlib/docstore/visitcache.h
index 9a07c0ceab2..baa594b8d28 100644
--- a/searchlib/src/vespa/searchlib/docstore/visitcache.h
+++ b/searchlib/src/vespa/searchlib/docstore/visitcache.h
@@ -104,6 +104,7 @@ public:
void invalidate(uint32_t key) { remove(key); }
vespalib::CacheStats getCacheStats() const;
+ vespalib::MemoryUsage getStaticMemoryUsage() const { return _cache->getStaticMemoryUsage(); }
void reconfigure(size_t cacheSize, CompressionConfig compression);
private:
/**
@@ -144,9 +145,10 @@ private:
class Cache : public vespalib::cache<CacheParams> {
public:
Cache(BackingStore & b, size_t maxBytes);
- ~Cache();
+ ~Cache() override;
CompressedBlobSet readSet(const KeySet & keys);
void removeKey(uint32_t key);
+ vespalib::MemoryUsage getStaticMemoryUsage() const override;
private:
void locateAndInvalidateOtherSubsets(const UniqueLock & cacheGuard, const KeySet & keys);
using IdSet = vespalib::hash_set<uint64_t>;
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: