summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2022-02-14 13:47:39 +0100
committerTor Egge <Tor.Egge@online.no>2022-02-14 13:47:39 +0100
commit464b2cc8fcc6e92d745c89b7f07900b51076496d (patch)
tree56220d16de146603bfc29637d57b9de043467365
parent0df1545a1df897c1dd32c4c5f976ac0e80648792 (diff)
Propagate memory allocator to attribute vector components.
-rw-r--r--searchlib/src/tests/attribute/attribute_test.cpp85
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attributevector.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attributevector.h1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumattribute.hpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multivalueattribute.hpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singleenumattribute.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singleenumattribute.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singleenumattribute.hpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp3
9 files changed, 100 insertions, 7 deletions
diff --git a/searchlib/src/tests/attribute/attribute_test.cpp b/searchlib/src/tests/attribute/attribute_test.cpp
index a26e751ae73..0ae495035f0 100644
--- a/searchlib/src/tests/attribute/attribute_test.cpp
+++ b/searchlib/src/tests/attribute/attribute_test.cpp
@@ -22,6 +22,7 @@
#include <vespa/searchlib/util/randomgenerator.h>
#include <vespa/vespalib/io/fileutil.h>
#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/vespalib/util/mmap_file_allocator_factory.h>
#include <vespa/fastos/file.h>
#include <cmath>
#include <iostream>
@@ -275,6 +276,10 @@ private:
void testPendingCompaction();
void testConditionalCommit();
+ static int64_t stat_size(const vespalib::string& swapfile);
+ int test_paged_attribute(const vespalib::string& name, const vespalib::string& swapfile, const search::attribute::Config& cfg);
+ void test_paged_attributes();
+
public:
AttributeTest();
int Main() override;
@@ -2266,6 +2271,85 @@ AttributeTest::testConditionalCommit() {
EXPECT_EQUAL(0u, iv.getChangeVectorMemoryUsage().usedBytes());
}
+int64_t
+AttributeTest::stat_size(const vespalib::string& swapfile)
+{
+ auto stat = vespalib::stat(swapfile);
+ ASSERT_TRUE(stat);
+ return stat->_size;
+}
+
+int
+AttributeTest::test_paged_attribute(const vespalib::string& name, const vespalib::string& swapfile, const search::attribute::Config& cfg)
+{
+ int result = 1;
+ LOG(info, "test_paged_attribute '%s'", name.c_str());
+ auto av = createAttribute(name, cfg);
+ auto v = std::dynamic_pointer_cast<IntegerAttribute>(av);
+ ASSERT_TRUE(v);
+ auto size1 = stat_size(swapfile);
+ // Grow mapping from lid to value or multivalue index
+ addClearedDocs(av, 1200);
+ auto size2 = stat_size(swapfile);
+ auto size3 = size2;
+ EXPECT_LESS(size1, size2);
+ if (cfg.collectionType().isMultiValue()) {
+ // Grow multi value mapping
+ for (uint32_t lid = 1; lid < 100; ++lid) {
+ av->clearDoc(lid);
+ for (uint32_t i = 0; i < 50; ++i) {
+ EXPECT_TRUE(v->append(lid, 0, 1));
+ }
+ av->commit();
+ }
+ size3 = stat_size(swapfile);
+ EXPECT_LESS(size2, size3);
+ result += 2;
+ }
+ if (cfg.fastSearch()) {
+ // Grow enum store
+ uint32_t maxlid = cfg.collectionType().isMultiValue() ? 100 : 1200;
+ for (uint32_t lid = 1; lid < maxlid; ++lid) {
+ av->clearDoc(lid);
+ if (cfg.collectionType().isMultiValue()) {
+ for (uint32_t i = 0; i < 50; ++i) {
+ EXPECT_TRUE(v->append(lid, lid * 100 + i, 1));
+ }
+ } else {
+ EXPECT_TRUE(v->update(lid, lid * 100));
+ }
+ av->commit();
+ }
+ auto size4 = stat_size(swapfile);
+ EXPECT_LESS(size3, size4);
+ result += 4;
+ }
+ return result;
+}
+
+void
+AttributeTest::test_paged_attributes()
+{
+ vespalib::string basedir("mmap-file-allocator-factory-dir");
+ vespalib::alloc::MmapFileAllocatorFactory::instance().setup(basedir);
+ search::attribute::Config cfg1(BasicType::INT32, CollectionType::SINGLE);
+ cfg1.setPaged(true);
+ EXPECT_EQUAL(1, test_paged_attribute("std-int-sv-paged", basedir + "/0.std-int-sv-paged/swapfile", cfg1));
+ search::attribute::Config cfg2(BasicType::INT32, CollectionType::ARRAY);
+ cfg2.setPaged(true);
+ EXPECT_EQUAL(3, test_paged_attribute("std-int-mv-paged", basedir + "/1.std-int-mv-paged/swapfile", cfg2));
+ search::attribute::Config cfg3(BasicType::INT32, CollectionType::SINGLE);
+ cfg3.setPaged(true);
+ cfg3.setFastSearch(true);
+ EXPECT_EQUAL(5, test_paged_attribute("fs-int-sv-paged", basedir + "/2.fs-int-sv-paged/swapfile", cfg3));
+ search::attribute::Config cfg4(BasicType::INT32, CollectionType::ARRAY);
+ cfg4.setPaged(true);
+ cfg4.setFastSearch(true);
+ EXPECT_EQUAL(7, test_paged_attribute("fs-int-mv-paged", basedir + "/3.fs-int-mv-paged/swapfile", cfg4));
+ vespalib::alloc::MmapFileAllocatorFactory::instance().setup("");
+ vespalib::rmdir(basedir, true);
+}
+
void testNamePrefix() {
Config cfg(BasicType::INT32, CollectionType::SINGLE);
AttributeVector::SP vFlat = createAttribute("sfsint32_pc", cfg);
@@ -2348,6 +2432,7 @@ int AttributeTest::Main()
TEST_DO(testConditionalCommit());
TEST_DO(testNamePrefix());
test_multi_value_mapping_has_free_lists_enabled();
+ TEST_DO(test_paged_attributes());
deleteDataDirs();
TEST_DONE();
diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.cpp b/searchlib/src/vespa/searchlib/attribute/attributevector.cpp
index 08721b7302e..4c3134d3235 100644
--- a/searchlib/src/vespa/searchlib/attribute/attributevector.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/attributevector.cpp
@@ -836,6 +836,12 @@ AttributeVector::update_config(const Config& cfg)
drain_hold(1_Mi); // Wait until 1MiB or less on hold
}
+vespalib::alloc::Alloc
+AttributeVector::get_initial_alloc()
+{
+ return (_memory_allocator ? vespalib::alloc::Alloc::alloc_with_allocator(_memory_allocator.get()) : vespalib::alloc::Alloc::alloc());
+}
+
template bool AttributeVector::append<StringChangeData>(ChangeVectorT< ChangeTemplate<StringChangeData> > &changes, uint32_t , const StringChangeData &, int32_t, bool);
template bool AttributeVector::update<StringChangeData>(ChangeVectorT< ChangeTemplate<StringChangeData> > &changes, uint32_t , const StringChangeData &);
template bool AttributeVector::remove<StringChangeData>(ChangeVectorT< ChangeTemplate<StringChangeData> > &changes, uint32_t , const StringChangeData &, int32_t);
diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.h b/searchlib/src/vespa/searchlib/attribute/attributevector.h
index 2bf2f3a6ed6..8b42b19cc60 100644
--- a/searchlib/src/vespa/searchlib/attribute/attributevector.h
+++ b/searchlib/src/vespa/searchlib/attribute/attributevector.h
@@ -378,6 +378,7 @@ protected:
virtual void populate_address_space_usage(AddressSpaceUsage& usage) const;
const std::shared_ptr<vespalib::alloc::MemoryAllocator>& get_memory_allocator() const noexcept { return _memory_allocator; }
+ vespalib::alloc::Alloc get_initial_alloc();
public:
DECLARE_IDENTIFIABLE_ABSTRACT(AttributeVector);
bool isLoaded() const { return _loaded; }
diff --git a/searchlib/src/vespa/searchlib/attribute/enumattribute.hpp b/searchlib/src/vespa/searchlib/attribute/enumattribute.hpp
index c0680fd9238..24dfe742120 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumattribute.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/enumattribute.hpp
@@ -14,7 +14,7 @@ EnumAttribute<B>::
EnumAttribute(const vespalib::string &baseFileName,
const AttributeVector::Config &cfg)
: B(baseFileName, cfg),
- _enumStore(cfg.fastSearch(), cfg.get_dictionary_config())
+ _enumStore(cfg.fastSearch(), cfg.get_dictionary_config(), this->get_memory_allocator())
{
this->setEnum(true);
}
diff --git a/searchlib/src/vespa/searchlib/attribute/multivalueattribute.hpp b/searchlib/src/vespa/searchlib/attribute/multivalueattribute.hpp
index c0524a4d043..326dbd4a380 100644
--- a/searchlib/src/vespa/searchlib/attribute/multivalueattribute.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/multivalueattribute.hpp
@@ -28,7 +28,7 @@ MultiValueAttribute(const vespalib::string &baseFileName,
8 * 1024,
cfg.getGrowStrategy().getMultiValueAllocGrowFactor(),
multivalueattribute::enable_free_lists),
- cfg.getGrowStrategy().to_generic_strategy(), {})
+ cfg.getGrowStrategy().to_generic_strategy(), this->get_memory_allocator())
{
}
diff --git a/searchlib/src/vespa/searchlib/attribute/singleenumattribute.cpp b/searchlib/src/vespa/searchlib/attribute/singleenumattribute.cpp
index d049e53c0a2..cffd52f3dc4 100644
--- a/searchlib/src/vespa/searchlib/attribute/singleenumattribute.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/singleenumattribute.cpp
@@ -14,11 +14,11 @@ namespace search {
using attribute::Config;
SingleValueEnumAttributeBase::
-SingleValueEnumAttributeBase(const Config & c, GenerationHolder &genHolder)
+SingleValueEnumAttributeBase(const Config & c, GenerationHolder &genHolder, const vespalib::alloc::Alloc& initial_alloc)
: _enumIndices(c.getGrowStrategy().getDocsInitialCapacity(),
c.getGrowStrategy().getDocsGrowPercent(),
c.getGrowStrategy().getDocsGrowDelta(),
- genHolder)
+ genHolder, initial_alloc)
{
}
diff --git a/searchlib/src/vespa/searchlib/attribute/singleenumattribute.h b/searchlib/src/vespa/searchlib/attribute/singleenumattribute.h
index a6bcfd92449..8fcef670fb0 100644
--- a/searchlib/src/vespa/searchlib/attribute/singleenumattribute.h
+++ b/searchlib/src/vespa/searchlib/attribute/singleenumattribute.h
@@ -30,7 +30,7 @@ public:
IEnumStore::Index getEnumIndex(DocId docId) const { return _enumIndices[docId]; }
EnumHandle getE(DocId doc) const { return _enumIndices[doc].ref(); }
protected:
- SingleValueEnumAttributeBase(const attribute::Config & c, GenerationHolder &genHolder);
+ SingleValueEnumAttributeBase(const attribute::Config & c, GenerationHolder &genHolder, const vespalib::alloc::Alloc& initial_alloc);
~SingleValueEnumAttributeBase();
AttributeVector::DocId addDoc(bool & incGeneration);
diff --git a/searchlib/src/vespa/searchlib/attribute/singleenumattribute.hpp b/searchlib/src/vespa/searchlib/attribute/singleenumattribute.hpp
index a51c9804cf2..56aa6672696 100644
--- a/searchlib/src/vespa/searchlib/attribute/singleenumattribute.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/singleenumattribute.hpp
@@ -16,7 +16,7 @@ SingleValueEnumAttribute<B>::
SingleValueEnumAttribute(const vespalib::string &baseFileName,
const AttributeVector::Config &cfg)
: B(baseFileName, cfg),
- SingleValueEnumAttributeBase(cfg, getGenerationHolder())
+ SingleValueEnumAttributeBase(cfg, getGenerationHolder(), this->get_initial_alloc())
{
}
diff --git a/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp b/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp
index 89c2a21231b..ef618262bcd 100644
--- a/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp
@@ -19,7 +19,8 @@ SingleValueNumericAttribute(const vespalib::string & baseFileName, const Attribu
_data(c.getGrowStrategy().getDocsInitialCapacity(),
c.getGrowStrategy().getDocsGrowPercent(),
c.getGrowStrategy().getDocsGrowDelta(),
- getGenerationHolder())
+ getGenerationHolder(),
+ this->get_initial_alloc())
{ }
template <typename B>