Skip to content
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

incusd/instance/lxc: Only apply soft cgroup limits on cgroup1 #760

Merged
merged 1 commit into from
Apr 16, 2024
Merged
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
14 changes: 8 additions & 6 deletions internal/server/instance/drivers/driver_lxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1180,10 +1180,12 @@ func (d *lxc) initLXC(config bool) (*liblxc.Container, error) {
}
}

// Set soft limit to value 10% less than hard limit
err = cg.SetMemorySoftLimit(int64(float64(valueInt) * 0.9))
if err != nil {
return nil, err
// If on CGroup1, set soft limit to value 10% less than hard limit.
if slices.Contains([]cgroup.Layout{cgroup.CgroupsLegacy, cgroup.CgroupsHybrid}, d.state.OS.CGInfo.Layout) {
err = cg.SetMemorySoftLimit(int64(float64(valueInt) * 0.9))
if err != nil {
return nil, err
}
}
}
}
Expand Down Expand Up @@ -4654,8 +4656,8 @@ func (d *lxc) Update(args db.InstanceArgs, userRequested bool) error {
}
}

// Set soft limit to value 10% less than hard limit.
if memoryInt > 0 {
// If on Cgroup1, set soft limit to value 10% less than hard limit.
if memoryInt > 0 && slices.Contains([]cgroup.Layout{cgroup.CgroupsLegacy, cgroup.CgroupsHybrid}, d.state.OS.CGInfo.Layout) {
err = cg.SetMemorySoftLimit(int64(float64(memoryInt) * 0.9))
if err != nil {
revertMemory()
Expand Down
Loading