Skip to content

Commit bfdffd5

Browse files
authored
Merge pull request #1282 from askervin/5aD-oci-mempolicy
Add support for Linux memory policy
2 parents 34a39b9 + 57c9495 commit bfdffd5

File tree

7 files changed

+168
-0
lines changed

7 files changed

+168
-0
lines changed

config-linux.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,45 @@ Tasks inside the container:
812812
}
813813
```
814814

815+
## <a name="configLinuxMemoryPolicy" />Memory policy
816+
817+
**`memoryPolicy`** (object, OPTIONAL) sets the NUMA memory policy for the container.
818+
For more information see the [set_mempolicy(2)][set_mempolicy.2] man page.
819+
820+
* **`mode`** *(string, REQUIRED)* -
821+
822+
A valid list of constants is shown below.
823+
824+
* `MPOL_DEFAULT`
825+
* `MPOL_BIND`
826+
* `MPOL_INTERLEAVE`
827+
* `MPOL_WEIGHTED_INTERLEAVE`
828+
* `MPOL_PREFERRED`
829+
* `MPOL_PREFERRED_MANY`
830+
* `MPOL_LOCAL`
831+
832+
* **`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.
833+
834+
* **`flags`** *(array of strings, OPTIONAL)* - list of flags to use with set_mempolicy(2).
835+
836+
A valid list of constants is shown below.
837+
838+
* `MPOL_F_NUMA_BALANCING`
839+
* `MPOL_F_RELATIVE_NODES`
840+
* `MPOL_F_STATIC_NODES`
841+
842+
### Example
843+
844+
```json
845+
"linux": {
846+
"memoryPolicy": {
847+
"mode": "MPOL_INTERLEAVE",
848+
"nodes": "2-3"
849+
"flags": ["MPOL_F_STATIC_NODES"],
850+
}
851+
}
852+
```
853+
815854
## <a name="configLinuxSysctl" />Sysctl
816855

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

10961135
[full.4]: https://man7.org/linux/man-pages/man4/full.4.html
1136+
[set_mempolicy.2]: https://man7.org/linux/man-pages/man2/set_mempolicy.2.html
10971137
[mknod.1]: https://man7.org/linux/man-pages/man1/mknod.1.html
10981138
[mknod.2]: https://man7.org/linux/man-pages/man2/mknod.2.html
10991139
[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
"schemata": true

schema/config-linux.json

Lines changed: 17 additions & 0 deletions
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

Lines changed: 20 additions & 0 deletions
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

Lines changed: 35 additions & 0 deletions
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.
@@ -860,6 +862,19 @@ type LinuxIntelRdt struct {
860862
EnableMonitoring bool `json:"enableMonitoring,omitempty"`
861863
}
862864

865+
// LinuxMemoryPolicy represents input for the set_mempolicy syscall.
866+
type LinuxMemoryPolicy struct {
867+
// Mode for the set_mempolicy syscall.
868+
Mode MemoryPolicyModeType `json:"mode"`
869+
870+
// Nodes representing the nodemask for the set_mempolicy syscall in comma separated ranges format.
871+
// Format: "<node0>-<node1>,<node2>,<node3>-<node4>,..."
872+
Nodes string `json:"nodes"`
873+
874+
// Flags for the set_mempolicy syscall.
875+
Flags []MemoryPolicyFlagType `json:"flags,omitempty"`
876+
}
877+
863878
// ZOS contains platform-specific configuration for z/OS based containers.
864879
type ZOS struct {
865880
// Namespaces contains the namespaces that are created and/or joined by the container
@@ -889,6 +904,26 @@ const (
889904
ZOSUTSNamespace ZOSNamespaceType = "uts"
890905
)
891906

907+
type MemoryPolicyModeType string
908+
909+
const (
910+
MpolDefault MemoryPolicyModeType = "MPOL_DEFAULT"
911+
MpolBind MemoryPolicyModeType = "MPOL_BIND"
912+
MpolInterleave MemoryPolicyModeType = "MPOL_INTERLEAVE"
913+
MpolWeightedInterleave MemoryPolicyModeType = "MPOL_WEIGHTED_INTERLEAVE"
914+
MpolPreferred MemoryPolicyModeType = "MPOL_PREFERRED"
915+
MpolPreferredMany MemoryPolicyModeType = "MPOL_PREFERRED_MANY"
916+
MpolLocal MemoryPolicyModeType = "MPOL_LOCAL"
917+
)
918+
919+
type MemoryPolicyFlagType string
920+
921+
const (
922+
MpolFNumaBalancing MemoryPolicyFlagType = "MPOL_F_NUMA_BALANCING"
923+
MpolFRelativeNodes MemoryPolicyFlagType = "MPOL_F_RELATIVE_NODES"
924+
MpolFStaticNodes MemoryPolicyFlagType = "MPOL_F_STATIC_NODES"
925+
)
926+
892927
// LinuxSchedulerPolicy represents different scheduling policies used with the Linux Scheduler
893928
type LinuxSchedulerPolicy string
894929

specs-go/features/features.go

Lines changed: 9 additions & 0 deletions
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)