From 227d45c0055aaf23f2befa7fe82a2dd72a20fedc Mon Sep 17 00:00:00 2001 From: luomingmeng Date: Tue, 12 May 2026 01:25:48 +0800 Subject: [PATCH 1/2] refactor(memory qrm plugin): split advisor handler into linux and non-linux versions Move the cgroup-v1/v2 dependent handleAdvisorMemoryHot implementation to platform-specific files to support cross-compilation on non-linux systems --- .../dynamicpolicy/policy_advisor_handler.go | 38 ---------- .../policy_advisor_handler_linux.go | 76 +++++++++++++++++++ .../policy_advisor_handler_unsupported.go | 41 ++++++++++ 3 files changed, 117 insertions(+), 38 deletions(-) create mode 100644 pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler_linux.go create mode 100644 pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler_unsupported.go diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler.go index a642cb19ed..18d8668e5f 100644 --- a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler.go +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler.go @@ -26,7 +26,6 @@ import ( "strconv" "time" - "github.com/opencontainers/runc/libcontainer/cgroups" "github.com/samber/lo" "google.golang.org/grpc" "google.golang.org/grpc/metadata" @@ -394,43 +393,6 @@ func (p *DynamicPolicy) handleAdvisorResp(advisorResp *advisorsvc.ListAndWatchRe return nil } -func (p *DynamicPolicy) handleAdvisorMemoryHigh( - _ *config.Configuration, - _ interface{}, - _ *dynamicconfig.DynamicAgentConfiguration, - emitter metrics.MetricEmitter, - metaServer *metaserver.MetaServer, - entryName, subEntryName string, - calculationInfo *advisorsvc.CalculationInfo, podResourceEntries state.PodResourceEntries, -) error { - memoryHighStr := calculationInfo.CalculationResult.Values[string(memoryadvisor.ControlKnobKeyMemoryHigh)] - memoryHigh, err := strconv.ParseInt(memoryHighStr, 10, 64) - if err != nil { - return fmt.Errorf("parse %s: %s failed with error: %v", memoryadvisor.ControlKnobKeyMemoryHigh, memoryHighStr, err) - } - - if !cgroups.IsCgroup2UnifiedMode() { - general.Infof("memory.high is not supported in cgroupv1 mode") - return nil - } - - if calculationInfo.CgroupPath != "" { - if err = cgroupmgr.ApplyMemoryWithRelativePath(calculationInfo.CgroupPath, &common.MemoryData{ - HighInBytes: memoryHigh, - }); err != nil { - return fmt.Errorf("apply memory.high failed with error: %v", err) - } - - _ = emitter.StoreInt64(util.MetricNameMemoryHandleAdvisorMemoryHigh, memoryHigh, - metrics.MetricTypeNameRaw, metrics.ConvertMapToTags(map[string]string{ - "cgroupPath": calculationInfo.CgroupPath, - })...) - return nil - } - - return nil -} - func (p *DynamicPolicy) handleAdvisorMemoryLimitInBytes( _ *config.Configuration, _ interface{}, diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler_linux.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler_linux.go new file mode 100644 index 0000000000..36cf269808 --- /dev/null +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler_linux.go @@ -0,0 +1,76 @@ +//go:build linux +// +build linux + +/* +Copyright 2022 The Katalyst Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package dynamicpolicy + +import ( + "fmt" + "strconv" + + "github.com/opencontainers/runc/libcontainer/cgroups" + + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/advisorsvc" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/memory/dynamicpolicy/memoryadvisor" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/memory/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/util" + "github.com/kubewharf/katalyst-core/pkg/config" + dynamicconfig "github.com/kubewharf/katalyst-core/pkg/config/agent/dynamic" + "github.com/kubewharf/katalyst-core/pkg/metaserver" + "github.com/kubewharf/katalyst-core/pkg/metrics" + "github.com/kubewharf/katalyst-core/pkg/util/cgroup/common" + cgroupmgr "github.com/kubewharf/katalyst-core/pkg/util/cgroup/manager" + "github.com/kubewharf/katalyst-core/pkg/util/general" +) + +func (p *DynamicPolicy) handleAdvisorMemoryHigh( + _ *config.Configuration, + _ interface{}, + _ *dynamicconfig.DynamicAgentConfiguration, + emitter metrics.MetricEmitter, + metaServer *metaserver.MetaServer, + entryName, subEntryName string, + calculationInfo *advisorsvc.CalculationInfo, podResourceEntries state.PodResourceEntries, +) error { + memoryHighStr := calculationInfo.CalculationResult.Values[string(memoryadvisor.ControlKnobKeyMemoryHigh)] + memoryHigh, err := strconv.ParseInt(memoryHighStr, 10, 64) + if err != nil { + return fmt.Errorf("parse %s: %s failed with error: %v", memoryadvisor.ControlKnobKeyMemoryHigh, memoryHighStr, err) + } + + if !cgroups.IsCgroup2UnifiedMode() { + general.Infof("memory.high is not supported in cgroupv1 mode") + return nil + } + + if calculationInfo.CgroupPath != "" { + if err = cgroupmgr.ApplyMemoryWithRelativePath(calculationInfo.CgroupPath, &common.MemoryData{ + HighInBytes: memoryHigh, + }); err != nil { + return fmt.Errorf("apply memory.high failed with error: %v", err) + } + + _ = emitter.StoreInt64(util.MetricNameMemoryHandleAdvisorMemoryHigh, memoryHigh, + metrics.MetricTypeNameRaw, metrics.ConvertMapToTags(map[string]string{ + "cgroupPath": calculationInfo.CgroupPath, + })...) + return nil + } + + return nil +} diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler_unsupported.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler_unsupported.go new file mode 100644 index 0000000000..e9a4519876 --- /dev/null +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler_unsupported.go @@ -0,0 +1,41 @@ +//go:build !linux +// +build !linux + +/* +Copyright 2022 The Katalyst Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package dynamicpolicy + +import ( + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/advisorsvc" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/memory/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/config" + dynamicconfig "github.com/kubewharf/katalyst-core/pkg/config/agent/dynamic" + "github.com/kubewharf/katalyst-core/pkg/metaserver" + "github.com/kubewharf/katalyst-core/pkg/metrics" +) + +func (p *DynamicPolicy) handleAdvisorMemoryHigh( + _ *config.Configuration, + _ interface{}, + _ *dynamicconfig.DynamicAgentConfiguration, + emitter metrics.MetricEmitter, + metaServer *metaserver.MetaServer, + entryName, subEntryName string, + calculationInfo *advisorsvc.CalculationInfo, podResourceEntries state.PodResourceEntries, +) error { + return nil +} From d305a35886d6c45085d31bc6e55f67c4eb467c78 Mon Sep 17 00:00:00 2001 From: luomingmeng Date: Mon, 11 May 2026 22:08:41 +0800 Subject: [PATCH 2/2] feat(qrm): add topology assignments to CPU allocation response - Plumb topology assignments through resource allocation state. - Surface topology assignments on the CPU QRM plugin allocation response. --- .../qrm-plugins/cpu/dynamicpolicy/policy.go | 19 +++-- .../cpu/dynamicpolicy/policy_test.go | 22 ++++++ .../cpu/dynamicpolicy/resize_test.go | 72 +++++++++++++++++++ .../memory/dynamicpolicy/policy_test.go | 42 +++++++---- .../memory/dynamicpolicy/state/state.go | 16 +++-- 5 files changed, 145 insertions(+), 26 deletions(-) diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy.go index 56f3a65037..390049b578 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy.go @@ -685,15 +685,22 @@ func (p *DynamicPolicy) GetResourcesAllocation(_ context.Context, if podResources[podUID].ContainerResources == nil { podResources[podUID].ContainerResources = make(map[string]*pluginapi.ResourceAllocation) } + + topologyAssignments := make(map[uint64]uint64) + for numaID, cset := range allocationInfo.TopologyAwareAssignments { + topologyAssignments[uint64(numaID)] = uint64(cset.Size()) + } + podResources[podUID].ContainerResources[containerName] = &pluginapi.ResourceAllocation{ ResourceAllocation: map[string]*pluginapi.ResourceAllocationInfo{ string(v1.ResourceCPU): { - OciPropertyName: util.OCIPropertyNameCPUSetCPUs, - IsNodeResource: false, - IsScalarResource: true, - AllocatedQuantity: float64(allocationInfo.AllocationResult.Size()), - AllocationResult: allocationInfo.AllocationResult.String(), - Annotations: general.DeepCopyMap(allocationInfo.Annotations), + OciPropertyName: util.OCIPropertyNameCPUSetCPUs, + IsNodeResource: false, + IsScalarResource: true, + AllocatedQuantity: float64(allocationInfo.AllocationResult.Size()), + AllocationResult: allocationInfo.AllocationResult.String(), + TopologyAssignments: topologyAssignments, + Annotations: general.DeepCopyMap(allocationInfo.Annotations), }, }, } diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_test.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_test.go index 2e656e0b45..d71ce65cf1 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_test.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_test.go @@ -5776,6 +5776,12 @@ func TestGetResourcesAllocation(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 10, AllocationResult: cpuTopology.CPUDetails.CPUs().Difference(dynamicPolicy.reservedCPUs).Difference(reclaim.AllocationResult).String(), + TopologyAssignments: map[uint64]uint64{ + 0: 3, + 1: 3, + 2: 2, + 3: 2, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, }, @@ -5803,6 +5809,12 @@ func TestGetResourcesAllocation(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 10, AllocationResult: machine.NewCPUSet(1, 3, 4, 5, 6, 7, 8, 9, 10, 11).String(), + TopologyAssignments: map[uint64]uint64{ + 0: 3, + 1: 3, + 2: 2, + 3: 2, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, }, @@ -5843,6 +5855,10 @@ func TestGetResourcesAllocation(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 4, AllocationResult: machine.NewCPUSet(12, 13, 14, 15).String(), + TopologyAssignments: map[uint64]uint64{ + uint64(2): 2, + uint64(3): 2, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, }, @@ -5909,6 +5925,12 @@ func TestGetResourcesAllocation(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 14, AllocationResult: machine.NewCPUSet(1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).String(), + TopologyAssignments: map[uint64]uint64{ + uint64(0): 3, + uint64(1): 3, + uint64(2): 4, + uint64(3): 4, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, }, diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/resize_test.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/resize_test.go index bdbad0e708..bb3924977b 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/resize_test.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/resize_test.go @@ -118,6 +118,9 @@ func TestSNBVPA(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 3, // 分配到numa0 (cpu0 -> reserved, cpu1,cpu8,cpu9 for snb) AllocationResult: "1,8-9", + TopologyAssignments: map[uint64]uint64{ + uint64(0): 3, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, @@ -216,6 +219,9 @@ func TestSNBVPA(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 3, // 分配到numa0 (cpu0 -> reserved, cpu1,cpu8,cpu9 for snb) AllocationResult: "1,8-9", + TopologyAssignments: map[uint64]uint64{ + uint64(0): 3, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, @@ -374,6 +380,9 @@ func TestSNBInplaceUpdateResizeWithSidecar(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 11, // 分配到numa0 (cpu0 -> reserved, cpu1~cpu5,cpu24~cpu29 for snb) AllocationResult: "1-5,24-29", + TopologyAssignments: map[uint64]uint64{ + uint64(0): 11, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, @@ -404,6 +413,9 @@ func TestSNBInplaceUpdateResizeWithSidecar(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 11, // 分配到numa0 (cpu0 -> reserved, cpu1~cpu5,cpu24~cpu29 for snb) AllocationResult: "1-5,24-29", + TopologyAssignments: map[uint64]uint64{ + uint64(0): 11, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, @@ -487,6 +499,9 @@ func TestSNBInplaceUpdateResizeWithSidecar(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 11, // 分配到numa0 (cpu0 -> reserved, cpu1~cpu5,cpu24~cpu29 for snb) AllocationResult: "1-5,24-29", + TopologyAssignments: map[uint64]uint64{ + uint64(0): 11, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, @@ -506,6 +521,9 @@ func TestSNBInplaceUpdateResizeWithSidecar(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 11, // 分配到numa0 (cpu0 -> reserved, cpu1~cpu5,cpu24~cpu29 for snb) AllocationResult: "1-5,24-29", + TopologyAssignments: map[uint64]uint64{ + uint64(0): 11, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, @@ -639,6 +657,9 @@ func TestSNBInplaceUpdateResizeWithSidecar(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 11, // 分配到numa0 (cpu0 -> reserved, cpu1~cpu5,cpu24~cpu29 for snb) AllocationResult: "1-5,24-29", + TopologyAssignments: map[uint64]uint64{ + uint64(0): 11, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, @@ -658,6 +679,9 @@ func TestSNBInplaceUpdateResizeWithSidecar(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 11, // 分配到numa0 (cpu0 -> reserved, cpu1~cpu5,cpu24~cpu29 for snb) AllocationResult: "1-5,24-29", + TopologyAssignments: map[uint64]uint64{ + uint64(0): 11, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, @@ -757,6 +781,12 @@ func TestNonBindingShareCoresInplaceUpdateResize(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 10, AllocationResult: cpuTopology.CPUDetails.CPUs().Difference(dynamicPolicy.reservedCPUs).Difference(reclaim.AllocationResult).String(), + TopologyAssignments: map[uint64]uint64{ + uint64(0): 3, + uint64(1): 3, + uint64(2): 2, + uint64(3): 2, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, }, @@ -829,6 +859,12 @@ func TestNonBindingShareCoresInplaceUpdateResize(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 10, AllocationResult: cpuTopology.CPUDetails.CPUs().Difference(dynamicPolicy.reservedCPUs).Difference(reclaim.AllocationResult).String(), + TopologyAssignments: map[uint64]uint64{ + uint64(0): 3, + uint64(1): 3, + uint64(2): 2, + uint64(3): 2, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, consts.PodAnnotationInplaceUpdateResizingKey: "true", @@ -915,6 +951,12 @@ func TestNonBindingShareCoresInplaceUpdateResizeWithSidecar(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 42, AllocationResult: cpuTopology.CPUDetails.CPUs().Difference(dynamicPolicy.reservedCPUs).Difference(reclaim.AllocationResult).String(), + TopologyAssignments: map[uint64]uint64{ + uint64(0): 11, + uint64(1): 11, + uint64(2): 10, + uint64(3): 10, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, consts.PodAnnotationAggregatedRequestsKey: "{\"cpu\":\"3\"}", @@ -968,6 +1010,12 @@ func TestNonBindingShareCoresInplaceUpdateResizeWithSidecar(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 42, AllocationResult: cpuTopology.CPUDetails.CPUs().Difference(dynamicPolicy.reservedCPUs).Difference(reclaim.AllocationResult).String(), + TopologyAssignments: map[uint64]uint64{ + uint64(0): 11, + uint64(1): 11, + uint64(2): 10, + uint64(3): 10, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, consts.PodAnnotationAggregatedRequestsKey: "{\"cpu\":\"3\"}", @@ -1030,6 +1078,12 @@ func TestNonBindingShareCoresInplaceUpdateResizeWithSidecar(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 42, AllocationResult: cpuTopology.CPUDetails.CPUs().Difference(dynamicPolicy.reservedCPUs).Difference(reclaim.AllocationResult).String(), + TopologyAssignments: map[uint64]uint64{ + uint64(0): 11, + uint64(1): 11, + uint64(2): 10, + uint64(3): 10, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, consts.PodAnnotationInplaceUpdateResizingKey: "true", @@ -1046,6 +1100,12 @@ func TestNonBindingShareCoresInplaceUpdateResizeWithSidecar(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 42, AllocationResult: cpuTopology.CPUDetails.CPUs().Difference(dynamicPolicy.reservedCPUs).Difference(reclaim.AllocationResult).String(), + TopologyAssignments: map[uint64]uint64{ + uint64(0): 11, + uint64(1): 11, + uint64(2): 10, + uint64(3): 10, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, consts.PodAnnotationInplaceUpdateResizingKey: "true", @@ -1117,6 +1177,12 @@ func TestNonBindingShareCoresInplaceUpdateResizeWithSidecar(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 42, AllocationResult: cpuTopology.CPUDetails.CPUs().Difference(dynamicPolicy.reservedCPUs).Difference(reclaim.AllocationResult).String(), + TopologyAssignments: map[uint64]uint64{ + uint64(0): 11, + uint64(1): 11, + uint64(2): 10, + uint64(3): 10, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, consts.PodAnnotationInplaceUpdateResizingKey: "true", @@ -1133,6 +1199,12 @@ func TestNonBindingShareCoresInplaceUpdateResizeWithSidecar(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 42, AllocationResult: cpuTopology.CPUDetails.CPUs().Difference(dynamicPolicy.reservedCPUs).Difference(reclaim.AllocationResult).String(), + TopologyAssignments: map[uint64]uint64{ + uint64(0): 11, + uint64(1): 11, + uint64(2): 10, + uint64(3): 10, + }, Annotations: map[string]string{ consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, consts.PodAnnotationInplaceUpdateResizingKey: "true", diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_test.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_test.go index 3ab5fe3fe6..f02be4bb5b 100644 --- a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_test.go +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_test.go @@ -3026,11 +3026,12 @@ func TestGetResourcesAllocation(t *testing.T) { } }, expectedMemory: &pluginapi.ResourceAllocationInfo{ - OciPropertyName: util.OCIPropertyNameCPUSetMems, - IsNodeResource: false, - IsScalarResource: true, - AllocatedQuantity: 1073741824, - AllocationResult: machine.NewCPUSet(0, 1, 2, 3).String(), + OciPropertyName: util.OCIPropertyNameCPUSetMems, + IsNodeResource: false, + IsScalarResource: true, + AllocatedQuantity: 1073741824, + AllocationResult: machine.NewCPUSet(0, 1, 2, 3).String(), + TopologyAssignments: map[uint64]uint64{}, }, }, { @@ -3058,11 +3059,12 @@ func TestGetResourcesAllocation(t *testing.T) { } }, expectedMemory: &pluginapi.ResourceAllocationInfo{ - OciPropertyName: util.OCIPropertyNameCPUSetMems, - IsNodeResource: false, - IsScalarResource: true, - AllocatedQuantity: 1073741824, - AllocationResult: machine.NewCPUSet(0, 1, 2, 3).String(), + OciPropertyName: util.OCIPropertyNameCPUSetMems, + IsNodeResource: false, + IsScalarResource: true, + AllocatedQuantity: 1073741824, + AllocationResult: machine.NewCPUSet(0, 1, 2, 3).String(), + TopologyAssignments: map[uint64]uint64{}, }, }, { @@ -3100,6 +3102,9 @@ func TestGetResourcesAllocation(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 7516192768, AllocationResult: machine.NewCPUSet(0).String(), + TopologyAssignments: map[uint64]uint64{ + 0: 7516192768, + }, }, }, { @@ -3132,11 +3137,12 @@ func TestGetResourcesAllocation(t *testing.T) { } }, expectedMemory: &pluginapi.ResourceAllocationInfo{ - OciPropertyName: util.OCIPropertyNameCPUSetMems, - IsNodeResource: false, - IsScalarResource: true, - AllocatedQuantity: 0, - AllocationResult: machine.NewCPUSet(0, 1, 2, 3).String(), + OciPropertyName: util.OCIPropertyNameCPUSetMems, + IsNodeResource: false, + IsScalarResource: true, + AllocatedQuantity: 0, + AllocationResult: machine.NewCPUSet(0, 1, 2, 3).String(), + TopologyAssignments: map[uint64]uint64{}, }, }, { @@ -3236,6 +3242,9 @@ func TestGetResourcesAllocation(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 2147483648, AllocationResult: machine.NewCPUSet(0).String(), + TopologyAssignments: map[uint64]uint64{ + 0: 2147483648, + }, }, checkHugepages: true, expectedHugepages: &pluginapi.ResourceAllocationInfo{ @@ -3244,6 +3253,9 @@ func TestGetResourcesAllocation(t *testing.T) { IsScalarResource: true, AllocatedQuantity: 2147483648, AllocationResult: machine.NewCPUSet(0).String(), + TopologyAssignments: map[uint64]uint64{ + 0: 2147483648, + }, }, }, } diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/state/state.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/state/state.go index 959ca8e1cb..964208775d 100644 --- a/pkg/agent/qrm-plugins/memory/dynamicpolicy/state/state.go +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/state/state.go @@ -217,12 +217,18 @@ func (pre PodResourceEntries) GetResourceAllocation(podUID, containerName string continue } + topologyAssignments := make(map[uint64]uint64) + for numaID, quantity := range allocationInfo.TopologyAwareAllocations { + topologyAssignments[uint64(numaID)] = quantity + } + resourceAllocation[string(resourceName)] = &pluginapi.ResourceAllocationInfo{ - OciPropertyName: util.OCIPropertyNameCPUSetMems, - IsNodeResource: false, - IsScalarResource: true, - AllocatedQuantity: float64(allocationInfo.AggregatedQuantity), - AllocationResult: allocationInfo.NumaAllocationResult.String(), + OciPropertyName: util.OCIPropertyNameCPUSetMems, + IsNodeResource: false, + IsScalarResource: true, + AllocatedQuantity: float64(allocationInfo.AggregatedQuantity), + AllocationResult: allocationInfo.NumaAllocationResult.String(), + TopologyAssignments: topologyAssignments, } // deal with accompanying resources