Skip to content

Add memory policy support #786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cmd/oci-runtime-tool/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ var generateFlags = []cli.Flag{
cli.StringFlag{Name: "linux-mems", Usage: "list of memory nodes in the cpuset (default is to use any available memory node)"},
cli.Uint64Flag{Name: "linux-mem-swap", Usage: "total memory limit (memory + swap) (in bytes)"},
cli.Uint64Flag{Name: "linux-mem-swappiness", Usage: "how aggressive the kernel will swap memory pages (Range from 0 to 100)"},
cli.StringFlag{Name: "linux-memorypolicy-mode", Usage: "memory policy defines from which nodes memory is allocated by default, e.g MPOL_INTERLEAVE"},
cli.StringFlag{Name: "linux-memorypolicy-nodes", Usage: "memory nodes related to the linux-memorypolicy-mode, e.g 0-3,7"},
cli.StringSliceFlag{Name: "linux-memorypolicy-flags", Usage: "optional memory policy mode flags, e.g MPOL_F_STATIC_NODES"},
cli.StringFlag{Name: "linux-mount-label", Usage: "selinux mount context label"},
cli.StringSliceFlag{Name: "linux-namespace-add", Usage: "adds a namespace to the set of namespaces to create or join of the form 'ns[:path]'"},
cli.StringSliceFlag{Name: "linux-namespace-remove", Usage: "removes a namespace from the set of namespaces to create or join of the form 'ns'"},
Expand Down Expand Up @@ -782,6 +785,18 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
g.SetLinuxResourcesMemorySwappiness(context.Uint64("linux-mem-swappiness"))
}

if context.IsSet("linux-memorypolicy-mode") {
g.SetLinuxMemoryPolicyMode(context.String("linux-memorypolicy-mode"))
}

if context.IsSet("linux-memorypolicy-nodes") {
g.SetLinuxMemoryPolicyNodes(context.String("linux-memorypolicy-nodes"))
}

if context.IsSet("linux-memorypolicy-flags") {
g.SetLinuxMemoryPolicyFlags(context.StringSlice("linux-memorypolicy-flags"))
}

if context.IsSet("linux-network-classid") {
g.SetLinuxResourcesNetworkClassID(uint32(context.Int("linux-network-classid")))
}
Expand Down
7 changes: 7 additions & 0 deletions generate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ func (g *Generator) initConfigLinuxResourcesMemory() {
}
}

func (g *Generator) initConfigLinuxMemoryPolicy() {
g.initConfigLinux()
if g.Config.Linux.MemoryPolicy == nil {
g.Config.Linux.MemoryPolicy = &rspec.LinuxMemoryPolicy{}
}
}

func (g *Generator) initConfigLinuxResourcesNetwork() {
g.initConfigLinuxResources()
if g.Config.Linux.Resources.Network == nil {
Expand Down
20 changes: 20 additions & 0 deletions generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,26 @@ func (g *Generator) SetLinuxResourcesMemorySwappiness(swappiness uint64) {
g.Config.Linux.Resources.Memory.Swappiness = &swappiness
}

// SetLinuxMemoryPolicyMode sets g.Config.Linux.MemoryPolicy.Mode
func (g *Generator) SetLinuxMemoryPolicyMode(mode string) {
g.initConfigLinuxMemoryPolicy()
g.Config.Linux.MemoryPolicy.Mode = rspec.MemoryPolicyModeType(mode)
}

// SetLinuxMemoryPolicyNodes sets g.Config.Linux.MemoryPolicy.Nodes
func (g *Generator) SetLinuxMemoryPolicyNodes(nodes string) {
g.initConfigLinuxMemoryPolicy()
g.Config.Linux.MemoryPolicy.Nodes = nodes
}

// SetLinuxMemoryPolicyFlags sets g.Config.Linux.MemoryPolicy.Flags
func (g *Generator) SetLinuxMemoryPolicyFlags(flags []string) {
g.initConfigLinuxMemoryPolicy()
for _, flag := range flags {
g.Config.Linux.MemoryPolicy.Flags = append(g.Config.Linux.MemoryPolicy.Flags, rspec.MemoryPolicyFlagType(flag))
}
}

// SetLinuxResourcesMemoryDisableOOMKiller sets g.Config.Linux.Resources.Memory.DisableOOMKiller.
func (g *Generator) SetLinuxResourcesMemoryDisableOOMKiller(disable bool) {
g.initConfigLinuxResourcesMemory()
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ require (
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

replace github.com/opencontainers/runtime-spec => github.com/askervin/runtime-spec v1.0.3-0.20250423073229-57c949588e88
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/askervin/runtime-spec v1.0.3-0.20250423073229-57c949588e88 h1:Rs1b8ssNo+RX0wq0ROF+OGpQ4aks2gmi9906a5tNBZk=
github.com/askervin/runtime-spec v1.0.3-0.20250423073229-57c949588e88/go.mod h1:0ccwhiCQXxLwvWvVsdVdxTe+IFfXyJTjr/wNue5fNJY=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -15,8 +17,6 @@ github.com/moby/sys/mountinfo v0.7.2 h1:1shs6aH5s4o5H2zQLn796ADW1wMrIwHsyJ2v9Kou
github.com/moby/sys/mountinfo v0.7.2/go.mod h1:1YOa8w8Ih7uW0wALDUgT1dTTSBrZ+HiBLGws92L2RU4=
github.com/mrunalp/fileutils v0.5.0 h1:NKzVxiH7eSk+OQ4M+ZYW1K6h27RUV3MI6NUTsHhU6Z4=
github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ=
github.com/opencontainers/runtime-spec v1.1.0 h1:HHUyrt9mwHUjtasSbXSMvs4cyFxh+Bll4AjJ9odEGpg=
github.com/opencontainers/runtime-spec v1.1.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opencontainers/selinux v1.9.1 h1:b4VPEF3O5JLZgdTDBmGepaaIbAo0GqoF6EBRq5f/g3Y=
github.com/opencontainers/selinux v1.9.1/go.mod h1:2i0OySw99QjzBBQByd1Gr9gSjvuho1lHsJxIJ3gGbJI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
121 changes: 101 additions & 20 deletions vendor/github.com/opencontainers/runtime-spec/specs-go/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ github.com/moby/sys/mountinfo
# github.com/mrunalp/fileutils v0.5.0
## explicit; go 1.13
github.com/mrunalp/fileutils
# github.com/opencontainers/runtime-spec v1.1.0
# github.com/opencontainers/runtime-spec v1.1.0 => github.com/askervin/runtime-spec v1.0.3-0.20250423073229-57c949588e88
## explicit
github.com/opencontainers/runtime-spec/specs-go
# github.com/opencontainers/selinux v1.9.1
Expand Down Expand Up @@ -63,3 +63,4 @@ golang.org/x/sys/windows
# gopkg.in/yaml.v2 v2.4.0
## explicit; go 1.15
gopkg.in/yaml.v2
# github.com/opencontainers/runtime-spec => github.com/askervin/runtime-spec v1.0.3-0.20250423073229-57c949588e88