diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-03-09 14:10:14 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-03-09 14:10:58 +0000 |
commit | 414f81bdd8fa59944f79d86b9ca7c03d1e4080f4 (patch) | |
tree | df92895f93a0446ff6ed1ee410af434916e5e449 /vespalib/src | |
parent | 435af93308d985ec4c503d3789a6d48f923dd60a (diff) |
Report more of the static memory usage for datastores.
Diffstat (limited to 'vespalib/src')
8 files changed, 64 insertions, 41 deletions
diff --git a/vespalib/src/tests/btree/btree_test.cpp b/vespalib/src/tests/btree/btree_test.cpp index 2a465f2c60a..ef64549e16a 100644 --- a/vespalib/src/tests/btree/btree_test.cpp +++ b/vespalib/src/tests/btree/btree_test.cpp @@ -1064,6 +1064,7 @@ adjustAllocatedBytes(size_t nodeCount, size_t nodeSize) TEST_F(BTreeTest, require_that_memory_usage_is_calculated) { + constexpr size_t BASE = 163912; typedef BTreeNodeAllocator<int32_t, int8_t, btree::NoAggregated, MyTraits::INTERNAL_SLOTS, MyTraits::LEAF_SLOTS> NodeAllocator; @@ -1082,6 +1083,8 @@ TEST_F(BTreeTest, require_that_memory_usage_is_calculated) const uint32_t initialLeafNodes = 128u; mu.incAllocatedBytes(adjustAllocatedBytes(initialInternalNodes, sizeof(INode))); mu.incAllocatedBytes(adjustAllocatedBytes(initialLeafNodes, sizeof(LNode))); + mu.incAllocatedBytes(BASE); + mu.incUsedBytes(BASE); mu.incUsedBytes(sizeof(INode)); mu.incDeadBytes(sizeof(INode)); EXPECT_TRUE(assertMemoryUsage(mu, tm.getMemoryUsage())); @@ -1112,6 +1115,8 @@ TEST_F(BTreeTest, require_that_memory_usage_is_calculated) mu = vespalib::MemoryUsage(); mu.incAllocatedBytes(adjustAllocatedBytes(initialInternalNodes, sizeof(INode))); mu.incAllocatedBytes(adjustAllocatedBytes(initialLeafNodes, sizeof(LNode))); + mu.incAllocatedBytes(BASE); + mu.incUsedBytes(BASE); mu.incUsedBytes(sizeof(INode) * 2); mu.incDeadBytes(sizeof(INode) * 2); mu.incUsedBytes(sizeof(LNode)); diff --git a/vespalib/src/tests/datastore/array_store/array_store_test.cpp b/vespalib/src/tests/datastore/array_store/array_store_test.cpp index 063ac445933..3ebe8fdba1a 100644 --- a/vespalib/src/tests/datastore/array_store/array_store_test.cpp +++ b/vespalib/src/tests/datastore/array_store/array_store_test.cpp @@ -218,8 +218,8 @@ TEST_P(NumberStoreTest, control_static_sizes) { #endif EXPECT_EQ(112u, sizeof(NumberStoreTest::ArrayStoreType::SmallBufferType)); MemoryUsage usage = store.getMemoryUsage(); - EXPECT_EQ(960u, usage.allocatedBytes()); - EXPECT_EQ(32u, usage.usedBytes()); + EXPECT_EQ(1312160u, usage.allocatedBytes()); + EXPECT_EQ(1311232u, usage.usedBytes()); } TEST_P(NumberStoreTest, add_and_get_small_arrays_of_trivial_type) diff --git a/vespalib/src/tests/datastore/datastore/datastore_test.cpp b/vespalib/src/tests/datastore/datastore/datastore_test.cpp index bffd32816a4..794be39ae9b 100644 --- a/vespalib/src/tests/datastore/datastore/datastore_test.cpp +++ b/vespalib/src/tests/datastore/datastore/datastore_test.cpp @@ -474,6 +474,7 @@ TEST(DataStoreTest, require_that_memory_stats_are_calculated) TEST(DataStoreTest, require_that_memory_usage_is_calculated) { + constexpr size_t BASE = 676; MyStore s; MyRef r = s.addEntry(10); s.addEntry(20); @@ -482,8 +483,8 @@ TEST(DataStoreTest, require_that_memory_usage_is_calculated) s.holdBuffer(r.bufferId()); s.assign_generation(100); vespalib::MemoryUsage m = s.getMemoryUsage(); - EXPECT_EQ(MyRef::offsetSize() * sizeof(int), m.allocatedBytes()); - EXPECT_EQ(5 * sizeof(int), m.usedBytes()); + EXPECT_EQ(MyRef::offsetSize() * sizeof(int) + BASE, m.allocatedBytes()); + EXPECT_EQ(5 * sizeof(int) + BASE, m.usedBytes()); EXPECT_EQ(0 * sizeof(int), m.deadBytes()); EXPECT_EQ(5 * sizeof(int), m.allocatedBytesOnHold()); s.reclaim_memory(101); @@ -491,27 +492,28 @@ TEST(DataStoreTest, require_that_memory_usage_is_calculated) TEST(DataStoreTest, require_that_we_can_disable_elemement_hold_list) { + constexpr size_t BASE = 676; MyStore s; MyRef r1 = s.addEntry(10); MyRef r2 = s.addEntry(20); MyRef r3 = s.addEntry(30); (void) r3; vespalib::MemoryUsage m = s.getMemoryUsage(); - EXPECT_EQ(MyRef::offsetSize() * sizeof(int), m.allocatedBytes()); - EXPECT_EQ(4 * sizeof(int), m.usedBytes()); + EXPECT_EQ(MyRef::offsetSize() * sizeof(int) + BASE, m.allocatedBytes()); + EXPECT_EQ(4 * sizeof(int) + BASE, m.usedBytes()); EXPECT_EQ(1 * sizeof(int), m.deadBytes()); EXPECT_EQ(0 * sizeof(int), m.allocatedBytesOnHold()); s.holdElem(r1, 1); m = s.getMemoryUsage(); - EXPECT_EQ(MyRef::offsetSize() * sizeof(int), m.allocatedBytes()); - EXPECT_EQ(4 * sizeof(int), m.usedBytes()); + EXPECT_EQ(MyRef::offsetSize() * sizeof(int) + BASE, m.allocatedBytes()); + EXPECT_EQ(4 * sizeof(int) + BASE, m.usedBytes()); EXPECT_EQ(1 * sizeof(int), m.deadBytes()); EXPECT_EQ(1 * sizeof(int), m.allocatedBytesOnHold()); s.disableElemHoldList(); s.holdElem(r2, 1); m = s.getMemoryUsage(); - EXPECT_EQ(MyRef::offsetSize() * sizeof(int), m.allocatedBytes()); - EXPECT_EQ(4 * sizeof(int), m.usedBytes()); + EXPECT_EQ(MyRef::offsetSize() * sizeof(int) + BASE, m.allocatedBytes()); + EXPECT_EQ(4 * sizeof(int) + BASE, m.usedBytes()); EXPECT_EQ(2 * sizeof(int), m.deadBytes()); EXPECT_EQ(1 * sizeof(int), m.allocatedBytesOnHold()); s.assign_generation(100); @@ -536,30 +538,31 @@ void assertGrowStats(GrowthStats expSizes, TEST(DataStoreTest, require_that_buffer_growth_works) { + constexpr size_t BASE = 41032u; // Always switch to new buffer, min size 4 assertGrowStats({ 4, 4, 4, 4, 8, 16, 16, 32, 64, 64 }, - { 4 }, 20, 4, 0); + { 4 }, 20 + BASE, 4, 0); // Resize if buffer size is less than 4, min size 0 assertGrowStats({ 4, 4, 8, 32, 32, 64, 64, 128, 128, 128 }, - { 0, 1, 2, 4 }, 4, 0, 4); + { 0, 1, 2, 4 }, 4 + BASE, 0, 4); // Always switch to new buffer, min size 16 assertGrowStats({ 16, 16, 16, 32, 32, 64, 128, 128, 128 }, - { 16 }, 68, 16, 0); + { 16 }, 68 + BASE, 16, 0); // Resize if buffer size is less than 16, min size 0 assertGrowStats({ 16, 32, 32, 128, 128, 128, 128, 128, 128 }, - { 0, 1, 2, 4, 8, 16 }, 4, 0, 16); + { 0, 1, 2, 4, 8, 16 }, 4 + BASE, 0, 16); // Resize if buffer size is less than 16, min size 4 assertGrowStats({ 16, 32, 32, 128, 128, 128, 128, 128, 128 }, - { 4, 8, 16 }, 20, 4, 16); + { 4, 8, 16 }, 20 + BASE, 4, 16); // Always switch to new buffer, min size 0 assertGrowStats({ 1, 1, 1, 1, 1, 2, 2, 4, 8, 8, 16, 32 }, - { 0, 1 }, 4, 0, 0); + { 0, 1 }, 4 + BASE, 0, 0); // Buffers with sizes larger than the huge page size of the mmap allocator. ASSERT_EQ(524288u, HUGE_PAGE_ARRAY_SIZE); assertGrowStats({ 262144, 524288, 524288, 524288 * 3, 524288 * 3, 524288 * 5, 524288 * 5, 524288 * 5, 524288 * 5, 524288 * 5 }, { 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144 }, - 4, 0, HUGE_PAGE_ARRAY_SIZE / 2, HUGE_PAGE_ARRAY_SIZE * 5); + 4 + BASE, 0, HUGE_PAGE_ARRAY_SIZE / 2, HUGE_PAGE_ARRAY_SIZE * 5); } using RefType15 = EntryRefT<15>; // offsetSize=32768 diff --git a/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp b/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp index 40920a8ca1b..cf62d238d53 100644 --- a/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp +++ b/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp @@ -472,10 +472,12 @@ TEST_F(DoubleTest, nan_is_handled) TEST_F(DoubleTest, control_memory_usage) { EXPECT_EQ(464, sizeof(store)); EXPECT_EQ(144u, sizeof(BufferState)); - EXPECT_EQ(32u, store.get_values_memory_usage().allocatedBytes()); - EXPECT_EQ(98208u, store.get_dictionary_memory_usage().allocatedBytes()); - EXPECT_EQ(98240u, store.getMemoryUsage().allocatedBytes()); - EXPECT_EQ(280u, store.getMemoryUsage().usedBytes()); + EXPECT_EQ(163908u, store.get_values_memory_usage().allocatedBytes()); + EXPECT_EQ(163892u, store.get_values_memory_usage().usedBytes()); + EXPECT_EQ(262120u, store.get_dictionary_memory_usage().allocatedBytes()); + EXPECT_EQ(164176u, store.get_dictionary_memory_usage().usedBytes()); + EXPECT_EQ(426028u, store.getMemoryUsage().allocatedBytes()); + EXPECT_EQ(328068u, store.getMemoryUsage().usedBytes()); } GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/vespa/vespalib/datastore/array_store.h b/vespalib/src/vespa/vespalib/datastore/array_store.h index d0ac6a216db..43bd469fca4 100644 --- a/vespalib/src/vespa/vespalib/datastore/array_store.h +++ b/vespalib/src/vespa/vespalib/datastore/array_store.h @@ -42,14 +42,14 @@ public: using SmallBufferType = typename TypeMapperT::SmallBufferType; using TypeMapper = TypeMapperT; private: - uint32_t _largeArrayTypeId; - uint32_t _maxSmallArrayTypeId; - size_t _maxSmallArraySize; - DataStoreType _store; - TypeMapper _mapper; + uint32_t _largeArrayTypeId; + uint32_t _maxSmallArrayTypeId; + size_t _maxSmallArraySize; + DataStoreType _store; + TypeMapper _mapper; std::vector<SmallBufferType> _smallArrayTypes; - LargeBufferType _largeArrayType; - CompactionSpec _compaction_spec; + LargeBufferType _largeArrayType; + CompactionSpec _compaction_spec; using generation_t = vespalib::GenerationHandler::generation_t; void initArrayTypes(const ArrayStoreConfig &cfg, std::shared_ptr<alloc::MemoryAllocator> memory_allocator); diff --git a/vespalib/src/vespa/vespalib/datastore/array_store.hpp b/vespalib/src/vespa/vespalib/datastore/array_store.hpp index a0fdf3f6563..64aed0bd541 100644 --- a/vespalib/src/vespa/vespalib/datastore/array_store.hpp +++ b/vespalib/src/vespa/vespalib/datastore/array_store.hpp @@ -59,9 +59,9 @@ ArrayStore<EntryT, RefT, TypeMapperT>::ArrayStore(const ArrayStoreConfig &cfg, s template <typename EntryT, typename RefT, typename TypeMapperT> vespalib::MemoryUsage ArrayStore<EntryT, RefT, TypeMapperT>::getMemoryUsage() const { - vespalib::MemoryUsage usage = _store.getMemoryUsage(); - //TODO Must be accounted - // usage.incAllocatedBytes(_smallArrayTypes.capacity() * sizeof(SmallBufferType)); + vespalib::MemoryUsage usage = _store.getMemoryUsage(); + usage.incAllocatedBytes(_smallArrayTypes.capacity() * sizeof(SmallBufferType)); + usage.incUsedBytes(_smallArrayTypes.size() * sizeof(SmallBufferType)); return usage; } diff --git a/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp b/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp index 6bf5f4c16c4..42234194040 100644 --- a/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp +++ b/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp @@ -258,18 +258,9 @@ DataStoreBase::dropBuffers() } vespalib::MemoryUsage -DataStoreBase::getMemoryUsage() const +DataStoreBase::getDynamicMemoryUsage() const { auto stats = getMemStats(); - - size_t extra = 0; - extra += _buffers.capacity() * sizeof(BufferAndTypeId); - extra += _primary_buffer_ids.capacity() * sizeof(uint32_t); - extra += _states.capacity() * sizeof(BufferState); - extra += _typeHandlers.capacity() * sizeof(BufferTypeBase *); - extra += _free_lists.capacity() * sizeof(FreeList); - (void) extra; //TODO Must be accounted as static cost - vespalib::MemoryUsage usage; usage.setAllocatedBytes(stats._allocBytes); usage.setUsedBytes(stats._usedBytes); @@ -278,6 +269,27 @@ DataStoreBase::getMemoryUsage() const return usage; } +vespalib::MemoryUsage +DataStoreBase::getMemoryUsage() const { + auto usage = getDynamicMemoryUsage(); + size_t extra_allocated = 0; + extra_allocated += _buffers.capacity() * sizeof(BufferAndTypeId); + extra_allocated += _primary_buffer_ids.capacity() * sizeof(uint32_t); + extra_allocated += _states.capacity() * sizeof(BufferState); + extra_allocated += _typeHandlers.capacity() * sizeof(BufferTypeBase *); + extra_allocated += _free_lists.capacity() * sizeof(FreeList); + + size_t extra_used = 0; + extra_used += _buffers.size() * sizeof(BufferAndTypeId); + extra_used += _primary_buffer_ids.size() * sizeof(uint32_t); + extra_used += _states.size() * sizeof(BufferState); + extra_used += _typeHandlers.size() * sizeof(BufferTypeBase *); + extra_used += _free_lists.size() * sizeof(FreeList); + usage.incAllocatedBytes(extra_allocated); + usage.incUsedBytes(extra_used); + return usage; +} + void DataStoreBase::holdBuffer(uint32_t bufferId) { diff --git a/vespalib/src/vespa/vespalib/datastore/datastorebase.h b/vespalib/src/vespa/vespalib/datastore/datastorebase.h index 16426218d47..950e1967ee2 100644 --- a/vespalib/src/vespa/vespalib/datastore/datastorebase.h +++ b/vespalib/src/vespa/vespalib/datastore/datastorebase.h @@ -65,6 +65,7 @@ public: void switch_primary_buffer(uint32_t typeId, size_t elemsNeeded); vespalib::MemoryUsage getMemoryUsage() const; + vespalib::MemoryUsage getDynamicMemoryUsage() const; vespalib::AddressSpace getAddressSpaceUsage() const; |