Skip to content

Comments

Enable adjusting memory policy from NRI plugins#166

Open
askervin wants to merge 3 commits intocontainerd:mainfrom
askervin:5aW_mempolicy
Open

Enable adjusting memory policy from NRI plugins#166
askervin wants to merge 3 commits intocontainerd:mainfrom
askervin:5aW_mempolicy

Conversation

@askervin
Copy link
Contributor

@askervin askervin commented Apr 25, 2025

This PR implements

  • container (default) Linux kernel memory policy adjustment
  • container memory policies adjustment by annotation in the device-injector plugin

See set_mempolicy(2) for more details about Linux kernel memory policies.

This PR can be tested using

apiVersion: v1
kind: Pod
metadata:
  name: alpine-test
  annotations:
    memory-policy.noderesource.dev/container.c0: |
      mode: MPOL_PREFERRED
      nodes: "1,2"
      flags: [ MPOL_F_STATIC_NODES ]
    memory-policy.noderesource.dev/container.c1: |
      mode: MPOL_INTERLEAVE
      nodes: "0,3"
      flags: [ MPOL_F_STATIC_NODES ]
spec:
  containers:
  - name: c0
    image: alpine:latest
    imagePullPolicy: IfNotPresent
    command:
      - sh
      - -c
      - echo c0 $(sleep inf)
    resources:
      requests:
        cpu: 1
        memory: '100M'
      limits:
        cpu: 9
        memory: '100M'
  - name: c1
    image: alpine:latest
    imagePullPolicy: IfNotPresent
    command:
      - sh
      - -c
      - echo c1 $(sleep inf)
    resources:
      requests:
        cpu: 1
        memory: '100M'
      limits:
        cpu: 9
        memory: '100M'
  terminationGracePeriodSeconds: 1

with something like this

$ kubectl apply -f test-pod.yaml
$ kubectl exec -c c0 alpine-test -- /bin/sh -c "apk add numactl-tools; numactl -s"
...
policy: [32769]
preferred node: physcpubind: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 
cpubind: 0 1 2 3 
nodebind: 0 1 2 3 
membind: 0 1 2 3 
preferred: 1 2
$ kubectl exec -c c1 alpine-test -- /bin/sh -c "apk add numactl-tools; numactl -s"
...
policy: [32771]
preferred node: physcpubind: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 
cpubind: 0 1 2 3 
nodebind: 0 1 2 3 
membind: 0 1 2 3 
preferred: 0 3

@klihub
Copy link
Member

klihub commented Dec 4, 2025

@askervin We have now the necessary plumbing in place and tagged in runtime Spec and our NRI deps here updated accordingly. So in principle we could go forward with this PR, but I think it needs a bit more work/additions before we can seriously consider it for merging:

  • pull the proposed opencontainers/runtime-tools additions locally to the pkg/runtime-tools/generate wrapper
  • pkg/adaptation test case(s) for memory policy adjustment
  • documentation updates to mention memory policy adjustment
  • ideally, support for memory policy adjustment in the usual suspect, the device-injector sample plugin

@klihub
Copy link
Member

klihub commented Dec 5, 2025

@mikebrow @chrishenzie Could we give this a preliminary review, so if there is anything beside the ones already flagged we could try pointing them out and get them addressed in the same round ?

@klihub klihub requested a review from chrishenzie December 7, 2025 09:32
@klihub klihub force-pushed the 5aW_mempolicy branch 5 times, most recently from c2ace9f to 38cddf5 Compare December 8, 2025 17:11
@klihub klihub requested review from klihub and mikebrow December 8, 2025 17:14
@klihub klihub marked this pull request as ready for review December 8, 2025 17:14
@klihub klihub added the v.next to be merged into the next release label Dec 10, 2025
@klihub klihub requested a review from chrishenzie December 11, 2025 15:42
@klihub klihub force-pushed the 5aW_mempolicy branch 2 times, most recently from d440222 to 5363825 Compare February 16, 2026 15:55
@klihub
Copy link
Member

klihub commented Feb 18, 2026

@mikebrow @chrishenzie Looks like all the review comments have been addressed. PTAL, could we get this approved ?

Copy link
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The device injector plugin readme is getting a bit long.. WDYT about links from the top.. to each of these plugin supported adjustment types?

TODO... this and a few of the other plugins are getting useful enough that they should probably be mentioned/linked in the main readme.

askervin and others added 2 commits February 23, 2026 20:15
Signed-off-by: Antti Kervinen <antti.kervinen@intel.com>
Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
@klihub klihub force-pushed the 5aW_mempolicy branch 2 times, most recently from 1f3b218 to ec18ad4 Compare February 23, 2026 18:20
@klihub
Copy link
Member

klihub commented Feb 23, 2026

The device injector plugin readme is getting a bit long.. WDYT about links from the top.. to each of these plugin supported adjustment types?

@mikebrow Do you mean to add a link from each bullet list point at the top of plugins/device-injector/README.md to the related more detailed description chapter later in the same README.md ?

TODO... this and a few of the other plugins are getting useful enough that they should probably be mentioned/linked in the main readme.

👍

Yes, and another TODO is that I promised @samuelkarp to roll a PR for renaming device-injector to something more closely reflecting the current state of affairs, maybe calling it container-adjuster.

Add support for adjusting container linux memory policy based
on annotations.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
@klihub
Copy link
Member

klihub commented Feb 23, 2026

The device injector plugin readme is getting a bit long.. WDYT about links from the top.. to each of these plugin supported adjustment types?

@mikebrow Do you mean to add a link from each bullet list point at the top of plugins/device-injector/README.md to the related more detailed description chapter later in the same README.md ?

@mikebrow Assuming that's what you meant I went ahead and updated it accordingly.

@klihub klihub requested a review from mikebrow February 23, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v.next to be merged into the next release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants