diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2024-04-18 13:18:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-18 13:18:38 +0200 |
commit | e978ed3707de259a944c5200c986c854295febb6 (patch) | |
tree | a64fc466f478cbcb125f4427e83d830a0fbbf7df /searchlib | |
parent | 2230b5937514d9563311b8b9e395672eaa6786a4 (diff) |
Revert "Use memory mapped disk index dictionary .ssdat file when large"
Diffstat (limited to 'searchlib')
7 files changed, 32 insertions, 127 deletions
diff --git a/searchlib/src/tests/diskindex/pagedict4/pagedict4_test.cpp b/searchlib/src/tests/diskindex/pagedict4/pagedict4_test.cpp index 3b7ec00211d..951d6f61980 100644 --- a/searchlib/src/tests/diskindex/pagedict4/pagedict4_test.cpp +++ b/searchlib/src/tests/diskindex/pagedict4/pagedict4_test.cpp @@ -15,9 +15,8 @@ #include <vespa/searchlib/diskindex/pagedict4randread.h> #include <vespa/searchlib/common/tunefileinfo.h> #include <vespa/vespalib/util/signalhandler.h> -#include <cinttypes> -#include <optional> #include <sstream> +#include <cinttypes> #include <vespa/log/log.h> LOG_SETUP("pagedict4test"); @@ -358,7 +357,6 @@ checkCounts(const std::string &word, void testWords(const std::string &logname, vespalib::Rand48 &rnd, - std::optional<uint32_t> mmap_file_size_threshold, uint64_t numWordIds, uint32_t tupleCount, uint32_t chunkSize, @@ -497,14 +495,7 @@ testWords(const std::string &logname, LOG(info, "%s: pagedict4 written", logname.c_str()); } { - std::unique_ptr<DictionaryFileSeqRead> dr; - { - auto my_dr = std::make_unique<PageDict4FileSeqRead>(); - if (mmap_file_size_threshold.has_value()) { - my_dr->set_mmap_file_size_threshold(mmap_file_size_threshold.value()); - } - dr = std::move(my_dr); - } + std::unique_ptr<DictionaryFileSeqRead> dr(new PageDict4FileSeqRead); search::TuneFileSeqRead tuneFileRead; bool openres = dr->open("fakedict", @@ -544,14 +535,7 @@ testWords(const std::string &logname, LOG(info, "%s: pagedict4 seqverify OK", logname.c_str()); } { - std::unique_ptr<DictionaryFileRandRead> drr; - { - auto my_drr = std::make_unique<PageDict4RandRead>(); - if (mmap_file_size_threshold.has_value()) { - my_drr->set_mmap_file_size_threshold(mmap_file_size_threshold.value()); - } - drr = std::move(my_drr); - } + std::unique_ptr<DictionaryFileRandRead> drr(new PageDict4RandRead); search::TuneFileRandRead tuneFileRead; bool openres = drr->open("fakedict", tuneFileRead); @@ -665,50 +649,46 @@ testWords(const std::string &logname, void PageDict4TestApp::testWords() { - ::testWords("smallchunkwordsempty", _rnd, std::nullopt, + ::testWords("smallchunkwordsempty", _rnd, 1000000, 0, 64, 80, 72, 64, false, false, false); - ::testWords("smallchunkwordsempty2", _rnd, std::nullopt, + ::testWords("smallchunkwordsempty2", _rnd, 0, 0, 64, 80, 72, 64, false, false, false); - ::testWords("smallchunkwords", _rnd, std::nullopt, + ::testWords("smallchunkwords", _rnd, 1000000, 100, 64, 80, 72, 64, false, false, false); - ::testWords("smallchunkwordswithemptyword", _rnd, std::nullopt, + ::testWords("smallchunkwordswithemptyword", _rnd, 1000000, 100, 64, 80, 72, 64, true, false, false); - ::testWords("smallchunkwordswithcommonfirstword", _rnd, std::nullopt, + ::testWords("smallchunkwordswithcommonfirstword", _rnd, 1000000, 100, 64, 80, 72, 64, false, true, false); - ::testWords("smallchunkwordswithcommonemptyfirstword", _rnd, std::nullopt, + ::testWords("smallchunkwordswithcommonemptyfirstword", _rnd, 1000000, 100, 64, 80, 72, 64, true, true, false); - ::testWords("smallchunkwordswithcommonlastword", _rnd, std::nullopt, + ::testWords("smallchunkwordswithcommonlastword", _rnd, 1000000, 100, 64, 80, 72, 64, false, false, true); - ::testWords("smallchunkwords2", _rnd, std::nullopt, +#if 1 + ::testWords("smallchunkwords2", _rnd, 1000000, _stress ? 10000 : 100, 64, 80, 72, 64, _emptyWord, _firstWordForcedCommon, _lastWordForcedCommon); - ::testWords("stdwords", _rnd, std::nullopt, +#endif +#if 1 + ::testWords("stdwords", _rnd, 1000000, _stress ? 10000 : 100, 262144, 80, 72, 64, _emptyWord, _firstWordForcedCommon, _lastWordForcedCommon); - ::testWords("stdwordsnommapssdat", _rnd, 500_Mi, - 1000000, 100, - 262144, 80, 72, 64, - _emptyWord, _firstWordForcedCommon, _lastWordForcedCommon); - ::testWords("stdwordsmmapssdat", _rnd, 1, - 1000000, 100, - 262144, 80, 72, 64, - _emptyWord, _firstWordForcedCommon, _lastWordForcedCommon); +#endif } int main(int argc, char **argv) { diff --git a/searchlib/src/vespa/searchlib/bitcompression/compression.cpp b/searchlib/src/vespa/searchlib/bitcompression/compression.cpp index e5ce886f499..f3fc31ac8b1 100644 --- a/searchlib/src/vespa/searchlib/bitcompression/compression.cpp +++ b/searchlib/src/vespa/searchlib/bitcompression/compression.cpp @@ -6,9 +6,7 @@ #include <vespa/searchlib/index/postinglistparams.h> #include <vespa/vespalib/data/fileheader.h> #include <vespa/vespalib/data/databuffer.h> -#include <vespa/vespalib/datastore/aligner.h> #include <vespa/vespalib/util/arrayref.h> -#include <vespa/vespalib/util/round_up_to_page_size.h> #include <vespa/vespalib/util/size_literals.h> namespace search::bitcompression { @@ -183,12 +181,6 @@ readHeader(vespalib::GenericHeader &header, int64_t fileSize) return headerLen; } -bool -DecodeContext64Base::is_padded_for_memory_map(uint64_t file_bit_size, uint64_t file_size) noexcept -{ - using Aligner = vespalib::datastore::Aligner<64>; - return (Aligner::align(file_bit_size) + 128 <= (vespalib::round_up_to_page_size(file_size) * 8)); -} template <bool bigEndian> void diff --git a/searchlib/src/vespa/searchlib/bitcompression/compression.h b/searchlib/src/vespa/searchlib/bitcompression/compression.h index b1e13a9d96b..4124f1f659f 100644 --- a/searchlib/src/vespa/searchlib/bitcompression/compression.h +++ b/searchlib/src/vespa/searchlib/bitcompression/compression.h @@ -1261,13 +1261,6 @@ public: virtual uint64_t decode_exp_golomb(int k) = 0; void readBytes(uint8_t *buf, size_t len); uint32_t readHeader(vespalib::GenericHeader &header, int64_t fileSize); - - /* - * Check if file is padding at end for decompression readahead. - */ - static bool is_padded_for_memory_map(uint64_t file_bit_size, uint64_t file_size) noexcept; - - static uint64_t file_units(uint64_t file_size) noexcept { return (file_size + sizeof(uint64_t) - 1) / sizeof(uint64_t); } }; diff --git a/searchlib/src/vespa/searchlib/diskindex/pagedict4file.cpp b/searchlib/src/vespa/searchlib/diskindex/pagedict4file.cpp index 89b5ffb84f8..bceeb1e7bc1 100644 --- a/searchlib/src/vespa/searchlib/diskindex/pagedict4file.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/pagedict4file.cpp @@ -51,7 +51,7 @@ using vespalib::getLastErrorString; namespace search::diskindex { struct PageDict4FileSeqRead::DictFileReadContext { - DictFileReadContext(vespalib::stringref id, const vespalib::string & name, const TuneFileSeqRead &tune, uint32_t mmap_file_size_threshold, bool read_all_upfront); + DictFileReadContext(vespalib::stringref id, const vespalib::string & name, const TuneFileSeqRead &tune, bool read_all_upfront); ~DictFileReadContext(); vespalib::FileHeader readHeader(); void readExtendedHeader(); @@ -66,7 +66,7 @@ struct PageDict4FileSeqRead::DictFileReadContext { }; PageDict4FileSeqRead::DictFileReadContext::DictFileReadContext(vespalib::stringref id, const vespalib::string & name, - const TuneFileSeqRead &tune, uint32_t mmap_file_size_threshold, bool read_all_upfront) + const TuneFileSeqRead &tune, bool read_all_upfront) : _id(id), _fileBitSize(0u), _headerLen(0u), @@ -79,49 +79,23 @@ PageDict4FileSeqRead::DictFileReadContext::DictFileReadContext(vespalib::stringr if (tune.getWantDirectIO()) { _file.EnableDirectIO(); } - if (read_all_upfront) { - _file.enableMemoryMap(0); - } if (!_file.OpenReadOnly(name.c_str())) { LOG(error, "could not open %s: %s", _file.GetFileName(), getLastErrorString().c_str()); return; } uint64_t fileSize = _file.getSize(); - uint64_t file_units = DC::file_units(fileSize); _readContext.setFile(&_file); _readContext.setFileSize(fileSize); - bool use_mmap = false; - /* - * Limit memory usage spike by using memory mapped .ssdat file if - * file size is greater than 32 MiB with padding at end of file. - */ - if (read_all_upfront && _file.MemoryMapPtr(0) != nullptr && fileSize >= mmap_file_size_threshold) { - _readContext.reference_compressed_buffer(_file.MemoryMapPtr(0), file_units); - vespalib::FileHeader header; - _dc.readHeader(header, _file.getSize()); - assert(header.hasTag("fileBitSize")); - int64_t file_bit_size = header.getTag("fileBitSize").asInteger(); - use_mmap = DC::is_padded_for_memory_map(file_bit_size, fileSize); - _readContext.setBitOffset(0); - _readContext.setBufferEndFilePos(0); - } if (read_all_upfront) { - if (use_mmap) { - _readContext.reference_compressed_buffer(_file.MemoryMapPtr(0), file_units); - } else { - _readContext.allocComprBuf(file_units, 32_Ki); - } + _readContext.allocComprBuf((fileSize + sizeof(uint64_t) - 1) / sizeof(uint64_t), 32_Ki); } else { _readContext.allocComprBuf(64_Ki, 32_Ki); } - if (!use_mmap) { - _dc.emptyBuffer(0); - _readContext.readComprBuffer(); - } + _dc.emptyBuffer(0); + _readContext.readComprBuffer(); if (read_all_upfront) { assert(_readContext.getBufferEndFilePos() >= fileSize); } - assert(_dc.getBitPosV() == 0); _valid = true; } @@ -147,8 +121,7 @@ PageDict4FileSeqRead::PageDict4FileSeqRead() _ss(), _sp(), _p(), - _wordNum(0u), - _mmap_file_size_threshold(32_Mi) + _wordNum(0u) { } PageDict4FileSeqRead::~PageDict4FileSeqRead() = default; @@ -193,9 +166,9 @@ bool PageDict4FileSeqRead::open(const vespalib::string &name, const TuneFileSeqRead &tuneFileRead) { - _ss = std::make_unique<DictFileReadContext>(mySSId, name + ".ssdat", tuneFileRead, _mmap_file_size_threshold, true); - _sp = std::make_unique<DictFileReadContext>(mySPId, name + ".spdat", tuneFileRead, _mmap_file_size_threshold, false); - _p = std::make_unique<DictFileReadContext>(myPId, name + ".pdat", tuneFileRead, _mmap_file_size_threshold, false); + _ss = std::make_unique<DictFileReadContext>(mySSId, name + ".ssdat", tuneFileRead, true); + _sp = std::make_unique<DictFileReadContext>(mySPId, name + ".spdat", tuneFileRead, false); + _p = std::make_unique<DictFileReadContext>(myPId, name + ".pdat", tuneFileRead, false); if ( !_ss->_valid || !_sp->_valid || !_p->_valid ) { return false; } diff --git a/searchlib/src/vespa/searchlib/diskindex/pagedict4file.h b/searchlib/src/vespa/searchlib/diskindex/pagedict4file.h index 40540cd458e..404f85e9088 100644 --- a/searchlib/src/vespa/searchlib/diskindex/pagedict4file.h +++ b/searchlib/src/vespa/searchlib/diskindex/pagedict4file.h @@ -26,7 +26,6 @@ class PageDict4FileSeqRead : public index::DictionaryFileSeqRead std::unique_ptr<DictFileReadContext> _sp; std::unique_ptr<DictFileReadContext> _p; uint64_t _wordNum; - uint32_t _mmap_file_size_threshold; public: PageDict4FileSeqRead(); ~PageDict4FileSeqRead() override; @@ -39,7 +38,6 @@ public: bool open(const vespalib::string &name, const TuneFileSeqRead &tuneFileRead) override; bool close() override; void getParams(index::PostingListParams ¶ms) override; - void set_mmap_file_size_threshold(uint32_t v) { _mmap_file_size_threshold = v; } }; /** diff --git a/searchlib/src/vespa/searchlib/diskindex/pagedict4randread.cpp b/searchlib/src/vespa/searchlib/diskindex/pagedict4randread.cpp index a513a18ae5d..3654b703648 100644 --- a/searchlib/src/vespa/searchlib/diskindex/pagedict4randread.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/pagedict4randread.cpp @@ -1,8 +1,8 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "pagedict4randread.h" -#include <vespa/vespalib/data/fileheader.h> #include <vespa/vespalib/stllike/asciistream.h> +#include <vespa/vespalib/data/fileheader.h> #include <vespa/fastos/file.h> #include <vespa/log/log.h> @@ -33,8 +33,7 @@ PageDict4RandRead::PageDict4RandRead() _pFileBitSize(0u), _ssHeaderLen(0u), _spHeaderLen(0u), - _pHeaderLen(0u), - _mmap_file_size_threshold(32_Mi) + _pHeaderLen(0u) { _ssd.setReadContext(&_ssReadContext); } @@ -230,42 +229,14 @@ PageDict4RandRead::open(const vespalib::string &name, } uint64_t fileSize = _ssfile->getSize(); - uint64_t file_units = DC::file_units(fileSize); _ssReadContext.setFile(_ssfile.get()); _ssReadContext.setFileSize(fileSize); - /* - * Limit memory usage spike by using memory mapped .ssdat file if - * file size is greater than 32 MiB with padding at end of file. - * Note: It might cause higher dictionary lookup latencies when - * system is under memory pressure due to pageins. - */ - bool has_read_ss_header = false; - if (_ssfile->MemoryMapPtr(0) != nullptr && fileSize >= _mmap_file_size_threshold) { - _ssReadContext.reference_compressed_buffer(_ssfile->MemoryMapPtr(0), file_units); - assert(_ssd.getReadOffset() == 0u); - readSSHeader(); - has_read_ss_header = true; - } - if (!has_read_ss_header || !DC::is_padded_for_memory_map(_ssFileBitSize, fileSize)) { - /* - * Insufficient padding or small .sdat file. Read whole file into - * memory. - */ - _ssReadContext.allocComprBuf(file_units, 32768u); - _ssd.emptyBuffer(0); - _ssReadContext.setBitOffset(0); - _ssReadContext.setBufferEndFilePos(0); - _ssfile->SetPosition(0); - _ssReadContext.readComprBuffer(); - assert(_ssReadContext.getBufferEndFilePos() >= fileSize); - assert(_ssd.getReadOffset() == 0u); - if (has_read_ss_header) { - _ssReadContext.setPosition(_ssHeaderLen * 8); - } else { - readSSHeader(); - } - } + _ssReadContext.allocComprBuf((fileSize + sizeof(uint64_t) - 1) / sizeof(uint64_t), 32768u); + _ssd.emptyBuffer(0); + _ssReadContext.readComprBuffer(); + assert(_ssReadContext.getBufferEndFilePos() >= fileSize); + readSSHeader(); readSPHeader(); readPHeader(); diff --git a/searchlib/src/vespa/searchlib/diskindex/pagedict4randread.h b/searchlib/src/vespa/searchlib/diskindex/pagedict4randread.h index 1c2e538cc48..051efa486dd 100644 --- a/searchlib/src/vespa/searchlib/diskindex/pagedict4randread.h +++ b/searchlib/src/vespa/searchlib/diskindex/pagedict4randread.h @@ -36,7 +36,6 @@ class PageDict4RandRead : public index::DictionaryFileRandRead uint32_t _ssHeaderLen; uint32_t _spHeaderLen; uint32_t _pHeaderLen; - uint32_t _mmap_file_size_threshold; void readSSHeader(); void readSPHeader(); @@ -52,7 +51,6 @@ public: bool close() override; uint64_t getNumWordIds() const override; - void set_mmap_file_size_threshold(uint32_t v) { _mmap_file_size_threshold = v; } }; } |