diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-03-14 08:11:10 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-03-14 08:11:10 +0000 |
commit | 2d43e1378265d1d8ca8d9fcdfd97e897a806ec38 (patch) | |
tree | e500c0e5c80ccd856ed153b13f98d3287b7941a1 | |
parent | e5a98270a180231b8055ec786565f31f9ba12445 (diff) |
Pre sizing is not necessary.
7 files changed, 25 insertions, 27 deletions
diff --git a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp index 71712623a1d..687f3624b44 100644 --- a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp +++ b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp @@ -1014,7 +1014,7 @@ TEST_F("require that there is control of static memory usage", Fixture) { vespalib::MemoryUsage usage = f.store.getMemoryUsage(); EXPECT_EQUAL(624u, sizeof(LogDataStore)); - EXPECT_EQUAL(2630020u, usage.allocatedBytes()); + EXPECT_EQUAL(74116u, usage.allocatedBytes()); EXPECT_EQUAL(392u, usage.usedBytes()); } diff --git a/searchlib/src/vespa/searchlib/docstore/filechunk.cpp b/searchlib/src/vespa/searchlib/docstore/filechunk.cpp index a280ae08b46..60ba449cdf6 100644 --- a/searchlib/src/vespa/searchlib/docstore/filechunk.cpp +++ b/searchlib/src/vespa/searchlib/docstore/filechunk.cpp @@ -14,7 +14,6 @@ #include <vespa/vespalib/util/executor.h> #include <vespa/vespalib/util/arrayqueue.hpp> #include <vespa/vespalib/util/array.hpp> -#include <vespa/vespalib/stllike/hash_map.hpp> #include <vespa/fastos/file.h> #include <future> @@ -37,7 +36,7 @@ const vespalib::string DOC_ID_LIMIT_KEY("docIdLimit"); using vespalib::make_string; -FileChunk::ChunkInfo::ChunkInfo(uint64_t offset, uint32_t size, uint64_t lastSerial) +FileChunk::ChunkInfo::ChunkInfo(uint64_t offset, uint32_t size, uint64_t lastSerial) noexcept : _lastSerial(lastSerial), _offset(offset), _size(size) @@ -531,7 +530,7 @@ FileChunk::getMemoryFootprint() const size_t FileChunk::getMemoryMetaFootprint() const { - return sizeof(*this) + _chunkInfo.byteCapacity(); + return sizeof(*this) + _chunkInfo.capacity()*sizeof(ChunkInfoVector::value_type); } vespalib::MemoryUsage @@ -540,8 +539,8 @@ FileChunk::getMemoryUsage() const vespalib::MemoryUsage result; result.incAllocatedBytes(sizeof(*this)); result.incUsedBytes(sizeof(*this)); - result.incAllocatedBytes(_chunkInfo.byteCapacity()); - result.incUsedBytes(_chunkInfo.byteSize()); + result.incAllocatedBytes(_chunkInfo.capacity()*sizeof(ChunkInfoVector::value_type)); + result.incUsedBytes(_chunkInfo.size()*sizeof(ChunkInfoVector::value_type)); return result; } diff --git a/searchlib/src/vespa/searchlib/docstore/filechunk.h b/searchlib/src/vespa/searchlib/docstore/filechunk.h index 8788430a5df..a29f7c511c5 100644 --- a/searchlib/src/vespa/searchlib/docstore/filechunk.h +++ b/searchlib/src/vespa/searchlib/docstore/filechunk.h @@ -163,7 +163,6 @@ public: virtual vespalib::system_time getModificationTime() const; virtual bool frozen() const { return true; } const vespalib::string & getName() const { return _name; } - void compact(const IGetLid & iGetLid); void appendTo(vespalib::Executor & executor, const IGetLid & db, IWriteData & dest, uint32_t numChunks, IFileChunkVisitorProgress *visitorProgress, vespalib::CpuUsage::Category cpu_category); @@ -202,7 +201,6 @@ public: static vespalib::string createDatFileName(const vespalib::string & name); private: using File = std::unique_ptr<FileRandRead>; - void loadChunkInfo(); const FileId _fileId; const NameId _nameId; const vespalib::string _name; @@ -221,8 +219,8 @@ protected: class ChunkInfo { public: - ChunkInfo() : _lastSerial(0), _offset(0), _size(0) { } - ChunkInfo(uint64_t offset, uint32_t size, uint64_t lastSerial); + ChunkInfo() noexcept : _lastSerial(0), _offset(0), _size(0) { } + ChunkInfo(uint64_t offset, uint32_t size, uint64_t lastSerial) noexcept; uint64_t getOffset() const { return _offset; } uint32_t getSize() const { return _size; } uint64_t getLastSerial() const { return _lastSerial; } diff --git a/searchlib/src/vespa/searchlib/docstore/lid_info.h b/searchlib/src/vespa/searchlib/docstore/lid_info.h index 24bc6a59664..72da441bbee 100644 --- a/searchlib/src/vespa/searchlib/docstore/lid_info.h +++ b/searchlib/src/vespa/searchlib/docstore/lid_info.h @@ -14,29 +14,29 @@ public: LidInfo() noexcept : _value() { } LidInfo(uint64_t rep) noexcept { _value.r = rep; } LidInfo(uint32_t fileId, uint32_t chunkId, uint32_t size); - uint32_t getFileId() const { return _value.v.fileId; } - uint32_t getChunkId() const { return _value.v.chunkId; } - uint32_t size() const { return _value.v.size << SIZE_SHIFT; } - operator uint64_t () const { return _value.r; } - bool empty() const { return size() == 0; } - bool valid() const { return _value.r != std::numeric_limits<uint64_t>::max(); } + uint32_t getFileId() const noexcept { return _value.v.fileId; } + uint32_t getChunkId() const noexcept { return _value.v.chunkId; } + uint32_t size() const noexcept { return _value.v.size << SIZE_SHIFT; } + operator uint64_t () const noexcept { return _value.r; } + bool empty() const noexcept { return size() == 0; } + bool valid() const noexcept { return _value.r != std::numeric_limits<uint64_t>::max(); } - bool operator==(const LidInfo &b) const { + bool operator==(const LidInfo &b) const noexcept { return (getFileId() == b.getFileId()) && (getChunkId() == b.getChunkId()); } - bool operator < (const LidInfo &b) const { + bool operator < (const LidInfo &b) const noexcept { return (getFileId() == b.getFileId()) ? (getChunkId() < b.getChunkId()) : (getFileId() < b.getFileId()); } - static uint32_t getFileIdLimit() { return 1 << NUM_FILE_BITS; } - static uint32_t getChunkIdLimit() { return 1 << NUM_CHUNK_BITS; } + static constexpr uint32_t getFileIdLimit() { return 1 << NUM_FILE_BITS; } + static constexpr uint32_t getChunkIdLimit() { return 1 << NUM_CHUNK_BITS; } private: - static uint32_t computeAlignedSize(uint32_t sz) { + static constexpr uint32_t computeAlignedSize(uint32_t sz) { return (sz+((1<<SIZE_SHIFT)-1)) >> SIZE_SHIFT; } - static uint32_t getSizeLimit() { + static constexpr uint32_t getSizeLimit() { return std::numeric_limits<uint32_t>::max() - ((2<<SIZE_SHIFT)-2); } static constexpr uint32_t NUM_FILE_BITS = 16; diff --git a/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp b/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp index 91ced8a66c5..cc396e50dda 100644 --- a/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp +++ b/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp @@ -82,7 +82,11 @@ LogDataStore::LogDataStore(vespalib::Executor &executor, const vespalib::string _compactLidSpaceGeneration() { // Reserve space for 1TB summary in order to avoid locking. - _fileChunks.reserve(LidInfo::getFileIdLimit()); + // Even if we have reserved 16 bits for file id ther is no chance that we will even get close to that. + // Size of files grows with disk size, so 8k files should be more than sufficient. + // File ids are reused so there should be no chance of running empty. + static_assert(LidInfo::getFileIdLimit() == 65536u); + _fileChunks.reserve(8_Ki); preload(); updateLidMap(getLastFileChunkDocIdLimit()); @@ -535,7 +539,7 @@ LogDataStore::memoryMeta() const FileChunk::FileId LogDataStore::allocateFileId(const MonitorGuard & guard) { - (void) guard; + assert(guard.owns_lock()); for (size_t i(0); i < _fileChunks.size(); i++) { if ( ! _fileChunks[i] ) { return FileId(i); diff --git a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp index 4248f42a5b4..bdaa23dad35 100644 --- a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp +++ b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp @@ -185,7 +185,6 @@ WriteableFileChunk::updateLidMap(const unique_lock &guard, ISetLid &ds, uint64_t _serialNum = getLastPersistedSerialNum(); _firstChunkIdToBeWritten = _active->getId(); setDiskFootprint(0); - _chunkInfo.reserve(0x10000); return sz; } diff --git a/vespalib/src/vespa/vespalib/util/array.h b/vespalib/src/vespa/vespalib/util/array.h index 30fa4f3eb09..e9d8c9ccfdb 100644 --- a/vespalib/src/vespa/vespalib/util/array.h +++ b/vespalib/src/vespa/vespalib/util/array.h @@ -128,8 +128,6 @@ public: reverse_iterator rbegin() { return empty() ? array(0) : array(_sz) - 1; } reverse_iterator rend() { return empty() ? array(0) : array(0) - 1; } size_t size() const { return _sz; } - size_t byteSize() const { return _sz * sizeof(T); } - size_t byteCapacity() const { return _array.size(); } size_t capacity() const { return _array.size()/sizeof(T); } void clear() { std::destroy(array(0), array(_sz)); |