Skip to content

Commit a722a43

Browse files
committed
Add support for Linux memory policy
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]>
1 parent ea38318 commit a722a43

File tree

6 files changed

+159
-0
lines changed

6 files changed

+159
-0
lines changed

config-linux.md

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

693+
## <a name="configLinuxMemoryPolicy" />Memory policy
694+
695+
**`memoryPolicy`** (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_PREFERRED_MANY`
708+
* `MPOL_LOCAL`
709+
710+
* **`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.
711+
712+
* **`flags`** *(array of strings, OPTIONAL)* - list of flags to use with set_mempolicy(2).
713+
714+
A valid list of constants is shown below.
715+
716+
* `MPOL_F_NUMA_BALANCING`
717+
* `MPOL_F_RELATIVE_NODES`
718+
* `MPOL_F_STATIC_NODES`
719+
720+
### Example
721+
722+
```json
723+
"linux": {
724+
"memoryPolicy": {
725+
"mode": "MPOL_INTERLEAVE",
726+
"nodes": "2-3"
727+
"flags": ["MPOL_F_STATIC_NODES"],
728+
}
729+
}
730+
```
731+
693732
## <a name="configLinuxSysctl" />Sysctl
694733

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

9741013
[full.4]: https://man7.org/linux/man-pages/man4/full.4.html
1014+
[set_mempolicy.2]: https://man7.org/linux/man-pages/man2/set_mempolicy.2.html
9751015
[mknod.1]: https://man7.org/linux/man-pages/man1/mknod.1.html
9761016
[mknod.2]: https://man7.org/linux/man-pages/man2/mknod.2.html
9771017
[namespaces.7_2]: https://man7.org/linux/man-pages/man7/namespaces.7.html

features-linux.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,37 @@ Irrelevant to the availability of SELinux on the host operating system.
195195
}
196196
```
197197

198+
## <a name="linuxFeaturesMemoryPolicy" />MemoryPolicy
199+
200+
**`memoryPolicy`** (object, OPTIONAL) represents the runtime's implementation status of memoryPolicy.
201+
202+
* **`modes`** (array of strings, OPTIONAL). Recognized memory policies. Includes policies that may not be supported by the host operating system.
203+
The runtime MUST recognize the elements in this array as the [`mode` of `linux.memoryPolicy` objects in `config.json`](config-linux.md#memory-policy).
204+
205+
* **`flags`** (array of strings, OPTIONAL). Recognized flags for memory policies. Includes flags that may not be supported by the host operating system.
206+
The runtime MUST recognize the elements in this in the [`flags` property of the `linux.memoryPolicy` object in `config.json`](config-linux.md#memory-policy)
207+
208+
### Example
209+
210+
```json
211+
"memoryPolicy": {
212+
"modes": [
213+
"MPOL_DEFAULT",
214+
"MPOL_BIND",
215+
"MPOL_INTERLEAVE",
216+
"MPOL_WEIGHTED_INTERLEAVE",
217+
"MPOL_PREFERRED",
218+
"MPOL_PREFERRED_MANY",
219+
"MPOL_LOCAL"
220+
],
221+
"flags": [
222+
"MPOL_F_NUMA_BALANCING",
223+
"MPOL_F_RELATIVE_NODES",
224+
"MPOL_F_STATIC_NODES"
225+
]
226+
}
227+
```
228+
198229
## <a name="linuxFeaturesIntelRdt" />Intel RDT
199230

200231
**`intelRdt`** (object, OPTIONAL) represents the runtime's implementation status of Intel RDT.

features.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,22 @@ Here is a full example for reference.
354354
"selinux": {
355355
"enabled": true
356356
},
357+
"memoryPolicy": {
358+
"modes": [
359+
"MPOL_DEFAULT",
360+
"MPOL_BIND",
361+
"MPOL_INTERLEAVE",
362+
"MPOL_WEIGHTED_INTERLEAVE",
363+
"MPOL_PREFERRED",
364+
"MPOL_PREFERRED_MANY",
365+
"MPOL_LOCAL"
366+
],
367+
"flags": [
368+
"MPOL_F_NUMA_BALANCING",
369+
"MPOL_F_RELATIVE_NODES",
370+
"MPOL_F_STATIC_NODES"
371+
]
372+
},
357373
"intelRdt": {
358374
"enabled": true
359375
}

schema/config-linux.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,23 @@
277277
}
278278
}
279279
},
280+
"memoryPolicy": {
281+
"type": "object",
282+
"properties": {
283+
"mode": {
284+
"$ref": "defs-linux.json#/definitions/MemoryPolicyMode"
285+
},
286+
"nodes": {
287+
"type": "string"
288+
},
289+
"flags": {
290+
"type": "array",
291+
"items": {
292+
"$ref": "defs-linux.json#/definitions/MemoryPolicyFlag"
293+
}
294+
}
295+
}
296+
},
280297
"personality": {
281298
"type": "object",
282299
"$ref": "defs-linux.json#/definitions/Personality"

schema/defs-linux.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,26 @@
264264
"allow"
265265
]
266266
},
267+
"MemoryPolicyMode": {
268+
"type": "string",
269+
"enum": [
270+
"MPOL_DEFAULT",
271+
"MPOL_BIND",
272+
"MPOL_INTERLEAVE",
273+
"MPOL_WEIGHTED_INTERLEAVE",
274+
"MPOL_PREFERRED",
275+
"MPOL_PREFERRED_MANY",
276+
"MPOL_LOCAL"
277+
]
278+
},
279+
"MemoryPolicyFlag": {
280+
"type": "string",
281+
"enum": [
282+
"MPOL_F_NUMA_BALANCING",
283+
"MPOL_F_RELATIVE_NODES",
284+
"MPOL_F_STATIC_NODES"
285+
]
286+
},
267287
"NetworkInterfacePriority": {
268288
"type": "object",
269289
"properties": {

specs-go/config.go

Lines changed: 35 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+
// MemoryPolicy contains NUMA memory policy for the container.
253+
MemoryPolicy *LinuxMemoryPolicy `json:"memoryPolicy,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+
// LinuxMemoryPolicy represents input for the set_mempolicy syscall.
853+
type LinuxMemoryPolicy struct {
854+
// Mode for the set_mempolicy syscall.
855+
Mode MemoryPolicyModeType `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 []MemoryPolicyFlagType `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,26 @@ const (
876891
ZOSUTSNamespace ZOSNamespaceType = "uts"
877892
)
878893

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

0 commit comments

Comments
 (0)