Skip to content

Commit

Permalink
libctr/fs2: best effort collect memory stats
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Hunt <[email protected]>
  • Loading branch information
haircommander committed Sep 27, 2023
1 parent cd71d92 commit 94655ab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions libcontainer/cgroups/fs2/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,22 @@ func getMemoryDataV2(path, name string) (cgroups.MemoryData, error) {
},
}

var lastErr error
for _, f := range files {
value, err := fscommon.GetCgroupParamUint(path, f.name)
if err != nil {
if name != "" && os.IsNotExist(err) {
// Ignore EEXIST as there's no swap accounting
// if kernel CONFIG_MEMCG_SWAP is not set or
// swapaccount=0 kernel boot parameter is given.
return cgroups.MemoryData{}, nil
continue
}
return cgroups.MemoryData{}, err
lastErr = err
}
*f.value = value
}

return memoryData, nil
return memoryData, lastErr
}

func rootStatsFromMeminfo(stats *cgroups.Stats) error {
Expand Down
2 changes: 1 addition & 1 deletion libcontainer/cgroups/fs2/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestStatMemoryPodCgroupNotFound(t *testing.T) {
t.Errorf("expected error when statting memory for cgroupv2 root, but was nil")
}

if !strings.Contains(err.Error(), "memory.current: no such file or directory") {
if !strings.Contains(err.Error(), "memory.peak: no such file or directory") {
t.Errorf("expected error to contain 'memory.current: no such file or directory', but was %s", err.Error())
}
}
Expand Down

0 comments on commit 94655ab

Please sign in to comment.