Skip to content

Conversation

askervin
Copy link
Contributor

Enable setting a NUMA memory policy for the container. New linux.mempolicy object contains inputs to the set_mempolicy(2) syscall.

@kad
Copy link
Contributor

kad commented Mar 27, 2025

Small nit, I'd suggest to use MemoryPolicy and memoryPolicy instead of mempolicy. It would be more readable IMHO.

@giuseppe
Copy link
Member

LGTM after the changes suggested above

@askervin askervin force-pushed the 5aD-oci-mempolicy branch from be4b9f4 to ee377f1 Compare March 28, 2025 14:56
@askervin
Copy link
Contributor Author

Small nit, I'd suggest to use MemoryPolicy and memoryPolicy instead of mempolicy. It would be more readable IMHO.

Thanks @kad, fixed. Definitely better.

@askervin askervin force-pushed the 5aD-oci-mempolicy branch from ee377f1 to 68936b6 Compare March 28, 2025 15:00
Copy link
Member

@utam0k utam0k left a comment

Choose a reason for hiding this comment

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

It seems set_mempolicy(2) is only effective agains for called threads. I'm not sure how to do it for processes created with exec. Any ideas?

set_mempolicy() sets the NUMA memory policy of the calling thread,
which consists of a policy mode and zero or more nodes, to the
values specified by the mode, nodemask, and maxnode arguments.

The behavior of several other system calls is the same, so it might be a good idea to define their behavior as well.

@utam0k
Copy link
Member

utam0k commented Apr 1, 2025

It seems set_mempolicy(2) is only effective agains for called threads.

I'm not sure but we may need to implement it in nsexec.c of runc because of the thread limitation. I recommend to implement PoC in runc.

@giuseppe
Copy link
Member

giuseppe commented Apr 1, 2025

It seems set_mempolicy(2) is only effective agains for called threads. I'm not sure how to do it for processes created with exec. Any ideas?

the man page says:

The process memory policy is preserved across an [execve](https://linux.die.net/man/2/execve)(2), and is inherited by child processes created using [fork](https://linux.die.net/man/2/fork)(2) or [clone](https://linux.die.net/man/2/clone)(2).

so I don't think it is a problem for the spec

@utam0k
Copy link
Member

utam0k commented Apr 1, 2025

@giuseppe Oh, I missed it. Looks good.

@AkihiroSuda AkihiroSuda added this to the v1.3.0 milestone Apr 8, 2025
askervin added a commit to askervin/runc that referenced this pull request Apr 16, 2025
Implement support for Linux memory policy in OCI spec PR:
opencontainers/runtime-spec#1282

TODO:
- remove the replace from go.mod when OCI spec is merged

Signed-off-by: Antti Kervinen <[email protected]>
askervin added a commit to askervin/runc that referenced this pull request Apr 16, 2025
Implement support for Linux memory policy in OCI spec PR:
opencontainers/runtime-spec#1282

TODO:
- remove the replace from go.mod when OCI spec is merged

Signed-off-by: Antti Kervinen <[email protected]>
askervin added a commit to askervin/runc that referenced this pull request Apr 16, 2025
Implement support for Linux memory policy in OCI spec PR:
opencontainers/runtime-spec#1282

TODO:
- remove the replace from go.mod when OCI spec is merged

Signed-off-by: Antti Kervinen <[email protected]>
askervin added a commit to askervin/runc that referenced this pull request Apr 16, 2025
Implement support for Linux memory policy in OCI spec PR:
opencontainers/runtime-spec#1282

TODO:
- remove the replace from go.mod when OCI spec is merged

Signed-off-by: Antti Kervinen <[email protected]>
askervin added a commit to askervin/runc that referenced this pull request Apr 16, 2025
Implement support for Linux memory policy in OCI spec PR:
opencontainers/runtime-spec#1282

TODO:
- remove the replace from go.mod when OCI spec is merged

Signed-off-by: Antti Kervinen <[email protected]>
askervin added a commit to askervin/runc that referenced this pull request Apr 16, 2025
Implement support for Linux memory policy in OCI spec PR:
opencontainers/runtime-spec#1282

TODO:
- remove the replace from go.mod when OCI spec is merged

Signed-off-by: Antti Kervinen <[email protected]>
askervin added a commit to askervin/runc that referenced this pull request Apr 22, 2025
Implement support for Linux memory policy in OCI spec PR:
opencontainers/runtime-spec#1282

TODO:
- remove the replace from go.mod

Signed-off-by: Antti Kervinen <[email protected]>
@askervin askervin force-pushed the 5aD-oci-mempolicy branch from a722a43 to fb37d43 Compare April 23, 2025 07:26
askervin added a commit to askervin/runc that referenced this pull request Apr 23, 2025
Implement support for Linux memory policy in OCI spec PR:
opencontainers/runtime-spec#1282

TODO:
- remove the replace from go.mod

Signed-off-by: Antti Kervinen <[email protected]>
askervin added a commit to askervin/runc that referenced this pull request Apr 23, 2025
Implement support for Linux memory policy in OCI spec PR:
opencontainers/runtime-spec#1282

TODO:
- remove the replace from go.mod

Signed-off-by: Antti Kervinen <[email protected]>
Enable setting a NUMA memory policy for the container. New
linux.memoryPolicy object contains inputs to the set_mempolicy(2)
syscall.

Signed-off-by: Antti Kervinen <[email protected]>
@askervin askervin force-pushed the 5aD-oci-mempolicy branch from fb37d43 to 57c9495 Compare April 23, 2025 07:33
askervin added a commit to askervin/runc that referenced this pull request Apr 23, 2025
Implement support for Linux memory policy in OCI spec PR:
opencontainers/runtime-spec#1282

TODO:
- remove the replace from go.mod

Signed-off-by: Antti Kervinen <[email protected]>
Copy link
Contributor

@marquiz marquiz left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

LGTM

@AkihiroSuda AkihiroSuda merged commit bfdffd5 into opencontainers:main Aug 4, 2025
4 checks passed
askervin added a commit to askervin/runc that referenced this pull request Aug 5, 2025
Implement support for Linux memory policy in OCI spec PR:
opencontainers/runtime-spec#1282

Signed-off-by: Antti Kervinen <[email protected]>
askervin added a commit to askervin/runc that referenced this pull request Aug 5, 2025
Implement support for Linux memory policy in OCI spec PR:
opencontainers/runtime-spec#1282

Signed-off-by: Antti Kervinen <[email protected]>
* `MPOL_PREFERRED_MANY`
* `MPOL_LOCAL`

* **`nodes`** *(string, REQUIRED)* - list of memory nodes from which nodemask is constructed to set_mempolicy(2). This is a comma-separated list, with dashes to represent ranges. For example, `0-3,7` represents memory nodes 0,1,2,3, and 7.

Choose a reason for hiding this comment

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

I think this might not be 100% correct. nodes is not required for MPOL_DEFAULT or MPOL_LOCAL, in fact set_mempolicy(2) explicitly mention to set nodes to NULL, 0 (even if some variants can work as well as long as nodes is empty).

There is also a question about parsing nodes strings. libnuma supports more modes than the ones described here. Including "all" (all nodes), "+" for relative and "!" for negation. Wouldn´t it be better to align the implementations to configure mempolicy to a common format/method and provide a better user interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing out the issue in documentation, @fabbione! Fixed in PR #1294.

Regarding the convenience syntax for nodes, I was arguing against it in opencontainers/runc#4726 (comment). Let's continue the discussion there, if you disagree.

Choose a reason for hiding this comment

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

no problem at all, thanks for being so fast in fixing the docs etc.

askervin added a commit to askervin/runc that referenced this pull request Aug 26, 2025
Implement support for Linux memory policy in OCI spec PR:
opencontainers/runtime-spec#1282

Signed-off-by: Antti Kervinen <[email protected]>

// Nodes representing the nodemask for the set_mempolicy syscall in comma separated ranges format.
// Format: "<node0>-<node1>,<node2>,<node3>-<node4>,..."
Nodes string `json:"nodes"`
Copy link
Member

Choose a reason for hiding this comment

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

Should this have been omitempty too?

askervin added a commit to askervin/runc that referenced this pull request Sep 4, 2025
Implement support for Linux memory policy in OCI spec PR:
opencontainers/runtime-spec#1282

Signed-off-by: Antti Kervinen <[email protected]>
askervin added a commit to askervin/runc that referenced this pull request Sep 4, 2025
Implement support for Linux memory policy in OCI spec PR:
opencontainers/runtime-spec#1282

Signed-off-by: Antti Kervinen <[email protected]>
askervin added a commit to askervin/runc that referenced this pull request Sep 4, 2025
Implement support for Linux memory policy in OCI spec PR:
opencontainers/runtime-spec#1282

Signed-off-by: Antti Kervinen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants