diff options
author | Tor Egge <Tor.Egge@online.no> | 2023-06-13 11:53:09 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2023-06-13 11:53:09 +0200 |
commit | c0c082863d6d0dd9f061cc1221a2da91d667c471 (patch) | |
tree | 0ebabe9b64564b4614dff1e34c7071c0ca7aa656 | |
parent | 982a3ae1a01cde9844e9bbbbd85865b9d3daa98c (diff) |
Store entry size in BufferTypeBase.
7 files changed, 33 insertions, 30 deletions
diff --git a/searchlib/src/tests/attribute/attribute_test.cpp b/searchlib/src/tests/attribute/attribute_test.cpp index 3a1a5b457ef..870562355d1 100644 --- a/searchlib/src/tests/attribute/attribute_test.cpp +++ b/searchlib/src/tests/attribute/attribute_test.cpp @@ -1089,8 +1089,8 @@ AttributeTest::testArray() { AttributePtr ptr = createAttribute("a-int32", Config(BasicType::INT32, CollectionType::ARRAY)); ptr->updateStat(true); - EXPECT_EQ(487480u, ptr->getStatus().getAllocated()); - EXPECT_EQ(479720u, ptr->getStatus().getUsed()); + EXPECT_EQ(495664u, ptr->getStatus().getAllocated()); + EXPECT_EQ(487904u, ptr->getStatus().getUsed()); addDocs(ptr, numDocs); testArray<IntegerAttribute, AttributeVector::largeint_t>(ptr, values); } @@ -1099,8 +1099,8 @@ AttributeTest::testArray() cfg.setFastSearch(true); AttributePtr ptr = createAttribute("flags", cfg); ptr->updateStat(true); - EXPECT_EQ(487480u, ptr->getStatus().getAllocated()); - EXPECT_EQ(479720u, ptr->getStatus().getUsed()); + EXPECT_EQ(495664u, ptr->getStatus().getAllocated()); + EXPECT_EQ(487904u, ptr->getStatus().getUsed()); addDocs(ptr, numDocs); testArray<IntegerAttribute, AttributeVector::largeint_t>(ptr, values); } @@ -1109,8 +1109,8 @@ AttributeTest::testArray() cfg.setFastSearch(true); AttributePtr ptr = createAttribute("a-fs-int32", cfg); ptr->updateStat(true); - EXPECT_EQ(844116u, ptr->getStatus().getAllocated()); - EXPECT_EQ(581372u, ptr->getStatus().getUsed()); + EXPECT_EQ(852300u, ptr->getStatus().getAllocated()); + EXPECT_EQ(589556u, ptr->getStatus().getUsed()); addDocs(ptr, numDocs); testArray<IntegerAttribute, AttributeVector::largeint_t>(ptr, values); } @@ -1128,8 +1128,8 @@ AttributeTest::testArray() cfg.setFastSearch(true); AttributePtr ptr = createAttribute("a-fs-float", cfg); ptr->updateStat(true); - EXPECT_EQ(844116u, ptr->getStatus().getAllocated()); - EXPECT_EQ(581372u, ptr->getStatus().getUsed()); + EXPECT_EQ(852300u, ptr->getStatus().getAllocated()); + EXPECT_EQ(589556u, ptr->getStatus().getUsed()); addDocs(ptr, numDocs); testArray<FloatingPointAttribute, double>(ptr, values); } @@ -1140,8 +1140,8 @@ AttributeTest::testArray() { AttributePtr ptr = createAttribute("a-string", Config(BasicType::STRING, CollectionType::ARRAY)); ptr->updateStat(true); - EXPECT_EQ(599784u + sizeof_large_string_entry, ptr->getStatus().getAllocated()); - EXPECT_EQ(532564u + sizeof_large_string_entry, ptr->getStatus().getUsed()); + EXPECT_EQ(607968u + sizeof_large_string_entry, ptr->getStatus().getAllocated()); + EXPECT_EQ(540748u + sizeof_large_string_entry, ptr->getStatus().getUsed()); addDocs(ptr, numDocs); testArray<StringAttribute, string>(ptr, values); } @@ -1150,8 +1150,8 @@ AttributeTest::testArray() cfg.setFastSearch(true); AttributePtr ptr = createAttribute("afs-string", cfg); ptr->updateStat(true); - EXPECT_EQ(849992u + sizeof_large_string_entry, ptr->getStatus().getAllocated()); - EXPECT_EQ(584296u + sizeof_large_string_entry, ptr->getStatus().getUsed()); + EXPECT_EQ(858176u + sizeof_large_string_entry, ptr->getStatus().getAllocated()); + EXPECT_EQ(592480u + sizeof_large_string_entry, ptr->getStatus().getUsed()); addDocs(ptr, numDocs); testArray<StringAttribute, string>(ptr, values); } 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 ba6782334bd..37d5fc66c8b 100644 --- a/vespalib/src/tests/datastore/array_store/array_store_test.cpp +++ b/vespalib/src/tests/datastore/array_store/array_store_test.cpp @@ -218,12 +218,12 @@ INSTANTIATE_TEST_SUITE_P(NumberStoreFreeListsDisabledMultiTest, TEST_P(NumberStoreTest, control_static_sizes) { static constexpr size_t sizeof_deque = vespalib::datastore::DataStoreBase::sizeof_entry_ref_hold_list_deque; - EXPECT_EQ(408u + sizeof_deque, sizeof(store)); + EXPECT_EQ(416u + sizeof_deque, sizeof(store)); EXPECT_EQ(240u + sizeof_deque, sizeof(NumberStoreTest::ArrayStoreType::DataStoreType)); - EXPECT_EQ(104u, sizeof(NumberStoreTest::ArrayStoreType::SmallBufferType)); + EXPECT_EQ(112u, sizeof(NumberStoreTest::ArrayStoreType::SmallBufferType)); MemoryUsage usage = store.getMemoryUsage(); - EXPECT_EQ(202116u, usage.allocatedBytes()); - EXPECT_EQ(197656u, usage.usedBytes()); + EXPECT_EQ(202140u, usage.allocatedBytes()); + EXPECT_EQ(197680u, 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 fb7a38aacb6..e31a6b1d3b0 100644 --- a/vespalib/src/tests/datastore/datastore/datastore_test.cpp +++ b/vespalib/src/tests/datastore/datastore/datastore_test.cpp @@ -665,7 +665,7 @@ TEST(DataStoreTest, can_reuse_active_buffer_as_primary_buffer) } TEST(DataStoreTest, control_static_sizes) { - EXPECT_EQ(88, sizeof(BufferTypeBase)); + EXPECT_EQ(96, sizeof(BufferTypeBase)); EXPECT_EQ(24, sizeof(FreeList)); EXPECT_EQ(48, sizeof(BufferFreeList)); EXPECT_EQ(1, sizeof(BufferState::State)); 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 a09a7213bf5..a9826a71091 100644 --- a/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp +++ b/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp @@ -464,7 +464,7 @@ TEST_F(DoubleTest, nan_is_handled) TEST_F(DoubleTest, control_memory_usage) { static constexpr size_t sizeof_deque = vespalib::datastore::DataStoreBase::sizeof_entry_ref_hold_list_deque; - EXPECT_EQ(368u + sizeof_deque, sizeof(store)); + EXPECT_EQ(376u + sizeof_deque, sizeof(store)); EXPECT_EQ(120u, sizeof(BufferState)); EXPECT_EQ(28740u, store.get_values_memory_usage().allocatedBytes()); EXPECT_EQ(24780u, store.get_values_memory_usage().usedBytes()); diff --git a/vespalib/src/vespa/vespalib/datastore/buffer_type.cpp b/vespalib/src/vespa/vespalib/datastore/buffer_type.cpp index 0d43ede9e62..bb34c5d0f9d 100644 --- a/vespalib/src/vespa/vespalib/datastore/buffer_type.cpp +++ b/vespalib/src/vespa/vespalib/datastore/buffer_type.cpp @@ -26,12 +26,14 @@ BufferTypeBase::CleanContext::extraBytesCleaned(size_t value) _extraHoldBytes.store(extra_hold_bytes - value, std::memory_order_relaxed); } -BufferTypeBase::BufferTypeBase(uint32_t arraySize, +BufferTypeBase::BufferTypeBase(uint32_t entry_size_in, + uint32_t arraySize, uint32_t min_entries, uint32_t max_entries, uint32_t num_entries_for_new_buffer, float allocGrowFactor) noexcept - : _arraySize(arraySize), + : _entry_size(entry_size_in), + _arraySize(arraySize), _min_entries(std::min(min_entries, max_entries)), _max_entries(max_entries), _num_entries_for_new_buffer(std::min(num_entries_for_new_buffer, max_entries)), @@ -43,10 +45,11 @@ BufferTypeBase::BufferTypeBase(uint32_t arraySize, { } -BufferTypeBase::BufferTypeBase(uint32_t arraySize, +BufferTypeBase::BufferTypeBase(uint32_t entry_size_in, + uint32_t arraySize, uint32_t min_entries, uint32_t max_entries) noexcept - : BufferTypeBase(arraySize, min_entries, max_entries, 0u, DEFAULT_ALLOC_GROW_FACTOR) + : BufferTypeBase(entry_size_in, arraySize, min_entries, max_entries, 0u, DEFAULT_ALLOC_GROW_FACTOR) { } diff --git a/vespalib/src/vespa/vespalib/datastore/buffer_type.h b/vespalib/src/vespa/vespalib/datastore/buffer_type.h index ea52b026228..3370bd47fad 100644 --- a/vespalib/src/vespa/vespalib/datastore/buffer_type.h +++ b/vespalib/src/vespa/vespalib/datastore/buffer_type.h @@ -39,8 +39,8 @@ public: BufferTypeBase & operator=(const BufferTypeBase &rhs) = delete; BufferTypeBase(BufferTypeBase &&rhs) noexcept = default; BufferTypeBase & operator=(BufferTypeBase &&rhs) noexcept = default; - BufferTypeBase(uint32_t arraySize, uint32_t min_entries, uint32_t max_entries) noexcept; - BufferTypeBase(uint32_t arraySize, uint32_t min_entries, uint32_t max_entries, + BufferTypeBase(uint32_t entry_size_in, uint32_t arraySize, uint32_t min_entries, uint32_t max_entries) noexcept; + BufferTypeBase(uint32_t entry_size_in, uint32_t arraySize, uint32_t min_entries, uint32_t max_entries, uint32_t num_entries_for_new_buffer, float allocGrowFactor) noexcept; virtual ~BufferTypeBase(); virtual void destroy_entries(void *buffer, EntryCount num_entries) = 0; @@ -56,9 +56,9 @@ public: * Initialize reserved elements at start of buffer. */ virtual void initialize_reserved_entries(void *buffer, EntryCount reserved_entries) = 0; - virtual size_t entry_size() const = 0; // Size of entry measured in bytes + size_t entry_size() const noexcept { return _entry_size; } virtual void clean_hold(void *buffer, size_t offset, EntryCount num_entries, CleanContext cleanCtx) = 0; - size_t getArraySize() const { return _arraySize; } + size_t getArraySize() const noexcept { return _arraySize; } virtual void on_active(uint32_t bufferId, std::atomic<EntryCount>* used_entries, std::atomic<EntryCount>* dead_entries, void* buffer); void on_hold(uint32_t buffer_id, const std::atomic<EntryCount>* used_entries, const std::atomic<EntryCount>* dead_entries); virtual void on_free(EntryCount used_entries); @@ -112,7 +112,8 @@ protected: bool empty() const { return _counts.empty(); } }; - uint32_t _arraySize; // Number of elements in an allocation unit + uint32_t _entry_size; // Number of bytes in an allocation unit + uint32_t _arraySize; // Number of elements in an allocation unit uint32_t _min_entries; // Minimum number of entries to allocate in a buffer uint32_t _max_entries; // Maximum number of entries to allocate in a buffer // Number of entries needed before allocating a new buffer instead of just resizing the first one @@ -150,7 +151,6 @@ public: void fallback_copy(void *newBuffer, const void *oldBuffer, EntryCount num_entries) override; void initialize_reserved_entries(void *buffer, EntryCount reserved_entries) override; void clean_hold(void *buffer, size_t offset, EntryCount num_entries, CleanContext cleanCxt) override; - size_t entry_size() const override { return sizeof(ElemType) * _arraySize; } }; extern template class BufferType<char>; diff --git a/vespalib/src/vespa/vespalib/datastore/buffer_type.hpp b/vespalib/src/vespa/vespalib/datastore/buffer_type.hpp index 60acca5ff39..375c832d9fb 100644 --- a/vespalib/src/vespa/vespalib/datastore/buffer_type.hpp +++ b/vespalib/src/vespa/vespalib/datastore/buffer_type.hpp @@ -8,13 +8,13 @@ namespace vespalib::datastore { template <typename ElemT, typename EmptyT> BufferType<ElemT, EmptyT>::BufferType(uint32_t arraySize, uint32_t min_entries, uint32_t max_entries) noexcept - : BufferTypeBase(arraySize, min_entries, max_entries) + : BufferTypeBase(arraySize * sizeof(ElemT), arraySize, min_entries, max_entries) { } template <typename ElemT, typename EmptyT> BufferType<ElemT, EmptyT>::BufferType(uint32_t arraySize, uint32_t min_entries, uint32_t max_entries, uint32_t num_entries_for_new_buffer, float allocGrowFactor) noexcept - : BufferTypeBase(arraySize, min_entries, max_entries, num_entries_for_new_buffer, allocGrowFactor) + : BufferTypeBase(arraySize * sizeof(ElemT), arraySize, min_entries, max_entries, num_entries_for_new_buffer, allocGrowFactor) { } template <typename ElemT, typename EmptyT> |