Skip to content

Commit

Permalink
Fix calculation of memory usage prediction for mmap mode (#26264)
Browse files Browse the repository at this point in the history
Signed-off-by: yah01 <yah2er0ne@outlook.com>
  • Loading branch information
yah01 authored Aug 12, 2023
1 parent 9ca8f28 commit a173486
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
4 changes: 0 additions & 4 deletions internal/core/src/mmap/Column.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@

namespace milvus {

#ifdef MAP_POPULATE
static int mmap_flags = MAP_SHARED | MAP_POPULATE;
#else
static int mmap_flags = MAP_SHARED;
#endif

class ColumnBase {
public:
Expand Down
31 changes: 27 additions & 4 deletions internal/querynodev2/segments/segment_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ func (loader *segmentLoader) notifyLoadFinish(segments ...*querypb.SegmentLoadIn
// requestResource requests memory & storage to load segments,
// returns the memory usage, disk usage and concurrency with the gained memory.
func (loader *segmentLoader) requestResource(ctx context.Context, infos ...*querypb.SegmentLoadInfo) (LoadResource, int, error) {
segmentIDs := lo.Map(infos, func(info *querypb.SegmentLoadInfo, _ int) int64 {
return info.GetSegmentID()
})
log := log.Ctx(ctx).With(
zap.Int64s("segmentIDs", segmentIDs),
)

resource := LoadResource{}

loader.mut.Lock()
Expand Down Expand Up @@ -350,6 +357,14 @@ func (loader *segmentLoader) requestResource(ctx context.Context, infos ...*quer
resource.DiskSize += du

loader.committedResource.Add(resource)
log.Info("request resource for loading segments",
zap.Int("workerNum", resource.WorkNum),
zap.Int("committedWorkerNum", loader.committedResource.WorkNum),
zap.Uint64("memory", resource.MemorySize),
zap.Uint64("committedMemory", loader.committedResource.MemorySize),
zap.Uint64("disk", resource.DiskSize),
zap.Uint64("committedDisk", loader.committedResource.DiskSize),
)

return resource, concurrencyLevel, nil
}
Expand Down Expand Up @@ -830,6 +845,7 @@ func (loader *segmentLoader) checkSegmentSize(ctx context.Context, segmentLoadIn
metrics.QueryNodeDiskUsedSize.WithLabelValues(fmt.Sprint(paramtable.GetNodeID())).Set(float64(toMB(uint64(localDiskUsage))))
diskUsage := uint64(localDiskUsage) + loader.committedResource.DiskSize

mmapEnabled := len(paramtable.Get().QueryNodeCfg.MmapDirPath.GetValue()) > 0
maxSegmentSize := uint64(0)
predictMemUsage := memUsage
predictDiskUsage := diskUsage
Expand All @@ -856,10 +872,18 @@ func (loader *segmentLoader) checkSegmentSize(ctx context.Context, segmentLoadIn
)
return 0, 0, err
}
predictMemUsage += neededMemSize
predictDiskUsage += neededDiskSize
if mmapEnabled {
predictDiskUsage += neededMemSize + neededDiskSize
} else {
predictMemUsage += neededMemSize
predictDiskUsage += neededDiskSize
}
} else {
predictMemUsage += uint64(getBinlogDataSize(fieldBinlog))
if mmapEnabled {
predictDiskUsage += uint64(getBinlogDataSize(fieldBinlog))
} else {
predictMemUsage += uint64(getBinlogDataSize(fieldBinlog))
}
}
}

Expand All @@ -878,7 +902,6 @@ func (loader *segmentLoader) checkSegmentSize(ctx context.Context, segmentLoadIn
}
}

mmapEnabled := len(paramtable.Get().QueryNodeCfg.MmapDirPath.GetValue()) > 0
log.Info("predict memory and disk usage while loading (in MiB)",
zap.Uint64("maxSegmentSize", toMB(maxSegmentSize)),
zap.Int("concurrency", concurrency),
Expand Down

0 comments on commit a173486

Please sign in to comment.