Skip to content

Commit

Permalink
fix: make sure the memory subsystem is available before accessing the…
Browse files Browse the repository at this point in the history
… memory limit (#10098) (#10099)

(cherry picked from commit ccda834)

Co-authored-by: kruskall <99559985+kruskall@users.noreply.github.com>
  • Loading branch information
mergify[bot] and kruskall authored Jan 24, 2023
1 parent 7405083 commit 16cb9e7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/beater/memlimit_cgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,18 @@ func cgroupMemoryLimit(rdr *cgroup.Reader) (uint64, error) {
if err != nil {
return 0, fmt.Errorf("unable to read cgroup limits: %w", err)
}
if stats.Memory == nil {
return 0, fmt.Errorf("cgroup memory subsystem unavailable")
}
return stats.Memory.Mem.Limit.Bytes, nil
case cgroup.CgroupsV2:
stats, err := rdr.GetV2StatsForProcess(pid)
if err != nil {
return 0, fmt.Errorf("unable to read cgroup limits: %w", err)
}
if stats.Memory == nil {
return 0, fmt.Errorf("cgroup memory subsystem unavailable")
}
return stats.Memory.Mem.Max.Bytes.ValueOr(0), nil
}
return 0, errors.New("unsupported cgroup version")
Expand Down

0 comments on commit 16cb9e7

Please sign in to comment.