Skip to content

Commit 8276db2

Browse files
committed
feat: add memory.min param
It helps to configure memory.min cgroup parameter. Signed-off-by: Serge Logvinov <[email protected]>
1 parent e96fc8e commit 8276db2

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

v2/manager.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,11 @@ func NewSystemd(slice, group string, pid int, resources *Resources) (*Manager, e
761761
properties = append(properties, newSystemdProperty("PIDs", []uint32{uint32(pid)}))
762762
}
763763

764+
if resources.Memory != nil && resources.Memory.Min != nil && *resources.Memory.Min != 0 {
765+
properties = append(properties,
766+
newSystemdProperty("MemoryMin", uint64(*resources.Memory.Min)))
767+
}
768+
764769
if resources.Memory != nil && resources.Memory.Max != nil && *resources.Memory.Max != 0 {
765770
properties = append(properties,
766771
newSystemdProperty("MemoryMax", uint64(*resources.Memory.Max)))

v2/memory.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package v2
1818

1919
type Memory struct {
2020
Swap *int64
21+
Min *int64
2122
Max *int64
2223
Low *int64
2324
High *int64
@@ -30,6 +31,12 @@ func (r *Memory) Values() (o []Value) {
3031
value: *r.Swap,
3132
})
3233
}
34+
if r.Min != nil {
35+
o = append(o, Value{
36+
filename: "memory.min",
37+
value: *r.Min,
38+
})
39+
}
3340
if r.Max != nil {
3441
o = append(o, Value{
3542
filename: "memory.max",

v2/memoryv2_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ func TestSystemdCgroupMemoryController(t *testing.T) {
5656
group := fmt.Sprintf("testing-memory-%d.scope", os.Getpid())
5757
res := Resources{
5858
Memory: &Memory{
59+
Min: pointerInt64(16384),
5960
Max: pointerInt64(629145600),
6061
},
6162
}
6263
c, err := NewSystemd("", group, os.Getpid(), &res)
6364
if err != nil {
6465
t.Fatal("failed to init new cgroup systemd manager: ", err)
6566
}
67+
checkFileContent(t, c.path, "memory.min", "16384")
6668
checkFileContent(t, c.path, "memory.max", "629145600")
6769
}

0 commit comments

Comments
 (0)