summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@yahooinc.com>2023-08-23 12:50:52 +0200
committerTor Egge <Tor.Egge@yahooinc.com>2023-08-23 12:50:52 +0200
commiteb47fc8942aedfa5d3e5256d25fb29757ba83372 (patch)
tree949bb738da6883c1f7571de5730a9ce7392aeb82 /vespalib
parent0b90f4fd3efc480d7fa2f46b037ccb6b3c5e13a9 (diff)
Estimate datastore stash memory usage instead of sampling it.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/datastore/datastorebase.cpp18
-rw-r--r--vespalib/src/vespa/vespalib/datastore/datastorebase.h2
2 files changed, 19 insertions, 1 deletions
diff --git a/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp b/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp
index 5c88900ae92..b5328134e4f 100644
--- a/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp
+++ b/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp
@@ -295,7 +295,7 @@ DataStoreBase::getMemoryUsage() const {
extra_used += _free_lists.size() * sizeof(FreeList);
usage.incAllocatedBytes(extra_allocated);
usage.incUsedBytes(extra_used);
- usage.merge(_stash.get_memory_usage());
+ merge_stash_memory_usage(usage);
return usage;
}
@@ -526,4 +526,20 @@ DataStoreBase::inc_hold_buffer_count()
++_hold_buffer_count;
}
+void
+DataStoreBase::merge_stash_memory_usage(vespalib::MemoryUsage& usage) const
+{
+ /*
+ * Estimate stash memory usage instead of sampling it to avoid race
+ * with writer thread.
+ */
+ uint32_t buffer_states = get_bufferid_limit_acquire();
+ size_t stashed_buffer_state_size = sizeof(BufferState) + sizeof(stash::DestructObject<BufferState>);
+ size_t chunk_size = _stash.get_chunk_size();
+ uint32_t buffer_states_per_chunk = (chunk_size - sizeof(stash::Chunk)) / stashed_buffer_state_size;
+ uint32_t chunks = (buffer_states + buffer_states_per_chunk - 1) / buffer_states_per_chunk;
+ usage.incAllocatedBytes(chunks * chunk_size);
+ usage.incUsedBytes(buffer_states * stashed_buffer_state_size + chunks * sizeof(stash::Chunk));
+}
+
}
diff --git a/vespalib/src/vespa/vespalib/datastore/datastorebase.h b/vespalib/src/vespa/vespalib/datastore/datastorebase.h
index b91d6c7cfa6..d7ae20a7028 100644
--- a/vespalib/src/vespa/vespalib/datastore/datastorebase.h
+++ b/vespalib/src/vespa/vespalib/datastore/datastorebase.h
@@ -261,6 +261,8 @@ private:
virtual void reclaim_all_entry_refs() = 0;
+ void merge_stash_memory_usage(vespalib::MemoryUsage& usage) const;
+
std::vector<BufferAndMeta> _buffers; // For fast mapping with known types
// Provides a mapping from typeId -> primary buffer for that type.