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