Skip to content

Commit

Permalink
refactor(sysadvisor): consider per numa memory reserved
Browse files Browse the repository at this point in the history
Signed-off-by: linzhecheng <linzhecheng@bytedance.com>
  • Loading branch information
cheney-lin authored and waynepeking348 committed Jan 12, 2024
1 parent 3a3ab98 commit 4da998a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
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())
})
}
}

0 comments on commit 4da998a

Please sign in to comment.