From 94655abf6bbf7e1defe533038d865d6623a3c52c Mon Sep 17 00:00:00 2001 From: Peter Hunt Date: Wed, 27 Sep 2023 10:31:08 -0400 Subject: [PATCH] libctr/fs2: best effort collect memory stats Signed-off-by: Peter Hunt --- libcontainer/cgroups/fs2/memory.go | 7 ++++--- libcontainer/cgroups/fs2/memory_test.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libcontainer/cgroups/fs2/memory.go b/libcontainer/cgroups/fs2/memory.go index f2a670e4130..978a0386010 100644 --- a/libcontainer/cgroups/fs2/memory.go +++ b/libcontainer/cgroups/fs2/memory.go @@ -154,6 +154,7 @@ 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 { @@ -161,14 +162,14 @@ func getMemoryDataV2(path, name string) (cgroups.MemoryData, error) { // 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 { diff --git a/libcontainer/cgroups/fs2/memory_test.go b/libcontainer/cgroups/fs2/memory_test.go index 460efbe5cb0..fd71e1b58dc 100644 --- a/libcontainer/cgroups/fs2/memory_test.go +++ b/libcontainer/cgroups/fs2/memory_test.go @@ -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()) } }