From 44742c8b56a018cdb7607ec9f0acf76a3bfd6877 Mon Sep 17 00:00:00 2001 From: cqy123456 <39671710+cqy123456@users.noreply.github.com> Date: Thu, 5 Sep 2024 18:07:05 +0800 Subject: [PATCH] enhance: reduce mmap_rss after chunkcache warmup (#35974) related pr: https://github.com/milvus-io/milvus/pull/35965 Signed-off-by: cqy123456 --- .../core/src/segcore/SegmentSealedImpl.cpp | 8 +++++-- internal/core/src/storage/ChunkCache.cpp | 21 +++++++++++++++++-- internal/core/src/storage/ChunkCache.h | 3 ++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/internal/core/src/segcore/SegmentSealedImpl.cpp b/internal/core/src/segcore/SegmentSealedImpl.cpp index 6154678391c81..e1f37e4b4c46f 100644 --- a/internal/core/src/segcore/SegmentSealedImpl.cpp +++ b/internal/core/src/segcore/SegmentSealedImpl.cpp @@ -152,9 +152,13 @@ SegmentSealedImpl::WarmupChunkCache(const FieldId field_id, bool mmap_enabled) { auto field_info = it->second; auto cc = storage::MmapManager::GetInstance().GetChunkCache(); + bool mmap_rss_not_need = true; for (const auto& data_path : field_info.insert_files) { - auto column = - cc->Read(data_path, mmap_descriptor_, field_meta, mmap_enabled); + auto column = cc->Read(data_path, + mmap_descriptor_, + field_meta, + mmap_enabled, + mmap_rss_not_need); } } diff --git a/internal/core/src/storage/ChunkCache.cpp b/internal/core/src/storage/ChunkCache.cpp index 10871babf9198..54661453d9d5d 100644 --- a/internal/core/src/storage/ChunkCache.cpp +++ b/internal/core/src/storage/ChunkCache.cpp @@ -24,7 +24,8 @@ std::shared_ptr ChunkCache::Read(const std::string& filepath, const MmapChunkDescriptorPtr& descriptor, const FieldMeta& field_meta, - bool mmap_enabled) { + bool mmap_enabled, + bool mmap_rss_not_need) { // use rlock to get future { std::shared_lock lck(mutex_); @@ -64,6 +65,22 @@ ChunkCache::Read(const std::string& filepath, field_data = DownloadAndDecodeRemoteFile(cm_.get(), filepath); column = Mmap( field_data->GetFieldData(), descriptor, field_meta, mmap_enabled); + if (mmap_enabled && mmap_rss_not_need) { + auto ok = madvise(reinterpret_cast( + const_cast(column->MmappedData())), + column->ByteSize(), + ReadAheadPolicy_Map["dontneed"]); + if (ok != 0) { + LOG_WARN( + "failed to madvise to the data file {}, addr {}, size {}, " + "err: " + "{}", + filepath, + static_cast(column->MmappedData()), + column->ByteSize(), + strerror(errno)); + } + } allocate_success = true; } catch (const SegcoreError& e) { err_code = e.get_error_code(); @@ -113,7 +130,7 @@ ChunkCache::Prefetch(const std::string& filepath) { LOG_WARN( "failed to madvise to the data file {}, addr {}, size {}, err: {}", filepath, - column->MmappedData(), + static_cast(column->MmappedData()), column->ByteSize(), strerror(errno)); } diff --git a/internal/core/src/storage/ChunkCache.h b/internal/core/src/storage/ChunkCache.h index b2b36c6ec4f30..64be0ae319540 100644 --- a/internal/core/src/storage/ChunkCache.h +++ b/internal/core/src/storage/ChunkCache.h @@ -48,7 +48,8 @@ class ChunkCache { Read(const std::string& filepath, const MmapChunkDescriptorPtr& descriptor, const FieldMeta& field_meta, - bool mmap_enabled); + bool mmap_enabled, + bool mmap_rss_not_need = false); void Remove(const std::string& filepath);