Skip to content

Commit

Permalink
feat: add memory.min param
Browse files Browse the repository at this point in the history
It helps to configure memory.min cgroup parameter.

Signed-off-by: Serge Logvinov <serge.logvinov@sinextra.dev>
  • Loading branch information
sergelogvinov committed Feb 28, 2022
1 parent e96fc8e commit 8276db2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions v2/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,11 @@ func NewSystemd(slice, group string, pid int, resources *Resources) (*Manager, e
properties = append(properties, newSystemdProperty("PIDs", []uint32{uint32(pid)}))
}

if resources.Memory != nil && resources.Memory.Min != nil && *resources.Memory.Min != 0 {
properties = append(properties,
newSystemdProperty("MemoryMin", uint64(*resources.Memory.Min)))
}

if resources.Memory != nil && resources.Memory.Max != nil && *resources.Memory.Max != 0 {
properties = append(properties,
newSystemdProperty("MemoryMax", uint64(*resources.Memory.Max)))
Expand Down
7 changes: 7 additions & 0 deletions v2/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v2

type Memory struct {
Swap *int64
Min *int64
Max *int64
Low *int64
High *int64
Expand All @@ -30,6 +31,12 @@ func (r *Memory) Values() (o []Value) {
value: *r.Swap,
})
}
if r.Min != nil {
o = append(o, Value{
filename: "memory.min",
value: *r.Min,
})
}
if r.Max != nil {
o = append(o, Value{
filename: "memory.max",
Expand Down
2 changes: 2 additions & 0 deletions v2/memoryv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ func TestSystemdCgroupMemoryController(t *testing.T) {
group := fmt.Sprintf("testing-memory-%d.scope", os.Getpid())
res := Resources{
Memory: &Memory{
Min: pointerInt64(16384),
Max: pointerInt64(629145600),
},
}
c, err := NewSystemd("", group, os.Getpid(), &res)
if err != nil {
t.Fatal("failed to init new cgroup systemd manager: ", err)
}
checkFileContent(t, c.path, "memory.min", "16384")
checkFileContent(t, c.path, "memory.max", "629145600")
}

0 comments on commit 8276db2

Please sign in to comment.