Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement(sysadvisor): introduce minCriticalWatermark to determin m… #415

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package plugin

import (
"strconv"
"sync"

"go.uber.org/atomic"

Expand All @@ -34,16 +33,15 @@ import (

const (
MemoryGuard = "memory-guard"
minReserved = 1 << 30 // 1GiB
)

type memoryGuard struct {
mutex sync.RWMutex
metaReader metacache.MetaReader
metaServer *metaserver.MetaServer
emitter metrics.MetricEmitter
reclaimRelativeRootCgroupPath string
reclaimMemoryLimit *atomic.Int64
minCriticalWatermark int64
}

func NewMemoryGuard(conf *config.Configuration, extraConfig interface{}, metaReader metacache.MetaReader, metaServer *metaserver.MetaServer, emitter metrics.MetricEmitter) MemoryAdvisorPlugin {
Expand All @@ -53,6 +51,7 @@ func NewMemoryGuard(conf *config.Configuration, extraConfig interface{}, metaRea
emitter: emitter,
reclaimRelativeRootCgroupPath: conf.ReclaimRelativeRootCgroupPath,
reclaimMemoryLimit: atomic.NewInt64(-1),
minCriticalWatermark: conf.MinCriticalWatermark,
}
}

Expand Down Expand Up @@ -82,7 +81,8 @@ func (mg *memoryGuard) Reconcile(status *types.MemoryPressureStatus) error {
return err
}

buffer := memoryFree.Value + memoryCache.Value + memoryBuffer.Value - memoryTotal.Value*scaleFactor.Value/10000
criticalWatermark := general.MaxFloat64(float64(mg.minCriticalWatermark*int64(mg.metaServer.NumNUMANodes)), memoryTotal.Value*scaleFactor.Value/10000)
buffer := memoryFree.Value + memoryCache.Value + memoryBuffer.Value - criticalWatermark
if buffer < 0 {
buffer = 0
}
Expand All @@ -97,14 +97,15 @@ func (mg *memoryGuard) Reconcile(status *types.MemoryPressureStatus) error {
return err
}

reclaimMemoryLimit := general.MaxFloat64(reclaimGroupUsed.Value+minReserved, reclaimGroupRss.Value+buffer)
reclaimMemoryLimit := general.MaxFloat64(reclaimGroupUsed.Value, reclaimGroupRss.Value+buffer)

general.InfoS("memory details",
"system total", general.FormatMemoryQuantity(memoryTotal.Value),
"system free", general.FormatMemoryQuantity(memoryFree.Value),
"system cache", general.FormatMemoryQuantity(memoryCache.Value),
"system buffer", general.FormatMemoryQuantity(memoryBuffer.Value),
"system scaleFactor", general.FormatMemoryQuantity(scaleFactor.Value),
"criticalWatermark", general.FormatMemoryQuantity(criticalWatermark),
"buffer", general.FormatMemoryQuantity(buffer),
"reclaim cgroup rss", general.FormatMemoryQuantity(reclaimGroupRss.Value),
"reclaim cgroup used", general.FormatMemoryQuantity(reclaimGroupUsed.Value),
Expand Down