← Back to Pull requests

DRA: pass memory policy settings in claim configs #857

Merged
bart0sh merged 31 files (1919 lines) on Oct 20, 2026 10:15 UTC
View on GitHub
bart0sh bart0sh commented on Oct 16, 2026 14:47 UTC
Author

Passing memory policy settings in claim configs

A claim can now set the memory policy of the containers that hold it, in an opaque config for the topology-aware driver:

config:
- requests: [first]        # optional: only the containers holding these requests
  opaque:
    driver: topology-aware.nri.io
    parameters:
      apiVersion: config.nri/v1alpha1
      kind: TopologyAwareClaimConfig
      memoryPolicy:
        mode: interleave
        nodes: allowed-mems

memoryPolicy has the same fields as the policy.memory-policy.nri.io annotation of the memory-policy plugin, with short mode and flag names such as interleave and static-nodes. The policy spec and the node resolution of the plugin move to the policy config API and libmem, so that both use the same code. The plugin works as before.

The policy decodes and checks the configs when the claim is prepared. A bad config fails the prepare, and the pod's events show the error. The config can also be in the DeviceClass. Class configs come first, and a later config overrides an earlier one. A config which names some requests applies only to the containers holding those requests.

A container holding the claim gets the memory policy in its NRI adjustment when it is created, with the nodes resolved for its CPUs and memory nodes. Creating a container holding claims with different memory policies fails. Template refuses a claim with a config, and balloons does not support claims yet.

Tested with new unit tests and test45, which runs a claim with one CPU on node 0 and one on node 1 with an interleave policy. A container holding both requests gets interleave:0-1, one holding only the first request gets interleave:0, and a claim with an unknown mode fails to prepare.

Diff: 1919 lines (+1762 / -157) across 31 files Reviewer: bart0sh Review duration: 5488m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.96) × (1 − Review Confidence (0.84)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.96 · 1919 lines diff across 31 files
0.96
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.91 · 5 substantive comment(s)
0.91
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
83%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.400
Self Review self_review
0.140
Sensitive Paths sensitive_paths
0.096
Mass File Touch mass_file_touch
0.080
Real PR Conversation Timeline
41 items
Copilot Copilot commented on code on Oct 17, 2026 19:45 UTC
Code Review
cmd/plugins/topology-aware/policy/dra.go:1
@@ -54,16 +65,21 @@ const (
 	draAttrSocketID resourceapi.QualifiedName = "dra.cpu/socketID"
 	// draAttrSMTEnabled tells whether the CPUs have SMT enabled.
 	draAttrSMTEnabled resourceapi.QualifiedName = "dra.cpu/smtEnabled"
+	// draConfigAPIVersion and draConfigKind identify our claim configs.
+	draConfigAPIVersion = "config.nri/v1alpha1"
+	draConfigKind       = "TopologyAwareClaimConfig"
 )
 
 // draDriverName is the name of our DRA driver.
 var draDriverName = dra.DriverName(PolicyName)
 
 // claim is a DRA claim we allocated. It has a grant of all of its CPUs, and
-// the CPUs of each of its allocation results, in result order.
+// the CPUs and the memory policy of each of its allocation results, in result
+// order. mpols is nil if no result has a memory policy.
 type claim struct {
 	Grant
 	results []cpuset.CPUSet
+	mpols   []*cfgapi.MemoryPolicy

allocations.clone() in topology-aware-policy.go:764 reconstructs each claim with only Grant and results, dropping this new field. Reconfigure clones allocations before restoring them, so a successful reload loses claim memory policies: new containers receive no policy, and preparing an existing claim again fails the consistency check. Copy mpols in the claim-cloning path (for example, with slices.Clone(c.mpols)) and add a reconfiguration regression test.

Copilot Copilot commented on code on Oct 17, 2026 19:45 UTC
Code Review
cmd/plugins/topology-aware/policy/dra.go:1
@@ -209,22 +234,119 @@ func (p *policy) ReleaseClaim(uid types.UID) error {
 	return nil
 }
 
-// containerClaims returns the CPUs of the claim results a container holds.
-// It ignores results we do not know.
-func (p *policy) containerClaims(c cache.Container) cpuset.CPUSet {
-	cpus := cpuset.New()
+// containerClaims returns the CPUs and the memory policy of the claim results
+// a container holds. It ignores results we do not know, and fails if the
+// results have different memory policies.
+func (p *policy) containerClaims(c cache.Container) (cpuset.CPUSet, *cfgapi.MemoryPolicy, error) {
+	var (
+		cpus = cpuset.New()
+		mpol *cfgapi.MemoryPolicy
+		from types.UID
+	)
 	for uid, indexes := range dra.ContainerClaims(c, draDriverName) {
 		claim, ok := p.allocations.claims[string(uid)]
 		if !ok {
 			continue
 		}
 		for _, i := range indexes {
-			if i < len(claim.results) {
-				cpus = cpus.Union(claim.results[i])
+			if i >= len(claim.results) {
+				continue
+			}
+			cpus = cpus.Union(claim.results[i])
+			if i >= len(claim.mpols) || claim.mpols[i] == nil {
+				continue
+			}
+			if mpol == nil {
+				mpol, from = claim.mpols[i], uid
+			} else if !reflect.DeepEqual(mpol, claim.mpols[i]) {
+				return cpuset.New(), nil, fmt.Errorf("memory policy %s of claim %s conflicts with %s of claim %s",
+					claim.mpols[i], uid, mpol, from)
+			}
+		}
+	}
+	return cpus, mpol, nil
+}
+
+// claimMemoryPolicies returns the memory policies of the claim results, or nil
+// if there are none. A later config overrides an earlier one.
+func (p *policy) claimMemoryPolicies(results []resourceapi.DeviceRequestAllocationResult,
+	configs []resourceapi.DeviceAllocationConfiguration) ([]*cfgapi.MemoryPolicy, error) {
+	var mpols []*cfgapi.MemoryPolicy
+	for i, config := range configs {
+		cfg, err := decodeClaimConfig(config.Opaque.Parameters.Raw)
+		if err != nil {
+			return nil, fmt.Errorf("config %d: %w", i, err)
+		}
+		if cfg.MemoryPolicy == nil {
+			continue
+		}
+		mpol, err := cfg.MemoryPolicy.ToMemoryPolicy()
+		if err != nil {
+			return nil, fmt.Errorf("config %d: %w", i, err)
+		}
+		// The nodes are resolved later, for each container. Resolving them
+		// here with no CPUs only checks the value.
+		if _, err := libmem.MemoryPolicyNodes(p.sys, mpol.Mode, mpol.Nodes, cpuset.New(), libmem.NewNodeMask()); err != nil {
+			return nil, fmt.Errorf("config %d: %w", i, err)
+		}
+		for j, r := range results {
+			if !configApplies(config.Requests, r.Request) {
+				continue
 			}
+			if mpols == nil {
+				mpols = make([]*cfgapi.MemoryPolicy, len(results))
+			}
+			mpols[j] = mpol
 		}
 	}
-	return cpus
+	return mpols, nil
+}
+
+// decodeClaimConfig decodes the parameters of a claim config.
+func decodeClaimConfig(data []byte) (*cfgapi.TopologyAwareClaimConfig, error) {
+	cfg := &cfgapi.TopologyAwareClaimConfig{}
+	if err := yaml.UnmarshalStrict(data, cfg); err != nil {
+		return nil, err
+	}
+	if cfg.APIVersion != draConfigAPIVersion || cfg.Kind != draConfigKind {
+		return nil, fmt.Errorf("got apiVersion %q and kind %q, expected %q and %q",
+			cfg.APIVersion, cfg.Kind, draConfigAPIVersion, draConfigKind)
+	}
+	return cfg, nil
+}
+
+// configApplies tells whether a config applies to a result of request.
+// requests are the requests the config names. A config naming no requests
+// applies to all results. A config naming a request also applies to its
+// subrequests.
+func configApplies(requests []string, request string) bool {
+	main, _, _ := strings.Cut(request, "/")
+	return len(requests) == 0 || slices.Contains(requests, request) || slices.Contains(requests, main)
+}
+
+// applyMemoryPolicy sets the memory policy of a new container to the policy of
+// its claims. The runtime applies it when the container starts.
+//
+// The policy's nodes, such as cpu-nodes, are resolved for the container's CPUs
+// and memory nodes. If the container's memory is not pinned, all nodes are
+// allowed.
+func (p *policy) applyMemoryPolicy(c cache.Container, mpol *cfgapi.MemoryPolicy, cpus cpuset.CPUSet, mems libmem.NodeMask) {
+	if mems == libmem.NodeMask(0) {
+		mems = libmem.NewNodeMask(p.sys.NodeIDs()...)
+	}

When memory resources are preserved, applyGrant leaves cpuset.mems unchanged but passes the grant's memory zone here (or zero if pinning is disabled). An omitted or allowed-mems selector therefore uses the wrong mask. For example, preserved node 2 with a grant on node 0 produces an interleave policy targeting a disallowed node, which can fail container startup. Read the preserved cpuset.mems before resolving the policy.

Copilot Copilot commented on code on Oct 17, 2026 19:45 UTC
Code Review
cmd/plugins/topology-aware/policy/dra.go:1
@@ -209,22 +234,119 @@ func (p *policy) ReleaseClaim(uid types.UID) error {
 	return nil
 }
 
-// containerClaims returns the CPUs of the claim results a container holds.
-// It ignores results we do not know.
-func (p *policy) containerClaims(c cache.Container) cpuset.CPUSet {
-	cpus := cpuset.New()
+// containerClaims returns the CPUs and the memory policy of the claim results
+// a container holds. It ignores results we do not know, and fails if the
+// results have different memory policies.
+func (p *policy) containerClaims(c cache.Container) (cpuset.CPUSet, *cfgapi.MemoryPolicy, error) {
+	var (
+		cpus = cpuset.New()
+		mpol *cfgapi.MemoryPolicy
+		from types.UID
+	)
 	for uid, indexes := range dra.ContainerClaims(c, draDriverName) {
 		claim, ok := p.allocations.claims[string(uid)]
 		if !ok {
 			continue
 		}
 		for _, i := range indexes {
-			if i < len(claim.results) {
-				cpus = cpus.Union(claim.results[i])
+			if i >= len(claim.results) {
+				continue
+			}
+			cpus = cpus.Union(claim.results[i])
+			if i >= len(claim.mpols) || claim.mpols[i] == nil {
+				continue
+			}
+			if mpol == nil {
+				mpol, from = claim.mpols[i], uid
+			} else if !reflect.DeepEqual(mpol, claim.mpols[i]) {
+				return cpuset.New(), nil, fmt.Errorf("memory policy %s of claim %s conflicts with %s of claim %s",
+					claim.mpols[i], uid, mpol, from)
+			}

A claim with mode: interleave and omitted nodes has the same policy as one explicitly using nodes: allowed-mems. However, conversion preserves the different strings, so DeepEqual treats them as conflicting and prevents a container from holding both claims. Compare these documented equivalent node defaults consistently.

Copilot Copilot commented on code on Oct 17, 2026 19:45 UTC
Code Review
cmd/plugins/topology-aware/policy/resources.go:1
@@ -809,8 +822,13 @@ func (p *policy) newRequest(container cache.Container, types libmem.TypeMask) (R
 	// The DRA claims of a container are fixed for its lifetime, so they are
 	// looked up once, here.
 	claimed := cpuset.New()
+	var mpol *cfgapi.MemoryPolicy
 	if cpuType != cpuPreserve {
-		claimed = p.containerClaims(container)
+		var err error
+		claimed, mpol, err = p.containerClaims(container)

With cpu.preserve.resource-policy.nri.io: "true", the enclosing guard skips claim memory-policy lookup and conflict validation as well as CPU handling. Containers silently lose their claim's memory policy and can hold conflicting policies, although the annotation only preserves CPU resources. Fetch and validate claim policies independently of cpuPreserve, keep CPU pinning unchanged, and resolve CPU-based node selectors against the preserved CPU set.

copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 17, 2026 19:45 UTC
Reviewer

<!-- ccr-overview-v2 -->

🟡 Changes recommended

Reloads lose claim policies, resource preservation mishandles them, and equivalent policies can incorrectly block container creation.

<details open>
<summary><strong>4 open issues</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> Clone claim memory policies during allocation reconfiguration · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> Resolve memory policy against preserved cpuset.mems · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Normalize equivalent omitted and allowed-mems node defaults · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Preserve memory policies independently of CPU resource preservation · New

  • </details>

    <details>
    <summary><strong>1 file not reviewed</strong></summary>

    <ul>
    <li><strong><code>pkg/apis/config/v1alpha1/resmgr/policy/zz_generated.deepcopy.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <details>
    <summary><strong>What changed in this PR</strong></summary>

    Adds claim-configured memory policies to topology-aware DRA, reusing the memory-policy plugin’s configuration and node resolution.

    Changes:

  • Decodes request-scoped claim policies and applies them during container creation.

  • Persists claim policies and rejects conflicting or unsupported configs.

  • Adds unit and end-to-end coverage.
  • | File | Description |
    | ---- | ----------- |
    | test/​e2e/​policies.test-suite/​topology-aware/​n4c16/​test45-dra-memory-policy/​mempolicy-pod.yaml.in | Defines request-selective test containers. |
    | test/​e2e/​policies.test-suite/​topology-aware/​n4c16/​test45-dra-memory-policy/​mempolicy-claim.yaml.in | Defines configurable test claims. |
    | test/​e2e/​policies.test-suite/​topology-aware/​n4c16/​test45-dra-memory-policy/​deviceclass.yaml.in | Selects topology-aware devices. |
    | test/​e2e/​policies.test-suite/​topology-aware/​n4c16/​test45-dra-memory-policy/​code.var.sh | Checks applied policies and invalid configs. |
    | pkg/​resmgr/​policy/​policy.go | Documents claim-config handling. |
    | pkg/​resmgr/​lib/​memory/​policy.go | Shares memory-node resolution. |
    | pkg/​resmgr/​lib/​memory/​policy_test.go | Tests node resolution. |
    | pkg/​resmgr/​dra/​claim.go | Adds driver-specific config extraction. |
    | pkg/​resmgr/​dra/​claim_test.go | Tests config extraction. |
    | pkg/​resmgr/​cache/​container.go | Records memory-policy adjustments. |
    | pkg/​resmgr/​cache/​container_test.go | Tests creation-only adjustments. |
    | pkg/​resmgr/​cache/​cache.go | Exposes the memory-policy setter. |
    | pkg/​apis/​config/​v1alpha1/​resmgr/​policy/​zz_generated.deepcopy.go | Adds memory-policy deep copying. |
    | pkg/​apis/​config/​v1alpha1/​resmgr/​policy/​topologyaware/​config.go | Aliases the shared policy type. |
    | pkg/​apis/​config/​v1alpha1/​resmgr/​policy/​topologyaware/​claimconfig.go | Defines claim config and short-name conversion. |
    | pkg/​apis/​config/​v1alpha1/​resmgr/​policy/​topologyaware/​claimconfig_test.go | Tests claim policy conversion. |
    | pkg/​apis/​config/​v1alpha1/​resmgr/​policy/​memorypolicy.go | Defines shared policy and NRI conversion. |
    | cmd/​plugins/​topology-aware/​policy/​resources.go | Carries claim policies through resource grants. |
    | cmd/​plugins/​topology-aware/​policy/​pools.go | Applies policies to new containers. |
    | cmd/​plugins/​topology-aware/​policy/​mocks_test.go | Extends the container mock. |
    | cmd/​plugins/​topology-aware/​policy/​dra.go | Validates and resolves claim policies. |
    | cmd/​plugins/​topology-aware/​policy/​dra_test.go | Tests claim-policy behavior and persistence. |
    | cmd/​plugins/​topology-aware/​policy/​cache.go | Serializes claim memory policies. |
    | cmd/​plugins/​template/​policy/​dra.go | Rejects unsupported claim configs. |
    | cmd/​plugins/​template/​policy/​dra_test.go | Tests config rejection. |
    | cmd/​plugins/​memory-policy/​main.go | Uses shared policy conversion and resolution. |
    | cmd/​plugins/​memory-policy/​main_test.go | Adapts existing resolution tests. |
    </details>

    <sub>Review effort: Balanced</sub>

    bart0sh bart0sh commented on code on Oct 17, 2026 20:31 UTC
    Code Review
    cmd/plugins/topology-aware/policy/dra.go:1
    @@ -54,16 +65,21 @@ const (
     	draAttrSocketID resourceapi.QualifiedName = "dra.cpu/socketID"
     	// draAttrSMTEnabled tells whether the CPUs have SMT enabled.
     	draAttrSMTEnabled resourceapi.QualifiedName = "dra.cpu/smtEnabled"
    +	// draConfigAPIVersion and draConfigKind identify our claim configs.
    +	draConfigAPIVersion = "config.nri/v1alpha1"
    +	draConfigKind       = "TopologyAwareClaimConfig"
     )
     
     // draDriverName is the name of our DRA driver.
     var draDriverName = dra.DriverName(PolicyName)
     
     // claim is a DRA claim we allocated. It has a grant of all of its CPUs, and
    -// the CPUs of each of its allocation results, in result order.
    +// the CPUs and the memory policy of each of its allocation results, in result
    +// order. mpols is nil if no result has a memory policy.
     type claim struct {
     	Grant
     	results []cpuset.CPUSet
    +	mpols   []*cfgapi.MemoryPolicy

    Fixed. clone() now copies the memory policies of the claims. TestReconfigureKeepsClaimMemoryPolicies checks that a reconfiguration keeps them and that the claim can be prepared again.

    bart0sh bart0sh commented on code on Oct 17, 2026 20:31 UTC
    Code Review
    cmd/plugins/topology-aware/policy/dra.go:1
    @@ -209,22 +234,119 @@ func (p *policy) ReleaseClaim(uid types.UID) error {
     	return nil
     }
     
    -// containerClaims returns the CPUs of the claim results a container holds.
    -// It ignores results we do not know.
    -func (p *policy) containerClaims(c cache.Container) cpuset.CPUSet {
    -	cpus := cpuset.New()
    +// containerClaims returns the CPUs and the memory policy of the claim results
    +// a container holds. It ignores results we do not know, and fails if the
    +// results have different memory policies.
    +func (p *policy) containerClaims(c cache.Container) (cpuset.CPUSet, *cfgapi.MemoryPolicy, error) {
    +	var (
    +		cpus = cpuset.New()
    +		mpol *cfgapi.MemoryPolicy
    +		from types.UID
    +	)
     	for uid, indexes := range dra.ContainerClaims(c, draDriverName) {
     		claim, ok := p.allocations.claims[string(uid)]
     		if !ok {
     			continue
     		}
     		for _, i := range indexes {
    -			if i < len(claim.results) {
    -				cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.results) {
    +				continue
    +			}
    +			cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.mpols) || claim.mpols[i] == nil {
    +				continue
    +			}
    +			if mpol == nil {
    +				mpol, from = claim.mpols[i], uid
    +			} else if !reflect.DeepEqual(mpol, claim.mpols[i]) {
    +				return cpuset.New(), nil, fmt.Errorf("memory policy %s of claim %s conflicts with %s of claim %s",
    +					claim.mpols[i], uid, mpol, from)
    +			}
    +		}
    +	}
    +	return cpus, mpol, nil
    +}
    +
    +// claimMemoryPolicies returns the memory policies of the claim results, or nil
    +// if there are none. A later config overrides an earlier one.
    +func (p *policy) claimMemoryPolicies(results []resourceapi.DeviceRequestAllocationResult,
    +	configs []resourceapi.DeviceAllocationConfiguration) ([]*cfgapi.MemoryPolicy, error) {
    +	var mpols []*cfgapi.MemoryPolicy
    +	for i, config := range configs {
    +		cfg, err := decodeClaimConfig(config.Opaque.Parameters.Raw)
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		if cfg.MemoryPolicy == nil {
    +			continue
    +		}
    +		mpol, err := cfg.MemoryPolicy.ToMemoryPolicy()
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		// The nodes are resolved later, for each container. Resolving them
    +		// here with no CPUs only checks the value.
    +		if _, err := libmem.MemoryPolicyNodes(p.sys, mpol.Mode, mpol.Nodes, cpuset.New(), libmem.NewNodeMask()); err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		for j, r := range results {
    +			if !configApplies(config.Requests, r.Request) {
    +				continue
     			}
    +			if mpols == nil {
    +				mpols = make([]*cfgapi.MemoryPolicy, len(results))
    +			}
    +			mpols[j] = mpol
     		}
     	}
    -	return cpus
    +	return mpols, nil
    +}
    +
    +// decodeClaimConfig decodes the parameters of a claim config.
    +func decodeClaimConfig(data []byte) (*cfgapi.TopologyAwareClaimConfig, error) {
    +	cfg := &cfgapi.TopologyAwareClaimConfig{}
    +	if err := yaml.UnmarshalStrict(data, cfg); err != nil {
    +		return nil, err
    +	}
    +	if cfg.APIVersion != draConfigAPIVersion || cfg.Kind != draConfigKind {
    +		return nil, fmt.Errorf("got apiVersion %q and kind %q, expected %q and %q",
    +			cfg.APIVersion, cfg.Kind, draConfigAPIVersion, draConfigKind)
    +	}
    +	return cfg, nil
    +}
    +
    +// configApplies tells whether a config applies to a result of request.
    +// requests are the requests the config names. A config naming no requests
    +// applies to all results. A config naming a request also applies to its
    +// subrequests.
    +func configApplies(requests []string, request string) bool {
    +	main, _, _ := strings.Cut(request, "/")
    +	return len(requests) == 0 || slices.Contains(requests, request) || slices.Contains(requests, main)
    +}
    +
    +// applyMemoryPolicy sets the memory policy of a new container to the policy of
    +// its claims. The runtime applies it when the container starts.
    +//
    +// The policy's nodes, such as cpu-nodes, are resolved for the container's CPUs
    +// and memory nodes. If the container's memory is not pinned, all nodes are
    +// allowed.
    +func (p *policy) applyMemoryPolicy(c cache.Container, mpol *cfgapi.MemoryPolicy, cpus cpuset.CPUSet, mems libmem.NodeMask) {
    +	if mems == libmem.NodeMask(0) {
    +		mems = libmem.NewNodeMask(p.sys.NodeIDs()...)
    +	}

    Fixed. When the memory of the container is preserved, applyGrant now reads its cpuset.mems before resolving the nodes of the policy. The same goes for preserved CPUs and cpuset.cpus. The preserved memory and preserved CPUs cases of TestApplyClaimMemoryPolicy cover this.

    bart0sh bart0sh commented on code on Oct 17, 2026 20:31 UTC
    Code Review
    cmd/plugins/topology-aware/policy/dra.go:1
    @@ -209,22 +234,119 @@ func (p *policy) ReleaseClaim(uid types.UID) error {
     	return nil
     }
     
    -// containerClaims returns the CPUs of the claim results a container holds.
    -// It ignores results we do not know.
    -func (p *policy) containerClaims(c cache.Container) cpuset.CPUSet {
    -	cpus := cpuset.New()
    +// containerClaims returns the CPUs and the memory policy of the claim results
    +// a container holds. It ignores results we do not know, and fails if the
    +// results have different memory policies.
    +func (p *policy) containerClaims(c cache.Container) (cpuset.CPUSet, *cfgapi.MemoryPolicy, error) {
    +	var (
    +		cpus = cpuset.New()
    +		mpol *cfgapi.MemoryPolicy
    +		from types.UID
    +	)
     	for uid, indexes := range dra.ContainerClaims(c, draDriverName) {
     		claim, ok := p.allocations.claims[string(uid)]
     		if !ok {
     			continue
     		}
     		for _, i := range indexes {
    -			if i < len(claim.results) {
    -				cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.results) {
    +				continue
    +			}
    +			cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.mpols) || claim.mpols[i] == nil {
    +				continue
    +			}
    +			if mpol == nil {
    +				mpol, from = claim.mpols[i], uid
    +			} else if !reflect.DeepEqual(mpol, claim.mpols[i]) {
    +				return cpuset.New(), nil, fmt.Errorf("memory policy %s of claim %s conflicts with %s of claim %s",
    +					claim.mpols[i], uid, mpol, from)
    +			}

    Fixed. claimMemoryPolicies stores allowed-mems as unset once the value has been checked, so the two forms compare equal. TestConflictingClaimMemoryPolicies now holds one claim of each form.

    bart0sh bart0sh commented on code on Oct 17, 2026 20:31 UTC
    Code Review
    cmd/plugins/topology-aware/policy/resources.go:1
    @@ -809,8 +822,13 @@ func (p *policy) newRequest(container cache.Container, types libmem.TypeMask) (R
     	// The DRA claims of a container are fixed for its lifetime, so they are
     	// looked up once, here.
     	claimed := cpuset.New()
    +	var mpol *cfgapi.MemoryPolicy
     	if cpuType != cpuPreserve {
    -		claimed = p.containerClaims(container)
    +		var err error
    +		claimed, mpol, err = p.containerClaims(container)

    Fixed. newRequest looks up the claims of every container now, and only drops the claimed CPUs when the CPUs are preserved, so CPU pinning does not change. Such a container gets the memory policy of its claims, with the nodes resolved for its own cpuset.

    Copilot Copilot commented on code on Oct 17, 2026 20:38 UTC
    Code Review
    cmd/plugins/topology-aware/policy/dra.go:1
    @@ -209,22 +234,127 @@ func (p *policy) ReleaseClaim(uid types.UID) error {
     	return nil
     }
     
    -// containerClaims returns the CPUs of the claim results a container holds.
    -// It ignores results we do not know.
    -func (p *policy) containerClaims(c cache.Container) cpuset.CPUSet {
    -	cpus := cpuset.New()
    +// containerClaims returns the CPUs and the memory policy of the claim results
    +// a container holds. It ignores results we do not know, and fails if the
    +// results have different memory policies.
    +func (p *policy) containerClaims(c cache.Container) (cpuset.CPUSet, *cfgapi.MemoryPolicy, error) {
    +	var (
    +		cpus = cpuset.New()
    +		mpol *cfgapi.MemoryPolicy
    +		from types.UID
    +	)
     	for uid, indexes := range dra.ContainerClaims(c, draDriverName) {
     		claim, ok := p.allocations.claims[string(uid)]
     		if !ok {
     			continue
     		}
     		for _, i := range indexes {
    -			if i < len(claim.results) {
    -				cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.results) {
    +				continue
    +			}
    +			cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.mpols) || claim.mpols[i] == nil {
    +				continue
     			}
    +			if mpol == nil {
    +				mpol, from = claim.mpols[i], uid
    +			} else if !reflect.DeepEqual(mpol, claim.mpols[i]) {
    +				return cpuset.New(), nil, fmt.Errorf("memory policy %s of claim %s conflicts with %s of claim %s",
    +					claim.mpols[i], uid, mpol, from)
    +			}
    +		}
    +	}
    +	return cpus, mpol, nil
    +}
    +
    +// claimMemoryPolicies returns the memory policies of the claim results, or nil
    +// if there are none. A later config overrides an earlier one.
    +func (p *policy) claimMemoryPolicies(results []resourceapi.DeviceRequestAllocationResult,
    +	configs []resourceapi.DeviceAllocationConfiguration) ([]*cfgapi.MemoryPolicy, error) {
    +	var mpols []*cfgapi.MemoryPolicy
    +	for i, config := range configs {
    +		cfg, err := decodeClaimConfig(config.Opaque.Parameters.Raw)
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		if cfg.MemoryPolicy == nil {
    +			continue
    +		}
    +		mpol, err := cfg.MemoryPolicy.ToMemoryPolicy()
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		// The nodes are resolved later, for each container. Resolving them
    +		// here with no CPUs only checks the value.
    +		if _, err := libmem.MemoryPolicyNodes(p.sys, mpol.Mode, mpol.Nodes, cpuset.New(), libmem.NewNodeMask()); err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		// Unset nodes mean allowed-mems. We keep the unset form, so the
    +		// policies of two claims compare equal.
    +		if mpol.Nodes == "allowed-mems" {
    +			mpol.Nodes = ""
     		}

    Flags retain their input order, so otherwise identical bind policies with [static-nodes, numa-balancing] and the reversed list fail containerClaims' reflect.DeepEqual check. A container holding both claims is refused even though they request the same kernel flags. Sort and deduplicate flags before storing the policy, and add a conflict-test case for equivalent flag lists.

    Copilot Copilot commented on code on Oct 17, 2026 20:38 UTC
    Code Review
    cmd/plugins/topology-aware/policy/pools.go:1
    @@ -659,6 +659,23 @@ func (p *policy) applyGrant(grant Grant) {
     		container.SetCpusetMems(mems.MemsetString())
     	}
     
    +	// A memory policy can only be set for a new container. Its nodes are
    +	// resolved for the container's own CPUs, if any, and its claimed CPUs.
    +	// Preserved CPUs and memory are read from the container.
    +	if mpol := grant.ClaimedMemoryPolicy(); mpol != nil && container.GetState() == cache.ContainerStateCreating {
    +		own := exclusive
    +		if cpuPortion > 0 {
    +			own = cpus
    +		}
    +		if cpuType == cpuPreserve {
    +			own, _ = cpuset.Parse(container.GetCpusetCpus())
    +		}
    +		if grant.MemoryType() == memoryPreserve {
    +			mems, _ = libmem.ParseNodeMask(container.GetCpusetMems())
    +		}
    +		p.applyMemoryPolicy(container, mpol, own.Union(claimed), mems)

    With pinCPU: false, the pinning block above is skipped, but CPU-based memory selectors still use the allocated and claimed CPUs. For example, a claim on node 0 resolves cpu-nodes to node 0 even when the container's unchanged cpuset spans nodes 0–1. When pinning is disabled, resolve from container.GetCpusetCpus() without adding claimed CPUs; the existing fallback handles an unset cpuset. Add a regression case with CPU pinning disabled.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 17, 2026 20:38 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🟡 Changes recommended

    Disabled CPU pinning resolves incorrect memory nodes, and equivalent flag lists can falsely block container creation.

    <details open>
    <summary><strong>2 open issues</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Normalize bind policy flag order before conflict comparison · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Avoid adding claimed CPUs when CPU pinning is disabled · New

  • </details>

    <details>
    <summary><strong>4 resolved since last review</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> Resolve memory policy against preserved cpuset.mems

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> Clone claim memory policies during allocation reconfiguration

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Preserve memory policies independently of CPU resource preservation

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Normalize equivalent omitted and allowed-mems node defaults

  • </details>

    <details>
    <summary><strong>1 file not reviewed</strong></summary>

    <ul>
    <li><strong><code>pkg/apis/config/v1alpha1/resmgr/policy/zz_generated.deepcopy.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <sub>Review effort: Balanced</sub>

    bart0sh bart0sh commented on code on Oct 18, 2026 05:49 UTC
    Code Review
    cmd/plugins/topology-aware/policy/dra.go:1
    @@ -209,22 +234,127 @@ func (p *policy) ReleaseClaim(uid types.UID) error {
     	return nil
     }
     
    -// containerClaims returns the CPUs of the claim results a container holds.
    -// It ignores results we do not know.
    -func (p *policy) containerClaims(c cache.Container) cpuset.CPUSet {
    -	cpus := cpuset.New()
    +// containerClaims returns the CPUs and the memory policy of the claim results
    +// a container holds. It ignores results we do not know, and fails if the
    +// results have different memory policies.
    +func (p *policy) containerClaims(c cache.Container) (cpuset.CPUSet, *cfgapi.MemoryPolicy, error) {
    +	var (
    +		cpus = cpuset.New()
    +		mpol *cfgapi.MemoryPolicy
    +		from types.UID
    +	)
     	for uid, indexes := range dra.ContainerClaims(c, draDriverName) {
     		claim, ok := p.allocations.claims[string(uid)]
     		if !ok {
     			continue
     		}
     		for _, i := range indexes {
    -			if i < len(claim.results) {
    -				cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.results) {
    +				continue
    +			}
    +			cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.mpols) || claim.mpols[i] == nil {
    +				continue
     			}
    +			if mpol == nil {
    +				mpol, from = claim.mpols[i], uid
    +			} else if !reflect.DeepEqual(mpol, claim.mpols[i]) {
    +				return cpuset.New(), nil, fmt.Errorf("memory policy %s of claim %s conflicts with %s of claim %s",
    +					claim.mpols[i], uid, mpol, from)
    +			}
    +		}
    +	}
    +	return cpus, mpol, nil
    +}
    +
    +// claimMemoryPolicies returns the memory policies of the claim results, or nil
    +// if there are none. A later config overrides an earlier one.
    +func (p *policy) claimMemoryPolicies(results []resourceapi.DeviceRequestAllocationResult,
    +	configs []resourceapi.DeviceAllocationConfiguration) ([]*cfgapi.MemoryPolicy, error) {
    +	var mpols []*cfgapi.MemoryPolicy
    +	for i, config := range configs {
    +		cfg, err := decodeClaimConfig(config.Opaque.Parameters.Raw)
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		if cfg.MemoryPolicy == nil {
    +			continue
    +		}
    +		mpol, err := cfg.MemoryPolicy.ToMemoryPolicy()
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		// The nodes are resolved later, for each container. Resolving them
    +		// here with no CPUs only checks the value.
    +		if _, err := libmem.MemoryPolicyNodes(p.sys, mpol.Mode, mpol.Nodes, cpuset.New(), libmem.NewNodeMask()); err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		// Unset nodes mean allowed-mems. We keep the unset form, so the
    +		// policies of two claims compare equal.
    +		if mpol.Nodes == "allowed-mems" {
    +			mpol.Nodes = ""
     		}

    Fixed in 33356499. claimMemoryPolicies now sorts the flags and drops duplicates, next to the allowed-mems handling. TestConflictingClaimMemoryPolicies has a new case with the same flags in a different order.

    bart0sh bart0sh commented on code on Oct 18, 2026 05:49 UTC
    Code Review
    cmd/plugins/topology-aware/policy/pools.go:1
    @@ -659,6 +659,23 @@ func (p *policy) applyGrant(grant Grant) {
     		container.SetCpusetMems(mems.MemsetString())
     	}
     
    +	// A memory policy can only be set for a new container. Its nodes are
    +	// resolved for the container's own CPUs, if any, and its claimed CPUs.
    +	// Preserved CPUs and memory are read from the container.
    +	if mpol := grant.ClaimedMemoryPolicy(); mpol != nil && container.GetState() == cache.ContainerStateCreating {
    +		own := exclusive
    +		if cpuPortion > 0 {
    +			own = cpus
    +		}
    +		if cpuType == cpuPreserve {
    +			own, _ = cpuset.Parse(container.GetCpusetCpus())
    +		}
    +		if grant.MemoryType() == memoryPreserve {
    +			mems, _ = libmem.ParseNodeMask(container.GetCpusetMems())
    +		}
    +		p.applyMemoryPolicy(container, mpol, own.Union(claimed), mems)

    Fixed in 33356499. With CPU pinning off, the nodes now come from the container's cpuset, without the claimed CPUs, as for preserved CPUs. TestApplyClaimMemoryPolicy now also runs with CPU pinning off, with a new case for it.

    Copilot Copilot commented on code on Oct 18, 2026 06:04 UTC
    Code Review
    cmd/plugins/topology-aware/policy/dra.go:1
    @@ -209,22 +234,129 @@ func (p *policy) ReleaseClaim(uid types.UID) error {
     	return nil
     }
     
    -// containerClaims returns the CPUs of the claim results a container holds.
    -// It ignores results we do not know.
    -func (p *policy) containerClaims(c cache.Container) cpuset.CPUSet {
    -	cpus := cpuset.New()
    +// containerClaims returns the CPUs and the memory policy of the claim results
    +// a container holds. It ignores results we do not know, and fails if the
    +// results have different memory policies.
    +func (p *policy) containerClaims(c cache.Container) (cpuset.CPUSet, *cfgapi.MemoryPolicy, error) {
    +	var (
    +		cpus = cpuset.New()
    +		mpol *cfgapi.MemoryPolicy
    +		from types.UID
    +	)
     	for uid, indexes := range dra.ContainerClaims(c, draDriverName) {
     		claim, ok := p.allocations.claims[string(uid)]
     		if !ok {
     			continue
     		}
     		for _, i := range indexes {
    -			if i < len(claim.results) {
    -				cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.results) {
    +				continue
    +			}
    +			cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.mpols) || claim.mpols[i] == nil {
    +				continue
     			}
    +			if mpol == nil {
    +				mpol, from = claim.mpols[i], uid
    +			} else if !reflect.DeepEqual(mpol, claim.mpols[i]) {
    +				return cpuset.New(), nil, fmt.Errorf("memory policy %s of claim %s conflicts with %s of claim %s",
    +					claim.mpols[i], uid, mpol, from)
    +			}
    +		}
    +	}
    +	return cpus, mpol, nil
    +}
    +
    +// claimMemoryPolicies returns the memory policies of the claim results, or nil
    +// if there are none. A later config overrides an earlier one.
    +func (p *policy) claimMemoryPolicies(results []resourceapi.DeviceRequestAllocationResult,
    +	configs []resourceapi.DeviceAllocationConfiguration) ([]*cfgapi.MemoryPolicy, error) {
    +	var mpols []*cfgapi.MemoryPolicy
    +	for i, config := range configs {
    +		cfg, err := decodeClaimConfig(config.Opaque.Parameters.Raw)
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		if cfg.MemoryPolicy == nil {
    +			continue
    +		}
    +		mpol, err := cfg.MemoryPolicy.ToMemoryPolicy()
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}

    A claim with mode: bind, nodes: "0", and flags [static-nodes, relative-nodes] passes preparation because both flag names are valid. Linux rejects this mutually exclusive combination with EINVAL, so the prepared claim cannot be used to start its containers. Reject the combination before allocating the claim, and add a preparation-rejection test so the configuration error is reported at prepare time.

    Copilot Copilot commented on code on Oct 18, 2026 06:04 UTC
    Code Review
    cmd/plugins/topology-aware/policy/dra.go:1
    @@ -209,22 +234,129 @@ func (p *policy) ReleaseClaim(uid types.UID) error {
     	return nil
     }
     
    -// containerClaims returns the CPUs of the claim results a container holds.
    -// It ignores results we do not know.
    -func (p *policy) containerClaims(c cache.Container) cpuset.CPUSet {
    -	cpus := cpuset.New()
    +// containerClaims returns the CPUs and the memory policy of the claim results
    +// a container holds. It ignores results we do not know, and fails if the
    +// results have different memory policies.
    +func (p *policy) containerClaims(c cache.Container) (cpuset.CPUSet, *cfgapi.MemoryPolicy, error) {
    +	var (
    +		cpus = cpuset.New()
    +		mpol *cfgapi.MemoryPolicy
    +		from types.UID
    +	)
     	for uid, indexes := range dra.ContainerClaims(c, draDriverName) {
     		claim, ok := p.allocations.claims[string(uid)]
     		if !ok {
     			continue
     		}
     		for _, i := range indexes {
    -			if i < len(claim.results) {
    -				cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.results) {
    +				continue
    +			}
    +			cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.mpols) || claim.mpols[i] == nil {
    +				continue
     			}
    +			if mpol == nil {
    +				mpol, from = claim.mpols[i], uid
    +			} else if !reflect.DeepEqual(mpol, claim.mpols[i]) {
    +				return cpuset.New(), nil, fmt.Errorf("memory policy %s of claim %s conflicts with %s of claim %s",
    +					claim.mpols[i], uid, mpol, from)
    +			}
    +		}
    +	}
    +	return cpus, mpol, nil
    +}
    +
    +// claimMemoryPolicies returns the memory policies of the claim results, or nil
    +// if there are none. A later config overrides an earlier one.
    +func (p *policy) claimMemoryPolicies(results []resourceapi.DeviceRequestAllocationResult,
    +	configs []resourceapi.DeviceAllocationConfiguration) ([]*cfgapi.MemoryPolicy, error) {
    +	var mpols []*cfgapi.MemoryPolicy
    +	for i, config := range configs {
    +		cfg, err := decodeClaimConfig(config.Opaque.Parameters.Raw)
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		if cfg.MemoryPolicy == nil {
    +			continue
    +		}
    +		mpol, err := cfg.MemoryPolicy.ToMemoryPolicy()
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		// The nodes are resolved later, for each container. Resolving them
    +		// here with no CPUs only checks the value.
    +		if _, err := libmem.MemoryPolicyNodes(p.sys, mpol.Mode, mpol.Nodes, cpuset.New(), libmem.NewNodeMask()); err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		// Unset nodes mean allowed-mems. We keep the unset form, and sort
    +		// the flags, so the policies of two claims compare equal.
    +		if mpol.Nodes == "allowed-mems" {
    +			mpol.Nodes = ""
     		}

    Two otherwise identical bind claims with nodes: "0-1" and nodes: "0,1" resolve to the same mask, but retain different strings. containerClaims then treats them as conflicting and refuses to create a container holding both. Canonicalize explicit numeric node lists using the validated mask before storing them, and add a regression case for these equivalent lists.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 18, 2026 06:04 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🟡 Changes recommended

    Policy normalization and flag validation leave container-start failures unresolved.

    <details open>
    <summary><strong>2 open issues</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Reject mutually exclusive static-nodes and relative-nodes flags · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Canonicalize equivalent numeric node lists before conflict checking · New

  • </details>

    <details>
    <summary><strong>2 resolved since last review</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Avoid adding claimed CPUs when CPU pinning is disabled

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Normalize bind policy flag order before conflict comparison

  • </details>

    <details>
    <summary><strong>1 file not reviewed</strong></summary>

    <ul>
    <li><strong><code>pkg/apis/config/v1alpha1/resmgr/policy/zz_generated.deepcopy.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <sub>Review effort: Balanced</sub>

    Copilot Copilot commented on code on Oct 18, 2026 06:22 UTC
    Code Review
    pkg/apis/config/v1alpha1/resmgr/policy/topologyaware/claimconfig.go:1
    @@ -0,0 +1,88 @@
    +// Copyright The NRI Plugins Authors. All Rights Reserved.
    +//
    +// 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 topologyaware
    +
    +import (
    +	"fmt"
    +	"slices"
    +	"strings"
    +
    +	nriapi "github.com/containerd/nri/pkg/api"
    +	policy "github.com/containers/nri-plugins/pkg/apis/config/v1alpha1/resmgr/policy"
    +	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    +)
    +
    +// TopologyAwareClaimConfig is the config of a DRA claim or device class for
    +// the topology-aware policy.
    +type TopologyAwareClaimConfig struct {
    +	metav1.TypeMeta `json:",inline"`
    +	// MemoryPolicy is the memory policy of the containers using the claim.
    +	// +optional
    +	MemoryPolicy *ClaimMemoryPolicy `json:"memoryPolicy,omitempty"`
    +}
    +
    +// ClaimMemoryPolicy is the memory policy of a claim. It is the same as
    +// MemoryPolicy, with short names for the mode and the flags.
    +type ClaimMemoryPolicy struct {
    +	// Mode is the memory policy mode: default, preferred, bind, interleave,
    +	// local, preferred-many or weighted-interleave.
    +	Mode string `json:"mode"`
    +	// Nodes are the memory nodes of the policy, as in MemoryPolicy.
    +	// +optional
    +	Nodes string `json:"nodes,omitempty"`
    +	// Flags are mode flags: static-nodes, relative-nodes or numa-balancing.
    +	// +optional
    +	Flags []string `json:"flags,omitempty"`
    +}
    +
    +// ToMemoryPolicy returns the policy with the MPOL_ names of its mode and
    +// flags.
    +func (mp *ClaimMemoryPolicy) ToMemoryPolicy() (*policy.MemoryPolicy, error) {
    +	mode, err := mpolName(mp.Mode, "MPOL_", nriapi.MpolMode_value)
    +	if err != nil {
    +		return nil, fmt.Errorf("invalid memory policy mode: %w", err)
    +	}
    +
    +	var flags []string
    +	for _, f := range mp.Flags {
    +		flag, err := mpolName(f, "MPOL_F_", nriapi.MpolFlag_value)
    +		if err != nil {
    +			return nil, fmt.Errorf("invalid memory policy flag: %w", err)
    +		}
    +		flags = append(flags, flag)
    +	}
    +	// The kernel refuses this pair with EINVAL.
    +	if slices.Contains(flags, "MPOL_F_STATIC_NODES") && slices.Contains(flags, "MPOL_F_RELATIVE_NODES") {
    +		return nil, fmt.Errorf("memory policy flags static-nodes and relative-nodes exclude each other")
    +	}

    mode: interleave with flags: [numa-balancing] passes this validation and claim preparation, but Linux rejects MPOL_INTERLEAVE | MPOL_F_NUMA_BALANCING with EINVAL. The claim therefore reserves CPUs successfully while consuming containers fail to start. Validate mode/flag compatibility here so preparation rejects this combination. Update the positive “interleave with flags” case in claimconfig_test.go to expect an error, and cover the rejection in the claim-preparation tests.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 18, 2026 06:22 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🟡 Changes recommended

    An invalid mode/flag combination passes claim preparation but prevents consuming containers from starting.

    <details open>
    <summary><strong>1 open issue</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> Reject incompatible interleave mode with numa-balancing flag · New

  • </details>

    <details>
    <summary><strong>2 resolved since last review</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Canonicalize equivalent numeric node lists before conflict checking

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Reject mutually exclusive static-nodes and relative-nodes flags

  • </details>

    <details>
    <summary><strong>1 file not reviewed</strong></summary>

    <ul>
    <li><strong><code>pkg/apis/config/v1alpha1/resmgr/policy/zz_generated.deepcopy.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <sub>Review effort: Balanced</sub>

    bart0sh bart0sh commented on code on Oct 18, 2026 16:07 UTC
    Code Review
    pkg/apis/config/v1alpha1/resmgr/policy/topologyaware/claimconfig.go:1
    @@ -0,0 +1,88 @@
    +// Copyright The NRI Plugins Authors. All Rights Reserved.
    +//
    +// 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 topologyaware
    +
    +import (
    +	"fmt"
    +	"slices"
    +	"strings"
    +
    +	nriapi "github.com/containerd/nri/pkg/api"
    +	policy "github.com/containers/nri-plugins/pkg/apis/config/v1alpha1/resmgr/policy"
    +	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    +)
    +
    +// TopologyAwareClaimConfig is the config of a DRA claim or device class for
    +// the topology-aware policy.
    +type TopologyAwareClaimConfig struct {
    +	metav1.TypeMeta `json:",inline"`
    +	// MemoryPolicy is the memory policy of the containers using the claim.
    +	// +optional
    +	MemoryPolicy *ClaimMemoryPolicy `json:"memoryPolicy,omitempty"`
    +}
    +
    +// ClaimMemoryPolicy is the memory policy of a claim. It is the same as
    +// MemoryPolicy, with short names for the mode and the flags.
    +type ClaimMemoryPolicy struct {
    +	// Mode is the memory policy mode: default, preferred, bind, interleave,
    +	// local, preferred-many or weighted-interleave.
    +	Mode string `json:"mode"`
    +	// Nodes are the memory nodes of the policy, as in MemoryPolicy.
    +	// +optional
    +	Nodes string `json:"nodes,omitempty"`
    +	// Flags are mode flags: static-nodes, relative-nodes or numa-balancing.
    +	// +optional
    +	Flags []string `json:"flags,omitempty"`
    +}
    +
    +// ToMemoryPolicy returns the policy with the MPOL_ names of its mode and
    +// flags.
    +func (mp *ClaimMemoryPolicy) ToMemoryPolicy() (*policy.MemoryPolicy, error) {
    +	mode, err := mpolName(mp.Mode, "MPOL_", nriapi.MpolMode_value)
    +	if err != nil {
    +		return nil, fmt.Errorf("invalid memory policy mode: %w", err)
    +	}
    +
    +	var flags []string
    +	for _, f := range mp.Flags {
    +		flag, err := mpolName(f, "MPOL_F_", nriapi.MpolFlag_value)
    +		if err != nil {
    +			return nil, fmt.Errorf("invalid memory policy flag: %w", err)
    +		}
    +		flags = append(flags, flag)
    +	}
    +	// The kernel refuses this pair with EINVAL.
    +	if slices.Contains(flags, "MPOL_F_STATIC_NODES") && slices.Contains(flags, "MPOL_F_RELATIVE_NODES") {
    +		return nil, fmt.Errorf("memory policy flags static-nodes and relative-nodes exclude each other")
    +	}

    Fixed, thanks. The kernel (sanitize_mpol_flags() in mm/mempolicy.c) allows MPOL_F_NUMA_BALANCING only with MPOL_BIND and MPOL_PREFERRED_MANY. ToMemoryPolicy() now refuses numa-balancing with other modes. It also refuses local with static-nodes or relative-nodes, because mpol_new() refuses that too.

    The "interleave with flags" test case no longer uses numa-balancing. There are new cases for the accepted and refused flags, and TestClaimConfigRefused now checks that an interleave claim with numa-balancing is refused and gets no CPUs.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 18, 2026 16:15 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🔵 Needs a closer look

    Cross-component claim lifecycle changes and kernel-dependent runtime behavior require final human integration validation.

    No open issues 🎉

    <details>
    <summary><strong>1 resolved since last review</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> Reject incompatible interleave mode with numa-balancing flag

  • </details>

    <details>
    <summary><strong>1 file not reviewed</strong></summary>

    <ul>
    <li><strong><code>pkg/apis/config/v1alpha1/resmgr/policy/zz_generated.deepcopy.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <sub>Review effort: Balanced</sub>

    Copilot Copilot commented on code on Oct 19, 2026 08:10 UTC
    Code Review
    cmd/plugins/topology-aware/policy/dra.go:1
    @@ -209,22 +234,134 @@ func (p *policy) ReleaseClaim(uid types.UID) error {
     	return nil
     }
     
    -// containerClaims returns the CPUs of the claim results a container holds.
    -// It ignores results we do not know.
    -func (p *policy) containerClaims(c cache.Container) cpuset.CPUSet {
    -	cpus := cpuset.New()
    +// containerClaims returns the CPUs and the memory policy of the claim results
    +// a container holds. It ignores results we do not know, and fails if the
    +// results have different memory policies.
    +func (p *policy) containerClaims(c cache.Container) (cpuset.CPUSet, *cfgapi.MemoryPolicy, error) {
    +	var (
    +		cpus = cpuset.New()
    +		mpol *cfgapi.MemoryPolicy
    +		from types.UID
    +	)
     	for uid, indexes := range dra.ContainerClaims(c, draDriverName) {
     		claim, ok := p.allocations.claims[string(uid)]
     		if !ok {
     			continue
     		}
     		for _, i := range indexes {
    -			if i < len(claim.results) {
    -				cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.results) {
    +				continue
    +			}
    +			cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.mpols) || claim.mpols[i] == nil {
    +				continue
    +			}
    +			if mpol == nil {
    +				mpol, from = claim.mpols[i], uid
    +			} else if !reflect.DeepEqual(mpol, claim.mpols[i]) {
    +				return cpuset.New(), nil, fmt.Errorf("memory policy %s of claim %s conflicts with %s of claim %s",
    +					claim.mpols[i], uid, mpol, from)
    +			}
    +		}
    +	}
    +	return cpus, mpol, nil
    +}
    +
    +// claimMemoryPolicies returns the memory policies of the claim results, or nil
    +// if there are none. A later config overrides an earlier one.
    +func (p *policy) claimMemoryPolicies(results []resourceapi.DeviceRequestAllocationResult,
    +	configs []resourceapi.DeviceAllocationConfiguration) ([]*cfgapi.MemoryPolicy, error) {
    +	var mpols []*cfgapi.MemoryPolicy
    +	for i, config := range configs {
    +		cfg, err := decodeClaimConfig(config.Opaque.Parameters.Raw)
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		if cfg.MemoryPolicy == nil {
    +			continue
    +		}
    +		mpol, err := cfg.MemoryPolicy.ToMemoryPolicy()
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		// The nodes are resolved later, for each container. Resolving them
    +		// here with no CPUs only checks the value.
    +		nodes, err := libmem.MemoryPolicyNodes(p.sys, mpol.Mode, mpol.Nodes, cpuset.New(), libmem.NewNodeMask())
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}

    This checks node-list syntax, but not whether an explicit absolute mask contains usable memory nodes. For example, mode: bind, nodes: "63", and no flags passes preparation on a host with only nodes 0–3. CPUs are then reserved, but consuming containers cannot start because the kernel rejects that memory policy. Reject unusable absolute masks during preparation and add a refusal regression test. Treat relative-nodes separately because its values are indices, not host node IDs.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 19, 2026 08:10 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🟡 Changes recommended

    Preparation accepts unusable absolute node masks, reserving claim resources while consuming containers fail to start.

    <details open>
    <summary><strong>1 open issue</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Reject unusable absolute memory node masks during preparation · New

  • </details>

    <details>
    <summary><strong>1 file not reviewed</strong></summary>

    <ul>
    <li><strong><code>pkg/apis/config/v1alpha1/resmgr/policy/zz_generated.deepcopy.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <sub>Review effort: Balanced</sub>

    klihub klihub commented on code on Oct 19, 2026 11:44 UTC
    Code Review
    cmd/plugins/topology-aware/policy/dra.go:1
    @@ -26,20 +26,31 @@ package topologyaware
     // A container holding claims runs on their CPUs, and also on its own CPUs
     // if it has a CPU request. A container naming only some requests of a claim
     // runs on the CPUs of those requests.
    +//
    +// A claim or its device class may set a memory policy for the containers
    +// holding the claim, in a TopologyAwareClaimConfig. A config applies to the
    +// results of the requests it names. A config naming no requests applies to
    +// all results.
     
     import (
     	"fmt"
    +	"reflect"

    Could we avoid reflect with autogenerated DeepEqual(). Perhaps with something like this: https://github.com/containers/nri-plugins/pull/860 ?

    bart0sh bart0sh commented on code on Oct 19, 2026 12:16 UTC
    Code Review
    cmd/plugins/topology-aware/policy/dra.go:1
    @@ -209,22 +234,134 @@ func (p *policy) ReleaseClaim(uid types.UID) error {
     	return nil
     }
     
    -// containerClaims returns the CPUs of the claim results a container holds.
    -// It ignores results we do not know.
    -func (p *policy) containerClaims(c cache.Container) cpuset.CPUSet {
    -	cpus := cpuset.New()
    +// containerClaims returns the CPUs and the memory policy of the claim results
    +// a container holds. It ignores results we do not know, and fails if the
    +// results have different memory policies.
    +func (p *policy) containerClaims(c cache.Container) (cpuset.CPUSet, *cfgapi.MemoryPolicy, error) {
    +	var (
    +		cpus = cpuset.New()
    +		mpol *cfgapi.MemoryPolicy
    +		from types.UID
    +	)
     	for uid, indexes := range dra.ContainerClaims(c, draDriverName) {
     		claim, ok := p.allocations.claims[string(uid)]
     		if !ok {
     			continue
     		}
     		for _, i := range indexes {
    -			if i < len(claim.results) {
    -				cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.results) {
    +				continue
    +			}
    +			cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.mpols) || claim.mpols[i] == nil {
    +				continue
    +			}
    +			if mpol == nil {
    +				mpol, from = claim.mpols[i], uid
    +			} else if !reflect.DeepEqual(mpol, claim.mpols[i]) {
    +				return cpuset.New(), nil, fmt.Errorf("memory policy %s of claim %s conflicts with %s of claim %s",
    +					claim.mpols[i], uid, mpol, from)
    +			}
    +		}
    +	}
    +	return cpus, mpol, nil
    +}
    +
    +// claimMemoryPolicies returns the memory policies of the claim results, or nil
    +// if there are none. A later config overrides an earlier one.
    +func (p *policy) claimMemoryPolicies(results []resourceapi.DeviceRequestAllocationResult,
    +	configs []resourceapi.DeviceAllocationConfiguration) ([]*cfgapi.MemoryPolicy, error) {
    +	var mpols []*cfgapi.MemoryPolicy
    +	for i, config := range configs {
    +		cfg, err := decodeClaimConfig(config.Opaque.Parameters.Raw)
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		if cfg.MemoryPolicy == nil {
    +			continue
    +		}
    +		mpol, err := cfg.MemoryPolicy.ToMemoryPolicy()
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		// The nodes are resolved later, for each container. Resolving them
    +		// here with no CPUs only checks the value.
    +		nodes, err := libmem.MemoryPolicyNodes(p.sys, mpol.Mode, mpol.Nodes, cpuset.New(), libmem.NewNodeMask())
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}

    Fixed. A node list with no node of the host is now refused when the claim is prepared, unless the relative-nodes flag is set, since then the values are indices. Added a test for both cases.

    bart0sh bart0sh commented on code on Oct 19, 2026 12:17 UTC
    Code Review
    cmd/plugins/topology-aware/policy/dra.go:1
    @@ -26,20 +26,31 @@ package topologyaware
     // A container holding claims runs on their CPUs, and also on its own CPUs
     // if it has a CPU request. A container naming only some requests of a claim
     // runs on the CPUs of those requests.
    +//
    +// A claim or its device class may set a memory policy for the containers
    +// holding the claim, in a TopologyAwareClaimConfig. A config applies to the
    +// results of the requests it names. A config naming no requests applies to
    +// all results.
     
     import (
     	"fmt"
    +	"reflect"

    Would you prefer to merge #860 first or I can cherry-pick from it to this PR's branch?

    bart0sh bart0sh commented on code on Oct 19, 2026 12:39 UTC
    Code Review
    cmd/plugins/topology-aware/policy/dra.go:1
    @@ -26,20 +26,31 @@ package topologyaware
     // A container holding claims runs on their CPUs, and also on its own CPUs
     // if it has a CPU request. A container naming only some requests of a claim
     // runs on the CPUs of those requests.
    +//
    +// A claim or its device class may set a memory policy for the containers
    +// holding the claim, in a TopologyAwareClaimConfig. A config applies to the
    +// results of the requests it names. A config naming no requests applies to
    +// all results.
     
     import (
     	"fmt"
    +	"reflect"

    Done. Cherry-picked the generator commit from #860 as the first commit of this PR and dropped DeepEqual usage, PTAL.

    Copilot Copilot commented on code on Oct 19, 2026 12:48 UTC
    Code Review
    scripts/hack/deepequal-gen.sh:1
    @@ -0,0 +1,32 @@
    +#!/usr/bin/env bash
    +set -euo pipefail
    +
    +# Run from the repository root.
    +repo_root=$(pwd)
    +module_path="github.com/containers/nri-plugins"
    +tmp_root="$repo_root/$module_path"
    +generator="$repo_root/build-aux/bin/deepequal-gen"

    The wrapper ignores the Makefile's configurable LOCALBIN and DEEPEQUAL_GEN paths. For example, make generate-deepequals LOCALBIN=/tmp/nri-tools installs the generator there but then looks under build-aux/bin, failing if that binary is absent or using a stale binary if present. Pass $(DEEPEQUAL_GEN) from the recipe and use that supplied path in the wrapper.

    Copilot Copilot commented on code on Oct 19, 2026 12:48 UTC
    Code Review
    cmd/plugins/topology-aware/policy/dra.go:1
    @@ -209,22 +233,146 @@ func (p *policy) ReleaseClaim(uid types.UID) error {
     	return nil
     }
     
    -// containerClaims returns the CPUs of the claim results a container holds.
    -// It ignores results we do not know.
    -func (p *policy) containerClaims(c cache.Container) cpuset.CPUSet {
    -	cpus := cpuset.New()
    +// containerClaims returns the CPUs and the memory policy of the claim results
    +// a container holds. It ignores results we do not know, and fails if the
    +// results have different memory policies.
    +func (p *policy) containerClaims(c cache.Container) (cpuset.CPUSet, *cfgapi.MemoryPolicy, error) {
    +	var (
    +		cpus = cpuset.New()
    +		mpol *cfgapi.MemoryPolicy
    +		from types.UID
    +	)
     	for uid, indexes := range dra.ContainerClaims(c, draDriverName) {
     		claim, ok := p.allocations.claims[string(uid)]
     		if !ok {
     			continue
     		}
     		for _, i := range indexes {
    -			if i < len(claim.results) {
    -				cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.results) {
    +				continue
    +			}
    +			cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.mpols) || claim.mpols[i] == nil {
    +				continue
    +			}
    +			if mpol == nil {
    +				mpol, from = claim.mpols[i], uid
    +			} else if !mpol.DeepEqual(claim.mpols[i]) {
    +				return cpuset.New(), nil, fmt.Errorf("memory policy %s of claim %s conflicts with %s of claim %s",
    +					claim.mpols[i], uid, mpol, from)
    +			}
    +		}
    +	}
    +	return cpus, mpol, nil
    +}
    +
    +// claimMemoryPolicies returns the memory policies of the claim results, or nil
    +// if there are none. A later config overrides an earlier one.
    +func (p *policy) claimMemoryPolicies(results []resourceapi.DeviceRequestAllocationResult,
    +	configs []resourceapi.DeviceAllocationConfiguration) ([]*cfgapi.MemoryPolicy, error) {
    +	var mpols []*cfgapi.MemoryPolicy
    +	for i, config := range configs {
    +		cfg, err := decodeClaimConfig(config.Opaque.Parameters.Raw)
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		if cfg.MemoryPolicy == nil {
    +			continue
    +		}
    +		mpol, err := cfg.MemoryPolicy.ToMemoryPolicy()
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		// The nodes are resolved later, for each container. Resolving them
    +		// here with no CPUs only checks the value.
    +		nodes, err := libmem.MemoryPolicyNodes(p.sys, mpol.Mode, mpol.Nodes, cpuset.New(), libmem.NewNodeMask())
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		// Unset nodes mean allowed-mems. We keep the unset form, write node
    +		// lists in one form, and sort the flags, so the policies of two
    +		// claims compare equal.
    +		switch {
    +		case mpol.Nodes == "allowed-mems":
    +			mpol.Nodes = ""
    +		case mpol.Nodes != "" && mpol.Nodes[0] >= '0' && mpol.Nodes[0] <= '9':
    +			// The kernel refuses a node list with no node of the host.
    +			// With relative-nodes the list holds indices, not node IDs.
    +			if !slices.Contains(mpol.Flags, "MPOL_F_RELATIVE_NODES") &&
    +				nodes.And(libmem.NewNodeMask(p.sys.NodeIDs()...)).Size() == 0 {
    +				return nil, fmt.Errorf("config %d: memory policy nodes %q has no node of this host", i, mpol.Nodes)
     			}

    NodeIDs() includes memoryless NUMA nodes. If node 1 has CPUs but no memory, mode: bind with nodes: "1" passes this check and reserves CPUs, but Linux rejects the policy when a consuming container starts. Validate absolute masks against the allocator's memory-bearing nodes, retaining the exception for relative indices, and add a memoryless-node refusal test.

    Copilot Copilot commented on code on Oct 19, 2026 12:48 UTC
    Code Review
    cmd/plugins/topology-aware/policy/dra.go:1
    @@ -209,22 +233,146 @@ func (p *policy) ReleaseClaim(uid types.UID) error {
     	return nil
     }
     
    -// containerClaims returns the CPUs of the claim results a container holds.
    -// It ignores results we do not know.
    -func (p *policy) containerClaims(c cache.Container) cpuset.CPUSet {
    -	cpus := cpuset.New()
    +// containerClaims returns the CPUs and the memory policy of the claim results
    +// a container holds. It ignores results we do not know, and fails if the
    +// results have different memory policies.
    +func (p *policy) containerClaims(c cache.Container) (cpuset.CPUSet, *cfgapi.MemoryPolicy, error) {
    +	var (
    +		cpus = cpuset.New()
    +		mpol *cfgapi.MemoryPolicy
    +		from types.UID
    +	)
     	for uid, indexes := range dra.ContainerClaims(c, draDriverName) {
     		claim, ok := p.allocations.claims[string(uid)]
     		if !ok {
     			continue
     		}
     		for _, i := range indexes {
    -			if i < len(claim.results) {
    -				cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.results) {
    +				continue
    +			}
    +			cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.mpols) || claim.mpols[i] == nil {
    +				continue
    +			}
    +			if mpol == nil {
    +				mpol, from = claim.mpols[i], uid
    +			} else if !mpol.DeepEqual(claim.mpols[i]) {
    +				return cpuset.New(), nil, fmt.Errorf("memory policy %s of claim %s conflicts with %s of claim %s",
    +					claim.mpols[i], uid, mpol, from)
    +			}
    +		}
    +	}
    +	return cpus, mpol, nil
    +}
    +
    +// claimMemoryPolicies returns the memory policies of the claim results, or nil
    +// if there are none. A later config overrides an earlier one.
    +func (p *policy) claimMemoryPolicies(results []resourceapi.DeviceRequestAllocationResult,
    +	configs []resourceapi.DeviceAllocationConfiguration) ([]*cfgapi.MemoryPolicy, error) {
    +	var mpols []*cfgapi.MemoryPolicy
    +	for i, config := range configs {
    +		cfg, err := decodeClaimConfig(config.Opaque.Parameters.Raw)
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		if cfg.MemoryPolicy == nil {
    +			continue
    +		}
    +		mpol, err := cfg.MemoryPolicy.ToMemoryPolicy()
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		// The nodes are resolved later, for each container. Resolving them
    +		// here with no CPUs only checks the value.
    +		nodes, err := libmem.MemoryPolicyNodes(p.sys, mpol.Mode, mpol.Nodes, cpuset.New(), libmem.NewNodeMask())
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		// Unset nodes mean allowed-mems. We keep the unset form, write node
    +		// lists in one form, and sort the flags, so the policies of two
    +		// claims compare equal.
    +		switch {
    +		case mpol.Nodes == "allowed-mems":
    +			mpol.Nodes = ""
    +		case mpol.Nodes != "" && mpol.Nodes[0] >= '0' && mpol.Nodes[0] <= '9':
    +			// The kernel refuses a node list with no node of the host.
    +			// With relative-nodes the list holds indices, not node IDs.
    +			if !slices.Contains(mpol.Flags, "MPOL_F_RELATIVE_NODES") &&
    +				nodes.And(libmem.NewNodeMask(p.sys.NodeIDs()...)).Size() == 0 {
    +				return nil, fmt.Errorf("config %d: memory policy nodes %q has no node of this host", i, mpol.Nodes)
     			}
    +			mpol.Nodes = nodes.MemsetString()
     		}
    +		slices.Sort(mpol.Flags)
    +		mpol.Flags = slices.Compact(mpol.Flags)
    +		for j, r := range results {
    +			if !configApplies(config.Requests, r.Request) {
    +				continue
    +			}
    +			if mpols == nil {
    +				mpols = make([]*cfgapi.MemoryPolicy, len(results))
    +			}
    +			mpols[j] = mpol
    +		}
    +	}
    +	return mpols, nil
    +}
    +
    +// sameMemoryPolicy tells whether two memory policies are the same. Two nil
    +// policies are the same.
    +func sameMemoryPolicy(a, b *cfgapi.MemoryPolicy) bool {
    +	return a == b || a != nil && a.DeepEqual(b)
    +}
    +
    +// decodeClaimConfig decodes the parameters of a claim config.
    +func decodeClaimConfig(data []byte) (*cfgapi.TopologyAwareClaimConfig, error) {
    +	cfg := &cfgapi.TopologyAwareClaimConfig{}
    +	if err := yaml.UnmarshalStrict(data, cfg); err != nil {
    +		return nil, err
    +	}
    +	if cfg.APIVersion != draConfigAPIVersion || cfg.Kind != draConfigKind {
    +		return nil, fmt.Errorf("got apiVersion %q and kind %q, expected %q and %q",
    +			cfg.APIVersion, cfg.Kind, draConfigAPIVersion, draConfigKind)
    +	}
    +	return cfg, nil
    +}
    +
    +// configApplies tells whether a config applies to a result of request.
    +// requests are the requests the config names. A config naming no requests
    +// applies to all results. A config naming a request also applies to its
    +// subrequests.
    +func configApplies(requests []string, request string) bool {
    +	main, _, _ := strings.Cut(request, "/")
    +	return len(requests) == 0 || slices.Contains(requests, request) || slices.Contains(requests, main)
    +}
    +
    +// applyMemoryPolicy sets the memory policy of a new container to the policy of
    +// its claims. The runtime applies it when the container starts.
    +//
    +// The policy's nodes, such as cpu-nodes, are resolved for the container's CPUs
    +// and memory nodes. A container with no cpuset runs on all CPUs, and all nodes
    +// are allowed if its memory is not pinned.
    +func (p *policy) applyMemoryPolicy(c cache.Container, mpol *cfgapi.MemoryPolicy, cpus cpuset.CPUSet, mems libmem.NodeMask) {
    +	if cpus.IsEmpty() {
    +		cpus = p.sys.OnlineCPUs()
    +	}
    +	if mems == libmem.NodeMask(0) {
    +		mems = libmem.NewNodeMask(p.sys.NodeIDs()...)
    +	}
    +	nodes, err := libmem.MemoryPolicyNodes(p.sys, mpol.Mode, mpol.Nodes, cpus, mems)
    +	if err != nil {
    +		log.Errorf("%s: failed to set memory policy %s: %v", c.PrettyName(), mpol, err)
    +		return
    +	}
    +	mode, flags, err := mpol.ToNRI()
    +	if err != nil {
    +		log.Errorf("%s: failed to set memory policy %s: %v", c.PrettyName(), mpol, err)
    +		return
     	}
    -	return cpus
    +	log.Infof("  => setting memory policy of %s to %s %v, nodes %s",
    +		c.PrettyName(), mpol.Mode, mpol.Flags, nodes.MemsetString())
    +	c.SetMemoryPolicy(mode, nodes.MemsetString(), flags...)

    Symbolic selectors resolve to absolute node IDs, but relative-nodes makes Linux interpret those numbers as indices into the allowed memory nodes. With cpuset.mems=1-2 and CPUs on node 1, a bind policy using nodes: cpu-nodes resolves to 1 and then targets node 2 instead. Convert symbolic results to relative indices, or reject symbolic selectors with this flag during preparation. Explicit numeric lists should remain indices. Cover a nonzero, restricted allowed-node set in a regression test.

    Copilot Copilot commented on code on Oct 19, 2026 12:48 UTC
    Code Review
    pkg/resmgr/lib/memory/policy.go:1
    @@ -0,0 +1,87 @@
    +// Copyright The NRI Plugins Authors. All Rights Reserved.
    +//
    +// 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 libmem
    +
    +import (
    +	"fmt"
    +	"strconv"
    +	"strings"
    +
    +	"github.com/containers/nri-plugins/pkg/sysfs"
    +	"github.com/containers/nri-plugins/pkg/utils/cpuset"
    +	idset "github.com/intel/goresctrl/pkg/utils"
    +)
    +
    +// MemoryPolicyNodes returns the nodes a memory policy uses for a container
    +// running on the given CPUs and memory nodes. The mode and the nodes use the
    +// format of the Mode and Nodes fields of MemoryPolicy in the policy
    +// configuration.
    +func MemoryPolicyNodes(sys sysfs.System, mode, nodes string, cpus cpuset.CPUSet, mems NodeMask) (NodeMask, error) {
    +	cpuNodes := func() idset.IDSet {
    +		return sys.IDSetForCPUs(cpus, func(cpu sysfs.CPU) idset.ID { return cpu.NodeID() })
    +	}
    +
    +	switch {
    +	// MPOL_DEFAULT and MPOL_LOCAL take no nodes, the kernel refuses any.
    +	case mode == "MPOL_DEFAULT" || mode == "MPOL_LOCAL":
    +		if nodes != "" {
    +			return 0, fmt.Errorf("memory policy mode %s takes no nodes, got %q", mode, nodes)
    +		}
    +		return NewNodeMask(), nil
    +
    +	case nodes == "all":
    +		return NewNodeMask(sys.NodeIDs()...), nil
    +
    +	case nodes == "" || nodes == "allowed-mems":
    +		return mems, nil
    +
    +	case nodes == "cpu-nodes":
    +		return NewNodeMask(cpuNodes().Members()...), nil
    +
    +	case nodes == "cpu-packages":
    +		pkgs := sys.IDSetForCPUs(cpus, func(cpu sysfs.CPU) idset.ID { return cpu.PackageID() })
    +		mask := NewNodeMask()
    +		for _, id := range sys.NodeIDs() {
    +			if pkgs.Has(sys.Node(id).PackageID()) {
    +				mask = mask.Set(id)
    +			}
    +		}
    +		return mask, nil
    +
    +	case strings.HasPrefix(nodes, "max-dist:"):
    +		maxDist, err := strconv.Atoi(strings.TrimPrefix(nodes, "max-dist:"))
    +		if err != nil {
    +			return 0, fmt.Errorf("invalid memory policy nodes %q: %w", nodes, err)
    +		}

    strconv.Atoi accepts negative distances, so mode: interleave with nodes: max-dist:-1 passes claim preparation and reserves CPUs. Resolving this selector for a container produces an empty mask, which Linux rejects for interleave with EINVAL. Reject negative distances here so preparation reports the invalid config instead of leaving consuming containers unable to start. Add a refusal regression test.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 19, 2026 12:48 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🟡 Changes recommended

    Unresolved node-validation, relative-node mapping, and generator-path issues affect correctness and reliable generation.

    <details open>
    <summary><strong>4 open issues</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> Honor configurable generator path in deepequal wrapper · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Reject absolute NUMA masks containing memoryless nodes · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Correct symbolic NUMA selectors with relative-nodes · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Reject negative NUMA distances during claim preparation · New

  • </details>

    <details>
    <summary><strong>1 resolved since last review</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Reject unusable absolute memory node masks during preparation

  • </details>

    <details>
    <summary><strong>2 files not reviewed</strong></summary>

    <ul>
    <li><strong><code>pkg/apis/config/v1alpha1/resmgr/policy/generated.deepequal.go</code></strong>: Generated file</li>
    <li><strong><code>pkg/apis/config/v1alpha1/resmgr/policy/zz_generated.deepcopy.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <sub>Review effort: Balanced</sub>

    klihub klihub commented on code on Oct 19, 2026 13:19 UTC
    Code Review
    cmd/plugins/topology-aware/policy/dra.go:1
    @@ -26,20 +26,31 @@ package topologyaware
     // A container holding claims runs on their CPUs, and also on its own CPUs
     // if it has a CPU request. A container naming only some requests of a claim
     // runs on the CPUs of those requests.
    +//
    +// A claim or its device class may set a memory policy for the containers
    +// holding the claim, in a TopologyAwareClaimConfig. A config applies to the
    +// results of the requests it names. A config naming no requests applies to
    +// all results.
     
     import (
     	"fmt"
    +	"reflect"

    It is easier if you just cherry-pick I think.

    klihub klihub commented on code on Oct 19, 2026 13:22 UTC
    Code Review
    cmd/plugins/topology-aware/policy/dra.go:1
    @@ -209,22 +233,146 @@ func (p *policy) ReleaseClaim(uid types.UID) error {
     	return nil
     }
     
    -// containerClaims returns the CPUs of the claim results a container holds.
    -// It ignores results we do not know.
    -func (p *policy) containerClaims(c cache.Container) cpuset.CPUSet {
    -	cpus := cpuset.New()
    +// containerClaims returns the CPUs and the memory policy of the claim results
    +// a container holds. It ignores results we do not know, and fails if the
    +// results have different memory policies.
    +func (p *policy) containerClaims(c cache.Container) (cpuset.CPUSet, *cfgapi.MemoryPolicy, error) {
    +	var (
    +		cpus = cpuset.New()
    +		mpol *cfgapi.MemoryPolicy
    +		from types.UID
    +	)
     	for uid, indexes := range dra.ContainerClaims(c, draDriverName) {
     		claim, ok := p.allocations.claims[string(uid)]
     		if !ok {
     			continue
     		}
     		for _, i := range indexes {
    -			if i < len(claim.results) {
    -				cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.results) {
    +				continue
    +			}
    +			cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.mpols) || claim.mpols[i] == nil {
    +				continue
    +			}
    +			if mpol == nil {
    +				mpol, from = claim.mpols[i], uid
    +			} else if !mpol.DeepEqual(claim.mpols[i]) {
    +				return cpuset.New(), nil, fmt.Errorf("memory policy %s of claim %s conflicts with %s of claim %s",
    +					claim.mpols[i], uid, mpol, from)
    +			}
    +		}
    +	}
    +	return cpus, mpol, nil
    +}
    +
    +// claimMemoryPolicies returns the memory policies of the claim results, or nil
    +// if there are none. A later config overrides an earlier one.
    +func (p *policy) claimMemoryPolicies(results []resourceapi.DeviceRequestAllocationResult,
    +	configs []resourceapi.DeviceAllocationConfiguration) ([]*cfgapi.MemoryPolicy, error) {
    +	var mpols []*cfgapi.MemoryPolicy
    +	for i, config := range configs {
    +		cfg, err := decodeClaimConfig(config.Opaque.Parameters.Raw)
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		if cfg.MemoryPolicy == nil {
    +			continue
    +		}
    +		mpol, err := cfg.MemoryPolicy.ToMemoryPolicy()
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		// The nodes are resolved later, for each container. Resolving them
    +		// here with no CPUs only checks the value.
    +		nodes, err := libmem.MemoryPolicyNodes(p.sys, mpol.Mode, mpol.Nodes, cpuset.New(), libmem.NewNodeMask())
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		// Unset nodes mean allowed-mems. We keep the unset form, write node
    +		// lists in one form, and sort the flags, so the policies of two
    +		// claims compare equal.
    +		switch {
    +		case mpol.Nodes == "allowed-mems":
    +			mpol.Nodes = ""
    +		case mpol.Nodes != "" && mpol.Nodes[0] >= '0' && mpol.Nodes[0] <= '9':
    +			// The kernel refuses a node list with no node of the host.
    +			// With relative-nodes the list holds indices, not node IDs.
    +			if !slices.Contains(mpol.Flags, "MPOL_F_RELATIVE_NODES") &&
    +				nodes.And(libmem.NewNodeMask(p.sys.NodeIDs()...)).Size() == 0 {
    +				return nil, fmt.Errorf("config %d: memory policy nodes %q has no node of this host", i, mpol.Nodes)
     			}
    +			mpol.Nodes = nodes.MemsetString()
     		}
    +		slices.Sort(mpol.Flags)
    +		mpol.Flags = slices.Compact(mpol.Flags)
    +		for j, r := range results {
    +			if !configApplies(config.Requests, r.Request) {
    +				continue
    +			}
    +			if mpols == nil {
    +				mpols = make([]*cfgapi.MemoryPolicy, len(results))
    +			}
    +			mpols[j] = mpol
    +		}
    +	}
    +	return mpols, nil
    +}
    +
    +// sameMemoryPolicy tells whether two memory policies are the same. Two nil
    +// policies are the same.
    +func sameMemoryPolicy(a, b *cfgapi.MemoryPolicy) bool {
    +	return a == b || a != nil && a.DeepEqual(b)
    +}
    +
    +// decodeClaimConfig decodes the parameters of a claim config.
    +func decodeClaimConfig(data []byte) (*cfgapi.TopologyAwareClaimConfig, error) {
    +	cfg := &cfgapi.TopologyAwareClaimConfig{}
    +	if err := yaml.UnmarshalStrict(data, cfg); err != nil {
    +		return nil, err
    +	}
    +	if cfg.APIVersion != draConfigAPIVersion || cfg.Kind != draConfigKind {
    +		return nil, fmt.Errorf("got apiVersion %q and kind %q, expected %q and %q",
    +			cfg.APIVersion, cfg.Kind, draConfigAPIVersion, draConfigKind)
    +	}
    +	return cfg, nil
    +}
    +
    +// configApplies tells whether a config applies to a result of request.
    +// requests are the requests the config names. A config naming no requests
    +// applies to all results. A config naming a request also applies to its
    +// subrequests.
    +func configApplies(requests []string, request string) bool {
    +	main, _, _ := strings.Cut(request, "/")
    +	return len(requests) == 0 || slices.Contains(requests, request) || slices.Contains(requests, main)
    +}
    +
    +// applyMemoryPolicy sets the memory policy of a new container to the policy of
    +// its claims. The runtime applies it when the container starts.
    +//
    +// The policy's nodes, such as cpu-nodes, are resolved for the container's CPUs
    +// and memory nodes. A container with no cpuset runs on all CPUs, and all nodes
    +// are allowed if its memory is not pinned.
    +func (p *policy) applyMemoryPolicy(c cache.Container, mpol *cfgapi.MemoryPolicy, cpus cpuset.CPUSet, mems libmem.NodeMask) {
    +	if cpus.IsEmpty() {
    +		cpus = p.sys.OnlineCPUs()
    +	}
    +	if mems == libmem.NodeMask(0) {
    +		mems = libmem.NewNodeMask(p.sys.NodeIDs()...)
    +	}
    +	nodes, err := libmem.MemoryPolicyNodes(p.sys, mpol.Mode, mpol.Nodes, cpus, mems)
    +	if err != nil {
    +		log.Errorf("%s: failed to set memory policy %s: %v", c.PrettyName(), mpol, err)
    +		return
    +	}
    +	mode, flags, err := mpol.ToNRI()
    +	if err != nil {
    +		log.Errorf("%s: failed to set memory policy %s: %v", c.PrettyName(), mpol, err)
    +		return
     	}
    -	return cpus
    +	log.Infof("  => setting memory policy of %s to %s %v, nodes %s",
    +		c.PrettyName(), mpol.Mode, mpol.Flags, nodes.MemsetString())
    +	c.SetMemoryPolicy(mode, nodes.MemsetString(), flags...)

    @bart0sh This seems like a real bug wrt. relative indices.

    klihub klihub commented on code on Oct 19, 2026 13:23 UTC
    Code Review
    pkg/resmgr/lib/memory/policy.go:1
    @@ -0,0 +1,87 @@
    +// Copyright The NRI Plugins Authors. All Rights Reserved.
    +//
    +// 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 libmem
    +
    +import (
    +	"fmt"
    +	"strconv"
    +	"strings"
    +
    +	"github.com/containers/nri-plugins/pkg/sysfs"
    +	"github.com/containers/nri-plugins/pkg/utils/cpuset"
    +	idset "github.com/intel/goresctrl/pkg/utils"
    +)
    +
    +// MemoryPolicyNodes returns the nodes a memory policy uses for a container
    +// running on the given CPUs and memory nodes. The mode and the nodes use the
    +// format of the Mode and Nodes fields of MemoryPolicy in the policy
    +// configuration.
    +func MemoryPolicyNodes(sys sysfs.System, mode, nodes string, cpus cpuset.CPUSet, mems NodeMask) (NodeMask, error) {
    +	cpuNodes := func() idset.IDSet {
    +		return sys.IDSetForCPUs(cpus, func(cpu sysfs.CPU) idset.ID { return cpu.NodeID() })
    +	}
    +
    +	switch {
    +	// MPOL_DEFAULT and MPOL_LOCAL take no nodes, the kernel refuses any.
    +	case mode == "MPOL_DEFAULT" || mode == "MPOL_LOCAL":
    +		if nodes != "" {
    +			return 0, fmt.Errorf("memory policy mode %s takes no nodes, got %q", mode, nodes)
    +		}
    +		return NewNodeMask(), nil
    +
    +	case nodes == "all":
    +		return NewNodeMask(sys.NodeIDs()...), nil
    +
    +	case nodes == "" || nodes == "allowed-mems":
    +		return mems, nil
    +
    +	case nodes == "cpu-nodes":
    +		return NewNodeMask(cpuNodes().Members()...), nil
    +
    +	case nodes == "cpu-packages":
    +		pkgs := sys.IDSetForCPUs(cpus, func(cpu sysfs.CPU) idset.ID { return cpu.PackageID() })
    +		mask := NewNodeMask()
    +		for _, id := range sys.NodeIDs() {
    +			if pkgs.Has(sys.Node(id).PackageID()) {
    +				mask = mask.Set(id)
    +			}
    +		}
    +		return mask, nil
    +
    +	case strings.HasPrefix(nodes, "max-dist:"):
    +		maxDist, err := strconv.Atoi(strings.TrimPrefix(nodes, "max-dist:"))
    +		if err != nil {
    +			return 0, fmt.Errorf("invalid memory policy nodes %q: %w", nodes, err)
    +		}

    @bart0sh This also seems like something we should flag as an error.

    bart0sh bart0sh commented on code on Oct 19, 2026 14:20 UTC
    Code Review
    scripts/hack/deepequal-gen.sh:1
    @@ -0,0 +1,32 @@
    +#!/usr/bin/env bash
    +set -euo pipefail
    +
    +# Run from the repository root.
    +repo_root=$(pwd)
    +module_path="github.com/containers/nri-plugins"
    +tmp_root="$repo_root/$module_path"
    +generator="$repo_root/build-aux/bin/deepequal-gen"

    Fixed. This PR now carries the updated commit from #860. The Makefile passes DEEPEQUAL_GEN to the script, and the script uses it.

    bart0sh bart0sh commented on code on Oct 19, 2026 14:20 UTC
    Code Review
    cmd/plugins/topology-aware/policy/dra.go:1
    @@ -209,22 +233,146 @@ func (p *policy) ReleaseClaim(uid types.UID) error {
     	return nil
     }
     
    -// containerClaims returns the CPUs of the claim results a container holds.
    -// It ignores results we do not know.
    -func (p *policy) containerClaims(c cache.Container) cpuset.CPUSet {
    -	cpus := cpuset.New()
    +// containerClaims returns the CPUs and the memory policy of the claim results
    +// a container holds. It ignores results we do not know, and fails if the
    +// results have different memory policies.
    +func (p *policy) containerClaims(c cache.Container) (cpuset.CPUSet, *cfgapi.MemoryPolicy, error) {
    +	var (
    +		cpus = cpuset.New()
    +		mpol *cfgapi.MemoryPolicy
    +		from types.UID
    +	)
     	for uid, indexes := range dra.ContainerClaims(c, draDriverName) {
     		claim, ok := p.allocations.claims[string(uid)]
     		if !ok {
     			continue
     		}
     		for _, i := range indexes {
    -			if i < len(claim.results) {
    -				cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.results) {
    +				continue
    +			}
    +			cpus = cpus.Union(claim.results[i])
    +			if i >= len(claim.mpols) || claim.mpols[i] == nil {
    +				continue
    +			}
    +			if mpol == nil {
    +				mpol, from = claim.mpols[i], uid
    +			} else if !mpol.DeepEqual(claim.mpols[i]) {
    +				return cpuset.New(), nil, fmt.Errorf("memory policy %s of claim %s conflicts with %s of claim %s",
    +					claim.mpols[i], uid, mpol, from)
    +			}
    +		}
    +	}
    +	return cpus, mpol, nil
    +}
    +
    +// claimMemoryPolicies returns the memory policies of the claim results, or nil
    +// if there are none. A later config overrides an earlier one.
    +func (p *policy) claimMemoryPolicies(results []resourceapi.DeviceRequestAllocationResult,
    +	configs []resourceapi.DeviceAllocationConfiguration) ([]*cfgapi.MemoryPolicy, error) {
    +	var mpols []*cfgapi.MemoryPolicy
    +	for i, config := range configs {
    +		cfg, err := decodeClaimConfig(config.Opaque.Parameters.Raw)
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		if cfg.MemoryPolicy == nil {
    +			continue
    +		}
    +		mpol, err := cfg.MemoryPolicy.ToMemoryPolicy()
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		// The nodes are resolved later, for each container. Resolving them
    +		// here with no CPUs only checks the value.
    +		nodes, err := libmem.MemoryPolicyNodes(p.sys, mpol.Mode, mpol.Nodes, cpuset.New(), libmem.NewNodeMask())
    +		if err != nil {
    +			return nil, fmt.Errorf("config %d: %w", i, err)
    +		}
    +		// Unset nodes mean allowed-mems. We keep the unset form, write node
    +		// lists in one form, and sort the flags, so the policies of two
    +		// claims compare equal.
    +		switch {
    +		case mpol.Nodes == "allowed-mems":
    +			mpol.Nodes = ""
    +		case mpol.Nodes != "" && mpol.Nodes[0] >= '0' && mpol.Nodes[0] <= '9':
    +			// The kernel refuses a node list with no node of the host.
    +			// With relative-nodes the list holds indices, not node IDs.
    +			if !slices.Contains(mpol.Flags, "MPOL_F_RELATIVE_NODES") &&
    +				nodes.And(libmem.NewNodeMask(p.sys.NodeIDs()...)).Size() == 0 {
    +				return nil, fmt.Errorf("config %d: memory policy nodes %q has no node of this host", i, mpol.Nodes)
     			}

    Fixed. The check now only counts nodes that have memory. A new test removes the memory from one node and checks that a bind to that node is refused.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 19, 2026 14:27 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🔵 Needs a closer look

    Unresolved configuration correctness issues and kernel-facing policy behavior require fixes and final human validation.

    <details open>
    <summary><strong>2 open issues</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Reject unusable NUMA distance selectors during preparation · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Class configs incorrectly override claim memory policies · New

  • </details>

    <details>
    <summary><strong>4 resolved since last review</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> Honor configurable generator path in deepequal wrapper

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Reject negative NUMA distances during claim preparation

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Correct symbolic NUMA selectors with relative-nodes

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Reject absolute NUMA masks containing memoryless nodes

  • </details>

    <details>
    <summary><strong>2 files not reviewed</strong></summary>

    <ul>
    <li><strong><code>pkg/apis/config/v1alpha1/resmgr/policy/generated.deepequal.go</code></strong>: Generated file</li>
    <li><strong><code>pkg/apis/config/v1alpha1/resmgr/policy/zz_generated.deepcopy.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <sub>Review effort: Balanced</sub>

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 19, 2026 15:05 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🔵 Needs a closer look

    Persisted claim state and create-only kernel memory-policy application warrant final human integration review.

    No open issues 🎉

    <details>
    <summary><strong>2 resolved since last review</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Class configs incorrectly override claim memory policies

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Reject unusable NUMA distance selectors during preparation

  • </details>

    <details>
    <summary><strong>2 files not reviewed</strong></summary>

    <ul>
    <li><strong><code>pkg/apis/config/v1alpha1/resmgr/policy/generated.deepequal.go</code></strong>: Generated file</li>
    <li><strong><code>pkg/apis/config/v1alpha1/resmgr/policy/zz_generated.deepcopy.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <sub>Review effort: Balanced</sub>

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 19, 2026 15:18 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🔵 Needs a closer look

    Claim recovery and create-time NUMA policies span runtime-sensitive components that warrant final human validation.

    No open issues 🎉

    <details>
    <summary><strong>2 files not reviewed</strong></summary>

    <ul>
    <li><strong><code>pkg/apis/config/v1alpha1/resmgr/policy/generated.deepequal.go</code></strong>: Generated file</li>
    <li><strong><code>pkg/apis/config/v1alpha1/resmgr/policy/zz_generated.deepcopy.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <sub>Review effort: Balanced</sub>

    Reviewers
    Assignees
    bart0sh bart0sh
    Labels
    risk: low confidence: 83.8% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 96% (HIGH) · Higher = larger blast radius
    96%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 83.8% · Lower = rushed or shallow review
    83.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.5% · Safe to merge
    15.5%