Skip to content

Commit be4b9f4

Browse files
committed
Add support for Linux memory policy
Enable setting a NUMA memory policy for the container. New linux.mempolicy object contains inputs to the set_mempolicy(2) syscall. Signed-off-by: Antti Kervinen <[email protected]>
1 parent ea38318 commit be4b9f4

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

config-linux.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,44 @@ and may use a maximum memory bandwidth of 20% on socket 0 and 70% on socket 1.
690690
}
691691
```
692692

693+
## <a name="configLinuxMempolicy" />Mempolicy
694+
695+
**`mempolicy`** (object, OPTIONAL) sets the NUMA memory policy for the container.
696+
For more information see the [set_mempolicy(2)][set_mempolicy.2] man page.
697+
698+
* **`mode`** *(string, REQUIRED)* -
699+
700+
A valid list of constants is shown below.
701+
702+
* `MPOL_DEFAULT`
703+
* `MPOL_BIND`
704+
* `MPOL_INTERLEAVE`
705+
* `MPOL_WEIGHTED_INTERLEAVE`
706+
* `MPOL_PREFERRED`
707+
* `MPOL_LOCAL`
708+
709+
* **`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.
710+
711+
* **`flags`** *(array of strings, OPTIONAL)* - list of flags to use with set_mempolicy(2).
712+
713+
A valid list of constants is shown below.
714+
715+
* `MPOL_F_NUMA_BALANCING`
716+
* `MPOL_F_RELATIVE_NODES`
717+
* `MPOL_F_STATIC_NODES`
718+
719+
### Example
720+
721+
```json
722+
"linux": {
723+
"mempolicy": {
724+
"mode": "MPOL_INTERLEAVE",
725+
"nodes": "2-3"
726+
"flags": ["MPOL_F_STATIC_NODES"],
727+
}
728+
}
729+
```
730+
693731
## <a name="configLinuxSysctl" />Sysctl
694732

695733
**`sysctl`** (object, OPTIONAL) allows kernel parameters to be modified at runtime for the container.
@@ -972,6 +1010,7 @@ subset of the available options.
9721010
[tmpfs]: https://www.kernel.org/doc/Documentation/filesystems/tmpfs.txt
9731011

9741012
[full.4]: https://man7.org/linux/man-pages/man4/full.4.html
1013+
[set_mempolicy.2]: https://man7.org/linux/man-pages/man2/set_mempolicy.2.html
9751014
[mknod.1]: https://man7.org/linux/man-pages/man1/mknod.1.html
9761015
[mknod.2]: https://man7.org/linux/man-pages/man2/mknod.2.html
9771016
[namespaces.7_2]: https://man7.org/linux/man-pages/man7/namespaces.7.html

schema/config-linux.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,20 @@
277277
}
278278
}
279279
},
280+
"mempolicy": {
281+
"type": "object",
282+
"properties": {
283+
"mode": {
284+
"$ref": "defs-linux.json#/definitions/MempolicyMode"
285+
},
286+
"nodes": {
287+
"type": "string"
288+
},
289+
"flags": {
290+
"$ref": "defs-linux.json#/definitions/MempolicyFlags"
291+
}
292+
}
293+
},
280294
"personality": {
281295
"type": "object",
282296
"$ref": "defs-linux.json#/definitions/Personality"

schema/defs-linux.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,25 @@
264264
"allow"
265265
]
266266
},
267+
"MempolicyMode": {
268+
"type": "string",
269+
"enum": [
270+
"MPOL_DEFAULT",
271+
"MPOL_BIND",
272+
"MPOL_INTERLEAVE",
273+
"MPOL_WEIGHTED_INTERLEAVE",
274+
"MPOL_PREFERRED",
275+
"MPOL_LOCAL"
276+
]
277+
},
278+
"MempolicyFlags": {
279+
"type": "string",
280+
"enum": [
281+
"MPOL_F_NUMA_BALANCING",
282+
"MPOL_F_RELATIVE_NODES",
283+
"MPOL_F_STATIC_NODES"
284+
]
285+
},
267286
"NetworkInterfacePriority": {
268287
"type": "object",
269288
"properties": {

specs-go/config.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ type Linux struct {
249249
// IntelRdt contains Intel Resource Director Technology (RDT) information for
250250
// handling resource constraints and monitoring metrics (e.g., L3 cache, memory bandwidth) for the container
251251
IntelRdt *LinuxIntelRdt `json:"intelRdt,omitempty"`
252+
// Mempolicy contains NUMA memory policy for the container.
253+
Mempolicy *LinuxMempolicy `json:"mempolicy,omitempty"`
252254
// Personality contains configuration for the Linux personality syscall
253255
Personality *LinuxPersonality `json:"personality,omitempty"`
254256
// TimeOffsets specifies the offset for supporting time namespaces.
@@ -847,6 +849,19 @@ type LinuxIntelRdt struct {
847849
EnableMBM bool `json:"enableMBM,omitempty"`
848850
}
849851

852+
// LinuxMempolicy represents input for the set_mempolicy syscall.
853+
type LinuxMempolicy struct {
854+
// Mode for the set_mempolicy syscall.
855+
Mode MempolicyModeType `json:"mode"`
856+
857+
// Nodes representing the nodemask for the set_mempolicy syscall in comma separated ranges format.
858+
// Format: "<node0>-<node1>,<node2>,<node3>-<node4>,..."
859+
Nodes string `json:"nodes"`
860+
861+
// Flags for the set_mempolicy syscall.
862+
Flags []MempolicyFlagType `json:"flags,omitempty"`
863+
}
864+
850865
// ZOS contains platform-specific configuration for z/OS based containers.
851866
type ZOS struct {
852867
// Namespaces contains the namespaces that are created and/or joined by the container
@@ -876,6 +891,25 @@ const (
876891
ZOSUTSNamespace ZOSNamespaceType = "uts"
877892
)
878893

894+
type MempolicyModeType string
895+
896+
const (
897+
MpolDefault MempolicyModeType = "MPOL_DEFAULT"
898+
MpolBind MempolicyModeType = "MPOL_BIND"
899+
MpolInterleave MempolicyModeType = "MPOL_INTERLEAVE"
900+
MpolWeightedInterleave MempolicyModeType = "MPOL_WEIGHTED_INTERLEAVE"
901+
MpolPreferred MempolicyModeType = "MPOL_PREFERRED"
902+
MpolLocal MempolicyModeType = "MPOL_LOCAL"
903+
)
904+
905+
type MempolicyFlagType string
906+
907+
const (
908+
MpolFNumaBalancing MempolicyFlagType = "MPOL_F_NUMA_BALANCING"
909+
MpolFRelativeNodes MempolicyFlagType = "MPOL_F_RELATIVE_NODES"
910+
MpolFStaticNodes MempolicyFlagType = "MPOL_F_STATIC_NODES"
911+
)
912+
879913
// LinuxSchedulerPolicy represents different scheduling policies used with the Linux Scheduler
880914
type LinuxSchedulerPolicy string
881915

0 commit comments

Comments
 (0)