Skip to content

Commit 89a8d81

Browse files
authored
Merge pull request #1053 from luomingmeng/dev/fix-min-reclaimed-cores-cpu-quota
fix min reclaimed cores cpu quota
2 parents d69afb8 + 5376904 commit 89a8d81

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/advisor.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,11 +606,40 @@ func (cra *cpuResourceAdvisor) emitMetrics(calculationResult types.InternalCPUCa
606606
_ = cra.emitter.StoreInt64(metricCPUAdvisorPoolSize, int64(cpuResource.Size), metrics.MetricTypeNameRaw,
607607
metrics.MetricTag{Key: "name", Val: poolName},
608608
metrics.MetricTag{Key: "numa_id", Val: strconv.Itoa(numaID)},
609-
metrics.MetricTag{Key: "pool_type", Val: commonstate.GetPoolType(poolName)})
609+
metrics.MetricTag{Key: "pool_type", Val: commonstate.GetPoolType(poolName)},
610+
metrics.MetricTag{Key: "overlap", Val: "none"})
610611
_ = cra.emitter.StoreFloat64(metricCPUAdvisorPoolQuota, cpuResource.Quota, metrics.MetricTypeNameRaw,
611612
metrics.MetricTag{Key: "name", Val: poolName},
612613
metrics.MetricTag{Key: "numa_id", Val: strconv.Itoa(numaID)},
613614
metrics.MetricTag{Key: "pool_type", Val: commonstate.GetPoolType(poolName)})
614615
}
615616
}
617+
618+
for poolName, overlapInfo := range calculationResult.PoolOverlapInfo {
619+
for numaID, poolOverlapInfo := range overlapInfo {
620+
for target, overlap := range poolOverlapInfo {
621+
_ = cra.emitter.StoreInt64(metricCPUAdvisorPoolSize, int64(overlap), metrics.MetricTypeNameRaw,
622+
metrics.MetricTag{Key: "name", Val: poolName},
623+
metrics.MetricTag{Key: "numa_id", Val: strconv.Itoa(numaID)},
624+
metrics.MetricTag{Key: "pool_type", Val: commonstate.GetPoolType(poolName)},
625+
metrics.MetricTag{Key: "overlap", Val: target})
626+
}
627+
}
628+
}
629+
630+
for poolName, overlapInfo := range calculationResult.PoolOverlapPodContainerInfo {
631+
for numaID, poolOverlapInfo := range overlapInfo {
632+
for podUID, overlapContainer := range poolOverlapInfo {
633+
// todo: current only emit first container overlap, because other containers' overlap is same now
634+
for _, overlap := range overlapContainer {
635+
_ = cra.emitter.StoreInt64(metricCPUAdvisorPoolSize, int64(overlap), metrics.MetricTypeNameRaw,
636+
metrics.MetricTag{Key: "name", Val: poolName},
637+
metrics.MetricTag{Key: "numa_id", Val: strconv.Itoa(numaID)},
638+
metrics.MetricTag{Key: "pool_type", Val: commonstate.GetPoolType(poolName)},
639+
metrics.MetricTag{Key: "overlap", Val: podUID})
640+
break
641+
}
642+
}
643+
}
644+
}
616645
}

pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/provisionassembler/assembler_common.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,18 @@ func (pa *ProvisionAssemblerCommon) assembleWithoutNUMAExclusivePool(
312312
poolSizes := make(map[string]int)
313313
sharePoolSizes := make(map[string]int)
314314
reclaimablePoolSizes := make(map[string]int)
315+
nonReclaimableSharePoolSizes := make(map[string]int)
316+
reclaimableShareRequirements := make(map[string]int)
315317
reclaimableRequirements := make(map[string]int)
316318
for poolName, size := range shareAndIsolateDedicatedPoolSizes {
317319
_, ok := sharePoolSizeRequirements[poolName]
318320
if ok {
319321
if shareInfo.reclaimEnable[poolName] {
320322
reclaimablePoolSizes[poolName] = size
323+
reclaimableShareRequirements[poolName] = shareInfo.requirements[poolName]
321324
reclaimableRequirements[poolName] = shareInfo.requirements[poolName]
325+
} else {
326+
nonReclaimableSharePoolSizes[poolName] = size
322327
}
323328
poolSizes[poolName] = size
324329
sharePoolSizes[poolName] = size
@@ -340,8 +345,10 @@ func (pa *ProvisionAssemblerCommon) assembleWithoutNUMAExclusivePool(
340345
}
341346

342347
overlapReclaimSize := make(map[string]int)
348+
// shareReclaimCoresSize is the size of cores that can be reclaimed from share pools
343349
shareReclaimCoresSize := shareAndIsolatedDedicatedPoolAvailable - isolated -
344-
general.SumUpMapValues(sharePoolSizeRequirements) - general.SumUpMapValues(dedicatedPoolSizes)
350+
general.SumUpMapValues(nonReclaimableSharePoolSizes) - general.SumUpMapValues(reclaimableShareRequirements) -
351+
general.SumUpMapValues(dedicatedPoolSizes)
345352
if nodeEnableReclaim {
346353
reclaimedCoresSize = shareReclaimCoresSize + dedicatedReclaimCoresSize
347354
if reclaimedCoresSize < reservedForReclaim {
@@ -402,8 +409,15 @@ func (pa *ProvisionAssemblerCommon) assembleWithoutNUMAExclusivePool(
402409
if quotaCtrlKnobEnabled && numaID != commonstate.FakedNUMAID && len(poolSizes) > 0 {
403410
reclaimedCoresQuota = float64(general.Max(reservedForReclaim, reclaimedCoresSize))
404411
if shareInfo.minReclaimedCoresCPUQuota != -1 || dedicatedInfo.minReclaimedCoresCPUQuota != -1 {
405-
reclaimedCoresQuota = general.MaxFloat64(float64(reservedForReclaim),
406-
general.MinFloat64(shareInfo.minReclaimedCoresCPUQuota, dedicatedInfo.minReclaimedCoresCPUQuota))
412+
if shareInfo.minReclaimedCoresCPUQuota != -1 {
413+
reclaimedCoresQuota = shareInfo.minReclaimedCoresCPUQuota
414+
}
415+
416+
if dedicatedInfo.minReclaimedCoresCPUQuota != -1 {
417+
reclaimedCoresQuota = general.MinFloat64(reclaimedCoresQuota, dedicatedInfo.minReclaimedCoresCPUQuota)
418+
}
419+
420+
reclaimedCoresQuota = general.MaxFloat64(reclaimedCoresQuota, float64(reservedForReclaim))
407421
}
408422

409423
// if cpu quota enabled, set all reclaimable share pool size to reclaimablePoolSizes
@@ -475,7 +489,8 @@ func (pa *ProvisionAssemblerCommon) assembleWithoutNUMAExclusivePool(
475489
}
476490
}
477491

478-
nonOverlapReclaimedCoresSize := reclaimedCoresSize - overlapReclaimedCoresSize
492+
// nonOverlapReclaimedCoresSize should be non-negative
493+
nonOverlapReclaimedCoresSize := general.Max(reclaimedCoresSize-overlapReclaimedCoresSize, 0)
479494
result.SetPoolEntry(commonstate.PoolNameReclaim, numaID, nonOverlapReclaimedCoresSize, reclaimedCoresQuota)
480495

481496
general.InfoS("assemble reclaim pool entry",

0 commit comments

Comments
 (0)