|
41 | 41 | flag int
|
42 | 42 | }
|
43 | 43 | complexFlags map[string]func(*configs.Mount)
|
| 44 | + mpolModeMap map[specs.MemoryPolicyModeType]uint |
| 45 | + mpolModeFMap map[specs.MemoryPolicyFlagType]uint |
44 | 46 | )
|
45 | 47 |
|
46 | 48 | func initMaps() {
|
@@ -148,6 +150,22 @@ func initMaps() {
|
148 | 150 | m.IDMapping.Recursive = true
|
149 | 151 | },
|
150 | 152 | }
|
| 153 | + |
| 154 | + mpolModeMap = map[specs.MemoryPolicyModeType]uint{ |
| 155 | + specs.MpolDefault: configs.MPOL_DEFAULT, |
| 156 | + specs.MpolPreferred: configs.MPOL_PREFERRED, |
| 157 | + specs.MpolBind: configs.MPOL_BIND, |
| 158 | + specs.MpolInterleave: configs.MPOL_INTERLEAVE, |
| 159 | + specs.MpolLocal: configs.MPOL_LOCAL, |
| 160 | + specs.MpolPreferredMany: configs.MPOL_PREFERRED_MANY, |
| 161 | + specs.MpolWeightedInterleave: configs.MPOL_WEIGHTED_INTERLEAVE, |
| 162 | + } |
| 163 | + |
| 164 | + mpolModeFMap = map[specs.MemoryPolicyFlagType]uint{ |
| 165 | + specs.MpolFStaticNodes: configs.MPOL_F_STATIC_NODES, |
| 166 | + specs.MpolFRelativeNodes: configs.MPOL_F_RELATIVE_NODES, |
| 167 | + specs.MpolFNumaBalancing: configs.MPOL_F_NUMA_BALANCING, |
| 168 | + } |
151 | 169 | })
|
152 | 170 | }
|
153 | 171 |
|
@@ -184,6 +202,30 @@ func KnownMountOptions() []string {
|
184 | 202 | return res
|
185 | 203 | }
|
186 | 204 |
|
| 205 | +// KnownMemoryPolicyModes returns the list of the known memory policy modes. |
| 206 | +// Used by `runc features`. |
| 207 | +func KnownMemoryPolicyModes() []string { |
| 208 | + initMaps() |
| 209 | + var res []string |
| 210 | + for k := range mpolModeMap { |
| 211 | + res = append(res, string(k)) |
| 212 | + } |
| 213 | + sort.Strings(res) |
| 214 | + return res |
| 215 | +} |
| 216 | + |
| 217 | +// KnownMemoryPolicyFlags returns the list of the known memory policy mode flags. |
| 218 | +// Used by `runc features`. |
| 219 | +func KnownMemoryPolicyFlags() []string { |
| 220 | + initMaps() |
| 221 | + var res []string |
| 222 | + for k := range mpolModeFMap { |
| 223 | + res = append(res, string(k)) |
| 224 | + } |
| 225 | + sort.Strings(res) |
| 226 | + return res |
| 227 | +} |
| 228 | + |
187 | 229 | // AllowedDevices is the set of devices which are automatically included for
|
188 | 230 | // all containers.
|
189 | 231 | //
|
@@ -468,6 +510,28 @@ func CreateLibcontainerConfig(opts *CreateOpts) (*configs.Config, error) {
|
468 | 510 | MemBwSchema: spec.Linux.IntelRdt.MemBwSchema,
|
469 | 511 | }
|
470 | 512 | }
|
| 513 | + if spec.Linux.MemoryPolicy != nil { |
| 514 | + var ok bool |
| 515 | + var err error |
| 516 | + specMp := spec.Linux.MemoryPolicy |
| 517 | + confMp := &configs.LinuxMemoryPolicy{} |
| 518 | + confMp.Mode, ok = mpolModeMap[specMp.Mode] |
| 519 | + if !ok { |
| 520 | + return nil, fmt.Errorf("invalid memory policy mode %q", specMp.Mode) |
| 521 | + } |
| 522 | + confMp.Nodes, err = configs.ToCPUSet(specMp.Nodes) |
| 523 | + if err != nil { |
| 524 | + return nil, fmt.Errorf("invalid memory policy nodes %q: %w", specMp.Nodes, err) |
| 525 | + } |
| 526 | + for _, specFlag := range specMp.Flags { |
| 527 | + confFlag, ok := mpolModeFMap[specFlag] |
| 528 | + if !ok { |
| 529 | + return nil, fmt.Errorf("invalid memory policy flag %q", specFlag) |
| 530 | + } |
| 531 | + confMp.Flags = append(confMp.Flags, confFlag) |
| 532 | + } |
| 533 | + config.MemoryPolicy = confMp |
| 534 | + } |
471 | 535 | if spec.Linux.Personality != nil {
|
472 | 536 | if len(spec.Linux.Personality.Flags) > 0 {
|
473 | 537 | logrus.Warnf("ignoring unsupported personality flags: %+v because personality flag has not supported at this time", spec.Linux.Personality.Flags)
|
|
0 commit comments