Skip to content

Commit 73be79a

Browse files
committed
Add memory policy support
1 parent 260e151 commit 73be79a

File tree

8 files changed

+152
-26
lines changed

8 files changed

+152
-26
lines changed

cmd/oci-runtime-tool/generate.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ var generateFlags = []cli.Flag{
6464
cli.StringFlag{Name: "linux-mems", Usage: "list of memory nodes in the cpuset (default is to use any available memory node)"},
6565
cli.Uint64Flag{Name: "linux-mem-swap", Usage: "total memory limit (memory + swap) (in bytes)"},
6666
cli.Uint64Flag{Name: "linux-mem-swappiness", Usage: "how aggressive the kernel will swap memory pages (Range from 0 to 100)"},
67+
cli.StringFlag{Name: "linux-memorypolicy-mode", Usage: "memory policy defines from which nodes memory is allocated by default, e.g MPOL_INTERLEAVE"},
68+
cli.StringFlag{Name: "linux-memorypolicy-nodes", Usage: "memory nodes related to the linux-memorypolicy-mode, e.g 0-3,7"},
69+
cli.StringSliceFlag{Name: "linux-memorypolicy-flags", Usage: "optional memory policy mode flags, e.g MPOL_F_STATIC_NODES"},
6770
cli.StringFlag{Name: "linux-mount-label", Usage: "selinux mount context label"},
6871
cli.StringSliceFlag{Name: "linux-namespace-add", Usage: "adds a namespace to the set of namespaces to create or join of the form 'ns[:path]'"},
6972
cli.StringSliceFlag{Name: "linux-namespace-remove", Usage: "removes a namespace from the set of namespaces to create or join of the form 'ns'"},
@@ -782,6 +785,18 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
782785
g.SetLinuxResourcesMemorySwappiness(context.Uint64("linux-mem-swappiness"))
783786
}
784787

788+
if context.IsSet("linux-memorypolicy-mode") {
789+
g.SetLinuxMemoryPolicyMode(context.String("linux-memorypolicy-mode"))
790+
}
791+
792+
if context.IsSet("linux-memorypolicy-nodes") {
793+
g.SetLinuxMemoryPolicyNodes(context.String("linux-memorypolicy-nodes"))
794+
}
795+
796+
if context.IsSet("linux-memorypolicy-flags") {
797+
g.SetLinuxMemoryPolicyFlags(context.StringSlice("linux-memorypolicy-flags"))
798+
}
799+
785800
if context.IsSet("linux-network-classid") {
786801
g.SetLinuxResourcesNetworkClassID(uint32(context.Int("linux-network-classid")))
787802
}

generate/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ func (g *Generator) initConfigLinuxResourcesMemory() {
109109
}
110110
}
111111

112+
func (g *Generator) initConfigLinuxMemoryPolicy() {
113+
g.initConfigLinux()
114+
if g.Config.Linux.MemoryPolicy == nil {
115+
g.Config.Linux.MemoryPolicy = &rspec.LinuxMemoryPolicy{}
116+
}
117+
}
118+
112119
func (g *Generator) initConfigLinuxResourcesNetwork() {
113120
g.initConfigLinuxResources()
114121
if g.Config.Linux.Resources.Network == nil {

generate/generate.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,26 @@ func (g *Generator) SetLinuxResourcesMemorySwappiness(swappiness uint64) {
926926
g.Config.Linux.Resources.Memory.Swappiness = &swappiness
927927
}
928928

929+
// SetLinuxMemoryPolicyMode sets g.Config.Linux.MemoryPolicy.Mode
930+
func (g *Generator) SetLinuxMemoryPolicyMode(mode string) {
931+
g.initConfigLinuxMemoryPolicy()
932+
g.Config.Linux.MemoryPolicy.Mode = rspec.MemoryPolicyModeType(mode)
933+
}
934+
935+
// SetLinuxMemoryPolicyNodes sets g.Config.Linux.MemoryPolicy.Nodes
936+
func (g *Generator) SetLinuxMemoryPolicyNodes(nodes string) {
937+
g.initConfigLinuxMemoryPolicy()
938+
g.Config.Linux.MemoryPolicy.Nodes = nodes
939+
}
940+
941+
// SetLinuxMemoryPolicyFlags sets g.Config.Linux.MemoryPolicy.Flags
942+
func (g *Generator) SetLinuxMemoryPolicyFlags(flags []string) {
943+
g.initConfigLinuxMemoryPolicy()
944+
for _, flag := range flags {
945+
g.Config.Linux.MemoryPolicy.Flags = append(g.Config.Linux.MemoryPolicy.Flags, rspec.MemoryPolicyFlagType(flag))
946+
}
947+
}
948+
929949
// SetLinuxResourcesMemoryDisableOOMKiller sets g.Config.Linux.Resources.Memory.DisableOOMKiller.
930950
func (g *Generator) SetLinuxResourcesMemoryDisableOOMKiller(disable bool) {
931951
g.initConfigLinuxResourcesMemory()

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ require (
2727
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
2828
gopkg.in/yaml.v2 v2.4.0 // indirect
2929
)
30+
31+
replace github.com/opencontainers/runtime-spec => github.com/askervin/runtime-spec v1.0.3-0.20250423073229-57c949588e88

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/askervin/runtime-spec v1.0.3-0.20250423073229-57c949588e88 h1:Rs1b8ssNo+RX0wq0ROF+OGpQ4aks2gmi9906a5tNBZk=
2+
github.com/askervin/runtime-spec v1.0.3-0.20250423073229-57c949588e88/go.mod h1:0ccwhiCQXxLwvWvVsdVdxTe+IFfXyJTjr/wNue5fNJY=
13
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
24
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
35
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -15,8 +17,6 @@ github.com/moby/sys/mountinfo v0.7.2 h1:1shs6aH5s4o5H2zQLn796ADW1wMrIwHsyJ2v9Kou
1517
github.com/moby/sys/mountinfo v0.7.2/go.mod h1:1YOa8w8Ih7uW0wALDUgT1dTTSBrZ+HiBLGws92L2RU4=
1618
github.com/mrunalp/fileutils v0.5.0 h1:NKzVxiH7eSk+OQ4M+ZYW1K6h27RUV3MI6NUTsHhU6Z4=
1719
github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ=
18-
github.com/opencontainers/runtime-spec v1.1.0 h1:HHUyrt9mwHUjtasSbXSMvs4cyFxh+Bll4AjJ9odEGpg=
19-
github.com/opencontainers/runtime-spec v1.1.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
2020
github.com/opencontainers/selinux v1.9.1 h1:b4VPEF3O5JLZgdTDBmGepaaIbAo0GqoF6EBRq5f/g3Y=
2121
github.com/opencontainers/selinux v1.9.1/go.mod h1:2i0OySw99QjzBBQByd1Gr9gSjvuho1lHsJxIJ3gGbJI=
2222
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

vendor/github.com/opencontainers/runtime-spec/specs-go/config.go

Lines changed: 101 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/opencontainers/runtime-spec/specs-go/version.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ github.com/moby/sys/mountinfo
2222
# github.com/mrunalp/fileutils v0.5.0
2323
## explicit; go 1.13
2424
github.com/mrunalp/fileutils
25-
# github.com/opencontainers/runtime-spec v1.1.0
25+
# github.com/opencontainers/runtime-spec v1.1.0 => github.com/askervin/runtime-spec v1.0.3-0.20250423073229-57c949588e88
2626
## explicit
2727
github.com/opencontainers/runtime-spec/specs-go
2828
# github.com/opencontainers/selinux v1.9.1
@@ -63,3 +63,4 @@ golang.org/x/sys/windows
6363
# gopkg.in/yaml.v2 v2.4.0
6464
## explicit; go 1.15
6565
gopkg.in/yaml.v2
66+
# github.com/opencontainers/runtime-spec => github.com/askervin/runtime-spec v1.0.3-0.20250423073229-57c949588e88

0 commit comments

Comments
 (0)