Skip to content

Commit 90dd1e4

Browse files
committed
mempolicy: pass plugin reply to adjustment in runtime, handle conflict
1 parent 013f9e3 commit 90dd1e4

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ require (
4040
)
4141

4242
replace (
43-
github.com/opencontainers/runtime-spec => github.com/askervin/runtime-spec v1.0.3-0.20250417130042-a722a4317550
43+
github.com/opencontainers/runtime-spec => github.com/askervin/runtime-spec v1.0.3-0.20250423073229-57c949588e88
4444
github.com/opencontainers/runtime-tools => github.com/askervin/runtime-tools v0.0.0-20250422130153-2087cf9533bc
4545
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/askervin/runtime-spec v1.0.3-0.20250417130042-a722a4317550 h1:vQgPMeVNiFFAb4VIOeRVf9siecYbXUPJLG1sbv/6oL4=
2-
github.com/askervin/runtime-spec v1.0.3-0.20250417130042-a722a4317550/go.mod h1:0ccwhiCQXxLwvWvVsdVdxTe+IFfXyJTjr/wNue5fNJY=
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=
33
github.com/askervin/runtime-tools v0.0.0-20250422130153-2087cf9533bc h1:0gE5arOd5PbR/FL7g6fscAYl/ZIz9IeggF0MAjgLoV0=
44
github.com/askervin/runtime-tools v0.0.0-20250422130153-2087cf9533bc/go.mod h1:uBzwOs+6K4xD2o35ZcFBhtSmynSky9zytTIdlc2+sqY=
55
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=

pkg/adaptation/result.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ func (r *result) adjust(rpl *ContainerAdjustment, plugin string) error {
224224
if err := r.adjustOomScoreAdj(rpl.Linux.OomScoreAdj, plugin); err != nil {
225225
return err
226226
}
227+
if err := r.adjustMemoryPolicy(rpl.Linux.MemoryPolicy, plugin); err != nil {
228+
return err
229+
}
227230
}
228231
if err := r.adjustRlimits(rpl.Rlimits, plugin); err != nil {
229232
return err
@@ -765,6 +768,22 @@ func (r *result) adjustOomScoreAdj(OomScoreAdj *OptionalInt, plugin string) erro
765768
return nil
766769
}
767770

771+
func (r *result) adjustMemoryPolicy(memoryPolicy *LinuxMemoryPolicy, plugin string) error {
772+
if memoryPolicy == nil {
773+
return nil
774+
}
775+
776+
id := r.request.create.Container.Id
777+
778+
if err := r.owners.claimMemoryPolicy(id, plugin); err != nil {
779+
return err
780+
}
781+
782+
r.reply.adjust.Linux.MemoryPolicy = memoryPolicy
783+
784+
return nil
785+
}
786+
768787
func (r *result) adjustRlimits(rlimits []*POSIXRlimit, plugin string) error {
769788
create, id, adjust := r.request.create, r.request.create.Container.Id, r.reply.adjust
770789
for _, l := range rlimits {
@@ -1004,6 +1023,7 @@ type owners struct {
10041023
unified map[string]string
10051024
cgroupsPath string
10061025
oomScoreAdj string
1026+
memoryPolicy string
10071027
rlimits map[string]string
10081028
}
10091029

@@ -1128,6 +1148,10 @@ func (ro resultOwners) claimOomScoreAdj(id, plugin string) error {
11281148
return ro.ownersFor(id).claimOomScoreAdj(plugin)
11291149
}
11301150

1151+
func (ro resultOwners) claimMemoryPolicy(id, plugin string) error {
1152+
return ro.ownersFor(id).claimMemoryPolicy(plugin)
1153+
}
1154+
11311155
func (ro resultOwners) claimRlimits(id, typ, plugin string) error {
11321156
return ro.ownersFor(id).claimRlimit(typ, plugin)
11331157
}
@@ -1389,6 +1413,14 @@ func (o *owners) claimOomScoreAdj(plugin string) error {
13891413
return nil
13901414
}
13911415

1416+
func (o *owners) claimMemoryPolicy(plugin string) error {
1417+
if other := o.memoryPolicy; other != "" {
1418+
return conflict(plugin, other, "memory policy")
1419+
}
1420+
o.memoryPolicy = plugin
1421+
return nil
1422+
}
1423+
13921424
func (ro resultOwners) clearAnnotation(id, key string) {
13931425
ro.ownersFor(id).clearAnnotation(key)
13941426
}

0 commit comments

Comments
 (0)