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

refactor(sysadvisor): consider per numa memory reserved #443

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
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 @@ -73,8 +73,10 @@ func (p *PolicyNUMAAware) Update() (err error) {
}()

var (
reclaimableMemory float64
data metric.MetricData
reclaimableMemory float64 = 0
availNUMATotal float64 = 0
reservedForAllocate float64 = 0
data metric.MetricData
)
dynamicConfig := p.conf.GetDynamicConfiguration()

Expand All @@ -83,30 +85,38 @@ func (p *PolicyNUMAAware) Update() (err error) {
return err
}

availNUMATotal := float64(0)
for _, numaID := range availNUMAs.ToSliceInt() {
data, err = p.metaServer.GetNumaMetric(numaID, consts.MetricMemFreeNuma)
if err != nil {
general.Errorf("Can not get numa memory free, numaID: %v", numaID)
return err
}
reclaimableMemory += data.Value
general.InfoS("reclaimable numa memory free", "numaID", numaID, "numaFree", general.FormatMemoryQuantity(data.Value))
free := data.Value

data, err = p.metaServer.GetNumaMetric(numaID, consts.MetricMemInactiveFileNuma)
if err != nil {
return err
}
reclaimableMemory += data.Value * dynamicConfig.CacheBasedRatio
general.InfoS("reclaimable numa inactive file", "numaID", numaID, "numaInactiveFile", general.FormatMemoryQuantity(data.Value))
inactiveFile := data.Value

data, err = p.metaServer.GetNumaMetric(numaID, consts.MetricMemTotalNuma)
if err != nil {
general.Errorf("Can not get numa memory total, numaID: %v", numaID)
general.ErrorS(err, "Can not get numa memory total", "numaID", numaID)
return err
}
availNUMATotal += data.Value
general.InfoS("reclaimable numa memory total", "numaID", numaID, "numaTotal", general.FormatMemoryQuantity(data.Value))
total := data.Value
availNUMATotal += total
reservedForAllocate += p.essentials.ReservedForAllocate / float64(p.metaServer.NumNUMANodes)

numaReclaimable := free + inactiveFile*dynamicConfig.CacheBasedRatio

general.InfoS("NUMA memory info", "numaID", numaID,
"total", general.FormatMemoryQuantity(total), "free", general.FormatMemoryQuantity(free),
"inactiveFile", general.FormatMemoryQuantity(inactiveFile), "CacheBasedRatio", dynamicConfig.CacheBasedRatio,
"numaReclaimable", general.FormatMemoryQuantity(numaReclaimable),
)

reclaimableMemory += numaReclaimable
}

for _, container := range reclaimedCoresContainers {
Expand All @@ -118,15 +128,16 @@ func (p *PolicyNUMAAware) Update() (err error) {
general.InfoS("Can not get system watermark scale factor")
return err
}

// reserve memory for watermark_scale_factor to make kswapd less happened
systemWatermarkReserved := availNUMATotal * watermarkScaleFactor.Value / 10000

general.InfoS("total memory reclaimable",
"reclaimableMemory", general.FormatMemoryQuantity(reclaimableMemory),
"ReservedForAllocate", general.FormatMemoryQuantity(p.essentials.ReservedForAllocate),
"ReservedForWatermark", general.FormatMemoryQuantity(systemWatermarkReserved),
"ResourceUpperBound", general.FormatMemoryQuantity(p.essentials.ResourceUpperBound))
p.memoryHeadroom = math.Max(reclaimableMemory-p.essentials.ReservedForAllocate-systemWatermarkReserved, 0)
"ResourceUpperBound", general.FormatMemoryQuantity(p.essentials.ResourceUpperBound),
"systemWatermarkReserved", general.FormatMemoryQuantity(systemWatermarkReserved),
"reservedForAllocate", general.FormatMemoryQuantity(reservedForAllocate))
p.memoryHeadroom = math.Max(reclaimableMemory-systemWatermarkReserved-reservedForAllocate, 0)

return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestPolicyNUMAAware(t *testing.T) {
},
},
wantErr: false,
want: resource.MustParse("128.5Gi"),
want: resource.MustParse("130.5Gi"),
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -237,9 +237,7 @@ func TestPolicyNUMAAware(t *testing.T) {
t.Errorf("GetHeadroom() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got.MilliValue() != tt.want.MilliValue() {
t.Errorf("GetHeadroom() got = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want.MilliValue(), got.MilliValue())
})
}
}