Skip to content

Commit

Permalink
Merge pull request #690 from cheney-lin/dev/fix-assembler
Browse files Browse the repository at this point in the history
fix: check having upper bound
  • Loading branch information
xu282934741 authored Sep 11, 2024
2 parents ef4cd80 + 85a5392 commit 47cc1fc
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (ha *HeadroomAssemblerCommon) GetHeadroom() (resource.Quantity, error) {
if !ok || regionInfo == nil || regionInfo.Headroom < 0 {
return resource.Quantity{}, fmt.Errorf("failed to get headroom for %v", r.Name())
}
if regionInfo.RegionStatus.BoundType == types.BoundUpper {
if regionInfo.RegionStatus.BoundType == types.BoundUpper && r.EnableReclaim() {
general.Infof("region %v is in status of upper bound", regionInfo.RegionName)
hasUpperBound = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ func TestHeadroomAssemblerCommon_GetHeadroom(t *testing.T) {
name: "normal report",
fields: fields{
entries: map[string]*types.RegionInfo{
"share-0": {
RegionType: configapi.QoSRegionTypeShare,
"share": {
RegionType: configapi.QoSRegionTypeShare,
OwnerPoolName: "share",
BindingNumas: machine.NewCPUSet(0, 1),
},
},
cnr: &v1alpha1.CustomNodeResource{
Expand Down Expand Up @@ -225,8 +227,10 @@ func TestHeadroomAssemblerCommon_GetHeadroom(t *testing.T) {
name: "disable util based",
fields: fields{
entries: map[string]*types.RegionInfo{
"share-0": {
RegionType: configapi.QoSRegionTypeShare,
"share": {
RegionType: configapi.QoSRegionTypeShare,
OwnerPoolName: "share",
BindingNumas: machine.NewCPUSet(0, 1),
},
},
cnr: &v1alpha1.CustomNodeResource{
Expand Down Expand Up @@ -271,8 +275,10 @@ func TestHeadroomAssemblerCommon_GetHeadroom(t *testing.T) {
name: "gap by oversold ratio",
fields: fields{
entries: map[string]*types.RegionInfo{
"share-0": {
RegionType: configapi.QoSRegionTypeShare,
"share": {
RegionType: configapi.QoSRegionTypeShare,
OwnerPoolName: "share",
BindingNumas: machine.NewCPUSet(0, 1),
},
},
cnr: &v1alpha1.CustomNodeResource{
Expand Down Expand Up @@ -317,8 +323,10 @@ func TestHeadroomAssemblerCommon_GetHeadroom(t *testing.T) {
name: "over maximum core utilization",
fields: fields{
entries: map[string]*types.RegionInfo{
"share-0": {
RegionType: configapi.QoSRegionTypeShare,
"share": {
RegionType: configapi.QoSRegionTypeShare,
OwnerPoolName: "share",
BindingNumas: machine.NewCPUSet(0, 1),
},
},
cnr: &v1alpha1.CustomNodeResource{
Expand Down Expand Up @@ -363,8 +371,10 @@ func TestHeadroomAssemblerCommon_GetHeadroom(t *testing.T) {
name: "limited by capacity",
fields: fields{
entries: map[string]*types.RegionInfo{
"share-0": {
RegionType: configapi.QoSRegionTypeShare,
"share": {
RegionType: configapi.QoSRegionTypeShare,
OwnerPoolName: "share",
BindingNumas: machine.NewCPUSet(0, 1),
},
},
cnr: &v1alpha1.CustomNodeResource{
Expand Down Expand Up @@ -407,6 +417,60 @@ func TestHeadroomAssemblerCommon_GetHeadroom(t *testing.T) {
},
want: *resource.NewQuantity(96, resource.DecimalSI),
},
{
name: "numa-exclusive region headroom",
fields: fields{
entries: map[string]*types.RegionInfo{
"dedicated": {
RegionType: configapi.QoSRegionTypeDedicatedNumaExclusive,
OwnerPoolName: "dedicated",
BindingNumas: machine.NewCPUSet(0),
Headroom: 10,
RegionStatus: types.RegionStatus{
BoundType: types.BoundUpper,
},
},
},
cnr: &v1alpha1.CustomNodeResource{
Status: v1alpha1.CustomNodeResourceStatus{
Resources: v1alpha1.Resources{
Allocatable: &v1.ResourceList{
consts.ReclaimedResourceMilliCPU: resource.MustParse("86000"),
},
},
},
},
reclaimedResourceConfiguration: &reclaimedresource.ReclaimedResourceConfiguration{
EnableReclaim: true,
CPUHeadroomConfiguration: &cpuheadroom.CPUHeadroomConfiguration{
CPUUtilBasedConfiguration: &cpuheadroom.CPUUtilBasedConfiguration{
Enable: false,
TargetReclaimedCoreUtilization: 0.6,
MaxReclaimedCoreUtilization: 0.8,
MaxOversoldRate: 1.5,
MaxHeadroomCapacityRate: 1.,
},
},
},
setFakeMetric: func(store *metric.FakeMetricsFetcher) {
now := time.Now()
for i := 0; i < 96; i++ {
store.SetCPUMetric(i, pkgconsts.MetricCPUUsageRatio, utilmetric.MetricData{Value: 0.3, Time: &now})
}
store.SetCgroupMetric("/kubepods/besteffort", pkgconsts.MetricCPUUsageCgroup, utilmetric.MetricData{Value: 28.8, Time: &now})
},
setMetaCache: func(cache *metacache.MetaCacheImp) {
err := cache.SetPoolInfo(state.PoolNameReclaim, &types.PoolInfo{
PoolName: state.PoolNameReclaim,
TopologyAwareAssignments: map[int]machine.CPUSet{
0: machine.MustParse("0-85"),
},
})
require.NoError(t, err)
},
},
want: *resource.NewQuantity(58, resource.DecimalSI),
},
}
for _, tt := range tests {
tt := tt
Expand Down Expand Up @@ -434,15 +498,17 @@ func TestHeadroomAssemblerCommon_GetHeadroom(t *testing.T) {

metaServer := generateTestMetaServer(t, tt.fields.cnr, tt.fields.podList, metricsFetcher)

if tt.fields.regions == nil {
shareRegion := region.NewQoSRegionBase("share", "share", configapi.QoSRegionTypeShare, conf, nil, false, metaCache, metaServer, metrics.DummyMetrics{})
shareRegion.SetBindingNumas(machine.NewCPUSet(0, 1))
for name, regionInfo := range tt.fields.entries {
r := region.NewQoSRegionBase(name, regionInfo.OwnerPoolName, regionInfo.RegionType, conf, nil, false, metaCache, metaServer, metrics.DummyMetrics{})
r.SetBindingNumas(regionInfo.BindingNumas)
tt.fields.regions = map[string]region.QoSRegion{
"share": shareRegion,
name: r,
}
}
reservedForReclaim := map[int]int{0: 2, 1: 2}
numaAvailable := map[int]int{0: 46, 1: 46}

ha := NewHeadroomAssemblerCommon(conf, nil, &tt.fields.regions, nil, nil, nil, metaCache, metaServer, metrics.DummyMetrics{})
ha := NewHeadroomAssemblerCommon(conf, nil, &tt.fields.regions, &reservedForReclaim, &numaAvailable, nil, metaCache, metaServer, metrics.DummyMetrics{})

store := metricsFetcher.(*metric.FakeMetricsFetcher)
tt.fields.setFakeMetric(store)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func (fake *FakeRegion) IsNumaBinding() bool {
return fake.isNumaBinding
}
func (fake *FakeRegion) SetThrottled(throttled bool) { fake.throttled = throttled }
func (fake *FakeRegion) EnableReclaim() bool { return true }
func (fake *FakeRegion) AddContainer(ci *types.ContainerInfo) error { return nil }
func (fake *FakeRegion) TryUpdateProvision() {}
func (fake *FakeRegion) TryUpdateHeadroom() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ type QoSRegion interface {

IsThrottled() bool

EnableReclaim() bool

// GetProvisionPolicy returns provision policy for this region,
// the first is policy with top priority, while the second is the policy that is in-use currently
GetProvisionPolicy() (types.CPUProvisionPolicyName, types.CPUProvisionPolicyName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func NewQoSRegionBase(name string, ownerPoolName string, regionType v1alpha1.QoS
if r.conf.PolicyRama.EnableBorwein {
r.borweinController = borweinctrl.NewBorweinController(name, regionType, ownerPoolName, conf, metaReader, emitter)
}
r.enableReclaim = r.EnableReclaim
r.enableReclaim = r.EnableReclaimFunc

klog.Infof("[qosaware-cpu] created region [%v/%v/%v]", r.Name(), r.Type(), r.OwnerPoolName())

Expand Down Expand Up @@ -447,6 +447,13 @@ func (r *QoSRegionBase) GetProvisionPolicy() (policyTopPriority types.CPUProvisi
return
}

func (r *QoSRegionBase) EnableReclaim() bool {
r.Lock()
defer r.Unlock()

return r.enableReclaim()
}

func (r *QoSRegionBase) GetHeadRoomPolicy() (policyTopPriority types.CPUHeadroomPolicyName, policyInUse types.CPUHeadroomPolicyName) {
r.Lock()
defer r.Unlock()
Expand Down Expand Up @@ -810,7 +817,7 @@ func (r *QoSRegionBase) updateOvershootStatus() bool {
return overshoot
}

func (r *QoSRegionBase) EnableReclaim() bool {
func (r *QoSRegionBase) EnableReclaimFunc() bool {
return r.ResourceEssentials.EnableReclaim
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/util/machine/zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ import (
"strings"
)

type NormalZoneInfo struct {
Node int64
Free uint64
Min uint64
Low uint64
FileInactive uint64
}

var nodeZoneRE = regexp.MustCompile(`(\d+), zone\s+(\w+)`)

func parseNormalZoneInfo(zoneInfoData []byte) ([]NormalZoneInfo, error) {
Expand Down
8 changes: 0 additions & 8 deletions pkg/util/machine/zone_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ import (
"os"
)

type NormalZoneInfo struct {
Node int64
Free uint64
Min uint64
Low uint64
FileInactive uint64
}

func GetNormalZoneInfo(zoneInfoPath string) []NormalZoneInfo {
data, err := os.ReadFile(zoneInfoPath)
if err != nil {
Expand Down

0 comments on commit 47cc1fc

Please sign in to comment.