From 307d1b1cb320fef66fab02db749f07a459245451 Mon Sep 17 00:00:00 2001 From: Michael Taufen Date: Fri, 15 Jul 2016 08:42:04 -0700 Subject: [PATCH] Modify working set memory stats calculation Change working set calculation to usage - total_inactive_file, rather than usage - total_inactive_anon - total_inactive_file. Since writes to tmpfs get tracked as total_inactive_anon when swap is disabled, the old calculation would under-report memory pressure. See this Kubernetes issue for context: https://github.com/kubernetes/kubernetes/issues/28619 --- container/libcontainer/helpers.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/container/libcontainer/helpers.go b/container/libcontainer/helpers.go index e030d1ad..65c72ab5 100644 --- a/container/libcontainer/helpers.go +++ b/container/libcontainer/helpers.go @@ -387,23 +387,16 @@ func toContainerStats2(s *cgroups.Stats, ret *info.ContainerStats) { ret.Memory.ContainerData.Pgmajfault = v ret.Memory.HierarchicalData.Pgmajfault = v } - if v, ok := s.MemoryStats.Stats["total_inactive_anon"]; ok { - workingSet := ret.Memory.Usage + + workingSet := ret.Memory.Usage + if v, ok := s.MemoryStats.Stats["total_inactive_file"]; ok { if workingSet < v { workingSet = 0 } else { workingSet -= v } - - if v, ok := s.MemoryStats.Stats["total_inactive_file"]; ok { - if workingSet < v { - workingSet = 0 - } else { - workingSet -= v - } - } - ret.Memory.WorkingSet = workingSet } + ret.Memory.WorkingSet = workingSet } func toContainerStats3(libcontainerStats *libcontainer.Stats, ret *info.ContainerStats) {