From b137e99af0aea94d8bc4802c0330cb6b5476fa15 Mon Sep 17 00:00:00 2001 From: HeRaNO Date: Wed, 6 Sep 2023 16:13:38 +0800 Subject: [PATCH] feat: use memory.peak and memory.swap.peak in cgroups v2 Signed-off-by: HeRaNO --- libcontainer/cgroups/fs2/memory.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libcontainer/cgroups/fs2/memory.go b/libcontainer/cgroups/fs2/memory.go index 85e96b1ce98..9b3406d6d11 100644 --- a/libcontainer/cgroups/fs2/memory.go +++ b/libcontainer/cgroups/fs2/memory.go @@ -138,6 +138,7 @@ func getMemoryDataV2(path, name string) (cgroups.MemoryData, error) { } usage := moduleName + ".current" limit := moduleName + ".max" + maxUsage := moduleName + ".peak" value, err := fscommon.GetCgroupParamUint(path, usage) if err != nil { @@ -157,6 +158,14 @@ func getMemoryDataV2(path, name string) (cgroups.MemoryData, error) { } memoryData.Limit = value + // `memory.peak` since kernel 5.19 + // `memory.swap.peak` since kernel 6.5 + value, err = fscommon.GetCgroupParamUint(path, maxUsage) + if err != nil && !os.IsNotExist(err) { + return cgroups.MemoryData{}, err + } + memoryData.MaxUsage = value + return memoryData, nil }