Skip to content
/ incus Public
forked from lxc/incus

Commit

Permalink
incusd/cgroup: Set hugepages reserved limits
Browse files Browse the repository at this point in the history
Closes lxc#769

Signed-off-by: Stéphane Graber <[email protected]>
  • Loading branch information
stgraber committed Apr 20, 2024
1 parent f2e3d04 commit e8afad8
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions internal/server/cgroup/abstraction.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,13 +754,49 @@ func (cg *CGroup) SetHugepagesLimit(pageType string, limit int64) error {
case Unavailable:
return ErrControllerMissing
case V1:
return cg.rw.Set(version, "hugetlb", fmt.Sprintf("hugetlb.%s.limit_in_bytes", pageType), fmt.Sprintf("%d", limit))
// Apply the overall limit.
err := cg.rw.Set(version, "hugetlb", fmt.Sprintf("hugetlb.%s.limit_in_bytes", pageType), fmt.Sprintf("%d", limit))
if err != nil {
return err
}

// Apply the reserved limit.
err = cg.rw.Set(version, "hugetlb", fmt.Sprintf("hugetlb.%s.rsvd.limit_in_bytes", pageType), fmt.Sprintf("%d", limit))
if err != nil && !os.IsNotExist(err) {
return err
}

return nil
case V2:
if limit == -1 {
return cg.rw.Set(version, "hugetlb", fmt.Sprintf("hugetlb.%s.max", pageType), "max")
// Apply the overall limit.
err := cg.rw.Set(version, "hugetlb", fmt.Sprintf("hugetlb.%s.max", pageType), "max")
if err != nil {
return err
}

// Apply the reserved limit.
err = cg.rw.Set(version, "hugetlb", fmt.Sprintf("hugetlb.%s.rsvd.max", pageType), "max")
if err != nil && !os.IsNotExist(err) {
return err
}

return nil
}

// Apply the overall limit.
err := cg.rw.Set(version, "hugetlb", fmt.Sprintf("hugetlb.%s.max", pageType), fmt.Sprintf("%d", limit))
if err != nil {
return err
}

return cg.rw.Set(version, "hugetlb", fmt.Sprintf("hugetlb.%s.max", pageType), fmt.Sprintf("%d", limit))
// Apply the reserved limit.
err = cg.rw.Set(version, "hugetlb", fmt.Sprintf("hugetlb.%s.rsvd.max", pageType), fmt.Sprintf("%d", limit))
if err != nil && !os.IsNotExist(err) {
return err
}

return nil
}

return ErrUnknownVersion
Expand Down

0 comments on commit e8afad8

Please sign in to comment.