Skip to content

Commit 57c9495

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 e935f99 commit 57c9495

File tree

7 files changed

+168
-0
lines changed

7 files changed

+168
-0
lines changed

config-linux.md

+40
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,45 @@ and may use a maximum memory bandwidth of 20% on socket 0 and 70% on socket 1.
791791
}
792792
```
793793

794+
## <a name="configLinuxMemoryPolicy" />Memory policy
795+
796+
**`memoryPolicy`** (object, OPTIONAL) sets the NUMA memory policy for the container.
797+
For more information see the [set_mempolicy(2)][set_mempolicy.2] man page.
798+
799+
* **`mode`** *(string, REQUIRED)* -
800+
801+
A valid list of constants is shown below.
802+
803+
* `MPOL_DEFAULT`
804+
* `MPOL_BIND`
805+
* `MPOL_INTERLEAVE`
806+
* `MPOL_WEIGHTED_INTERLEAVE`
807+
* `MPOL_PREFERRED`
808+
* `MPOL_PREFERRED_MANY`
809+
* `MPOL_LOCAL`
810+
811+
* **`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.
812+
813+
* **`flags`** *(array of strings, OPTIONAL)* - list of flags to use with set_mempolicy(2).
814+
815+
A valid list of constants is shown below.
816+
817+
* `MPOL_F_NUMA_BALANCING`
818+
* `MPOL_F_RELATIVE_NODES`
819+
* `MPOL_F_STATIC_NODES`
820+
821+
### Example
822+
823+
```json
824+
"linux": {
825+
"memoryPolicy": {
826+
"mode": "MPOL_INTERLEAVE",
827+
"nodes": "2-3"
828+
"flags": ["MPOL_F_STATIC_NODES"],
829+
}
830+
}
831+
```
832+
794833
## <a name="configLinuxSysctl" />Sysctl
795834

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

10751114
[full.4]: https://man7.org/linux/man-pages/man4/full.4.html
1115+
[set_mempolicy.2]: https://man7.org/linux/man-pages/man2/set_mempolicy.2.html
10761116
[mknod.1]: https://man7.org/linux/man-pages/man1/mknod.1.html
10771117
[mknod.2]: https://man7.org/linux/man-pages/man2/mknod.2.html
10781118
[namespaces.7_2]: https://man7.org/linux/man-pages/man7/namespaces.7.html

features-linux.md

+31
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

+16
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

+17
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,23 @@
283283
}
284284
}
285285
},
286+
"memoryPolicy": {
287+
"type": "object",
288+
"properties": {
289+
"mode": {
290+
"$ref": "defs-linux.json#/definitions/MemoryPolicyMode"
291+
},
292+
"nodes": {
293+
"type": "string"
294+
},
295+
"flags": {
296+
"type": "array",
297+
"items": {
298+
"$ref": "defs-linux.json#/definitions/MemoryPolicyFlag"
299+
}
300+
}
301+
}
302+
},
286303
"personality": {
287304
"type": "object",
288305
"$ref": "defs-linux.json#/definitions/Personality"

schema/defs-linux.json

+20
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,26 @@
272272
"allow"
273273
]
274274
},
275+
"MemoryPolicyMode": {
276+
"type": "string",
277+
"enum": [
278+
"MPOL_DEFAULT",
279+
"MPOL_BIND",
280+
"MPOL_INTERLEAVE",
281+
"MPOL_WEIGHTED_INTERLEAVE",
282+
"MPOL_PREFERRED",
283+
"MPOL_PREFERRED_MANY",
284+
"MPOL_LOCAL"
285+
]
286+
},
287+
"MemoryPolicyFlag": {
288+
"type": "string",
289+
"enum": [
290+
"MPOL_F_NUMA_BALANCING",
291+
"MPOL_F_RELATIVE_NODES",
292+
"MPOL_F_STATIC_NODES"
293+
]
294+
},
275295
"NetworkInterfacePriority": {
276296
"type": "object",
277297
"properties": {

specs-go/config.go

+35
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ type Linux struct {
251251
// IntelRdt contains Intel Resource Director Technology (RDT) information for
252252
// handling resource constraints and monitoring metrics (e.g., L3 cache, memory bandwidth) for the container
253253
IntelRdt *LinuxIntelRdt `json:"intelRdt,omitempty"`
254+
// MemoryPolicy contains NUMA memory policy for the container.
255+
MemoryPolicy *LinuxMemoryPolicy `json:"memoryPolicy,omitempty"`
254256
// Personality contains configuration for the Linux personality syscall
255257
Personality *LinuxPersonality `json:"personality,omitempty"`
256258
// TimeOffsets specifies the offset for supporting time namespaces.
@@ -855,6 +857,19 @@ type LinuxIntelRdt struct {
855857
EnableMBM bool `json:"enableMBM,omitempty"`
856858
}
857859

860+
// LinuxMemoryPolicy represents input for the set_mempolicy syscall.
861+
type LinuxMemoryPolicy struct {
862+
// Mode for the set_mempolicy syscall.
863+
Mode MemoryPolicyModeType `json:"mode"`
864+
865+
// Nodes representing the nodemask for the set_mempolicy syscall in comma separated ranges format.
866+
// Format: "<node0>-<node1>,<node2>,<node3>-<node4>,..."
867+
Nodes string `json:"nodes"`
868+
869+
// Flags for the set_mempolicy syscall.
870+
Flags []MemoryPolicyFlagType `json:"flags,omitempty"`
871+
}
872+
858873
// ZOS contains platform-specific configuration for z/OS based containers.
859874
type ZOS struct {
860875
// Namespaces contains the namespaces that are created and/or joined by the container
@@ -884,6 +899,26 @@ const (
884899
ZOSUTSNamespace ZOSNamespaceType = "uts"
885900
)
886901

902+
type MemoryPolicyModeType string
903+
904+
const (
905+
MpolDefault MemoryPolicyModeType = "MPOL_DEFAULT"
906+
MpolBind MemoryPolicyModeType = "MPOL_BIND"
907+
MpolInterleave MemoryPolicyModeType = "MPOL_INTERLEAVE"
908+
MpolWeightedInterleave MemoryPolicyModeType = "MPOL_WEIGHTED_INTERLEAVE"
909+
MpolPreferred MemoryPolicyModeType = "MPOL_PREFERRED"
910+
MpolPreferredMany MemoryPolicyModeType = "MPOL_PREFERRED_MANY"
911+
MpolLocal MemoryPolicyModeType = "MPOL_LOCAL"
912+
)
913+
914+
type MemoryPolicyFlagType string
915+
916+
const (
917+
MpolFNumaBalancing MemoryPolicyFlagType = "MPOL_F_NUMA_BALANCING"
918+
MpolFRelativeNodes MemoryPolicyFlagType = "MPOL_F_RELATIVE_NODES"
919+
MpolFStaticNodes MemoryPolicyFlagType = "MPOL_F_STATIC_NODES"
920+
)
921+
887922
// LinuxSchedulerPolicy represents different scheduling policies used with the Linux Scheduler
888923
type LinuxSchedulerPolicy string
889924

specs-go/features/features.go

+9
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type Linux struct {
4747
Apparmor *Apparmor `json:"apparmor,omitempty"`
4848
Selinux *Selinux `json:"selinux,omitempty"`
4949
IntelRdt *IntelRdt `json:"intelRdt,omitempty"`
50+
MemoryPolicy *MemoryPolicy `json:"memoryPolicy,omitempty"`
5051
MountExtensions *MountExtensions `json:"mountExtensions,omitempty"`
5152
NetDevices *NetDevices `json:"netDevices,omitempty"`
5253
}
@@ -132,6 +133,14 @@ type IntelRdt struct {
132133
Enabled *bool `json:"enabled,omitempty"`
133134
}
134135

136+
// MemoryPolicy represents the "memoryPolicy" field.
137+
type MemoryPolicy struct {
138+
// modes is the list of known memory policy modes, e.g., "MPOL_INTERLEAVE".
139+
Modes []string `json:"modes,omitempty"`
140+
// flags is the list of known memory policy mode flags, e.g., "MPOL_F_STATIC_NODES".
141+
Flags []string `json:"flags,omitempty"`
142+
}
143+
135144
// MountExtensions represents the "mountExtensions" field.
136145
type MountExtensions struct {
137146
// IDMap represents the status of idmap mounts support.

0 commit comments

Comments
 (0)