Skip to content

Commit

Permalink
enhance: reduce mmap_rss after chunkcache warmup (milvus-io#35974)
Browse files Browse the repository at this point in the history
related pr: milvus-io#35965

Signed-off-by: cqy123456 <[email protected]>
  • Loading branch information
cqy123456 authored and chyezh committed Sep 11, 2024
1 parent 6e28b27 commit 44742c8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
8 changes: 6 additions & 2 deletions internal/core/src/segcore/SegmentSealedImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
21 changes: 19 additions & 2 deletions internal/core/src/storage/ChunkCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ std::shared_ptr<ColumnBase>
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_);
Expand Down Expand Up @@ -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<void*>(
const_cast<char*>(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<const void*>(column->MmappedData()),
column->ByteSize(),
strerror(errno));
}
}
allocate_success = true;
} catch (const SegcoreError& e) {
err_code = e.get_error_code();
Expand Down Expand Up @@ -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<const void*>(column->MmappedData()),
column->ByteSize(),
strerror(errno));
}
Expand Down
3 changes: 2 additions & 1 deletion internal/core/src/storage/ChunkCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 44742c8

Please sign in to comment.