diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-06-15 09:43:56 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-06-16 12:11:40 +0000 |
commit | acb0b472c558fc4dd89407b7c26e260415729ca9 (patch) | |
tree | a337928708f94d406751a36b2e0d79ce8f96d6b2 | |
parent | d782ba728837c36c20f2b8b6e1757b7305e7b57b (diff) |
When computing size of visit cache count allocated bytes, not only used.
3 files changed, 23 insertions, 19 deletions
diff --git a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp index 1ca020bca86..2bf2a38b7e6 100644 --- a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp +++ b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp @@ -368,13 +368,13 @@ TEST("test visit cache does not cache empty ones and is able to access some back IDataStore & datastore = store.getStore(); VisitCache visitCache(datastore, 100000, CompressionConfig::Type::LZ4); - EXPECT_EQUAL(12u, visitCache.read({1}).byteSize()); + EXPECT_EQUAL(12u, visitCache.read({1}).bytesAllocated()); EXPECT_TRUE(visitCache.read({1}).empty()); datastore.write(1,1, A7, 7); - EXPECT_EQUAL(12u, visitCache.read({2}).byteSize()); + EXPECT_EQUAL(12u, visitCache.read({2}).bytesAllocated()); CompressedBlobSet cbs = visitCache.read({1}); EXPECT_FALSE(cbs.empty()); - EXPECT_EQUAL(19u, cbs.byteSize()); + EXPECT_EQUAL(19u, cbs.bytesAllocated()); BlobSet bs(cbs.getBlobSet()); EXPECT_EQUAL(7u, bs.get(1).size()); EXPECT_EQUAL(0, strncmp(A7, bs.get(1).c_str(), 7)); diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp index cb56d5d20ff..b61cf49c438 100644 --- a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp +++ b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp @@ -77,26 +77,29 @@ BlobSet::get(uint32_t lid) const } CompressedBlobSet::CompressedBlobSet() noexcept - : _compression(CompressionConfig::Type::LZ4), - _positions(), - _buffer() + : _positions(), + _buffer(), + _used(0), + _compression(CompressionConfig::Type::LZ4) { } CompressedBlobSet::~CompressedBlobSet() = default; CompressedBlobSet::CompressedBlobSet(CompressionConfig compression, BlobSet uncompressed) - : _compression(compression.type), - _positions(uncompressed.stealPositions()), - _buffer() + : _positions(uncompressed.stealPositions()), + _buffer(), + _used(0), + _compression(compression.type) { if ( ! _positions.empty() ) { DataBuffer compressed; ConstBufferRef org = uncompressed.getBuffer(); _compression = vespalib::compression::compress(compression, org, compressed, false); - _buffer = std::make_shared<vespalib::MallocPtr>(compressed.getDataLen()); - memcpy(*_buffer, compressed.getData(), compressed.getDataLen()); + _used = compressed.getDataLen(); + _buffer = std::make_shared<Alloc>(Alloc::alloc(_used)); + memcpy(_buffer->get(), compressed.getData(), _used); } else { - _buffer = std::make_shared<vespalib::MallocPtr>(); + _buffer = std::make_shared<Alloc>(); } } @@ -108,13 +111,13 @@ CompressedBlobSet::getBlobSet() const DataBuffer uncompressed(0, 1, Alloc::alloc(0, 16 * MemoryAllocator::HUGEPAGE_SIZE)); if ( ! _positions.empty() ) { decompress(_compression, getBufferSize(_positions), - ConstBufferRef(_buffer->c_str(), _buffer->size()), uncompressed, false); + ConstBufferRef(_buffer->get(), _used), uncompressed, false); } return BlobSet(_positions, std::move(uncompressed).stealBuffer()); } size_t -CompressedBlobSet::byteSize() const { +CompressedBlobSet::bytesAllocated() const { return _positions.capacity() * sizeof(BlobSet::Positions::value_type) + _buffer->size(); } @@ -137,7 +140,7 @@ VisitCollector::visit(uint32_t lid, ConstBufferRef buf) { } struct ByteSize { - size_t operator() (const CompressedBlobSet & arg) const noexcept { return arg.byteSize(); } + size_t operator() (const CompressedBlobSet & arg) const noexcept { return arg.bytesAllocated(); } }; } diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.h b/searchlib/src/vespa/searchlib/docstore/visitcache.h index f7b419c0fc6..2f312ec3011 100644 --- a/searchlib/src/vespa/searchlib/docstore/visitcache.h +++ b/searchlib/src/vespa/searchlib/docstore/visitcache.h @@ -4,7 +4,6 @@ #include "idocumentstore.h" #include <vespa/vespalib/util/alloc.h> -#include <vespa/vespalib/util/memory.h> #include <vespa/vespalib/util/compressionconfig.h> #include <vespa/vespalib/objects/nbostream.h> @@ -78,13 +77,15 @@ public: CompressedBlobSet(const CompressedBlobSet & rhs) = default; CompressedBlobSet & operator=(const CompressedBlobSet & rhs) = default; ~CompressedBlobSet(); - size_t byteSize() const; + size_t bytesAllocated() const; bool empty() const { return _positions.empty(); } BlobSet getBlobSet() const; private: - CompressionConfig::Type _compression; + using Alloc = vespalib::alloc::Alloc; BlobSet::Positions _positions; - std::shared_ptr<vespalib::MallocPtr> _buffer; + std::shared_ptr<Alloc> _buffer; + uint32_t _used; + CompressionConfig::Type _compression; }; /** |