From 0f754f0bb9433951658852467224a061e273506a Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Tue, 20 Jun 2023 13:29:27 +0100 Subject: [PATCH] fix(clistat): do not include buffers/cache for host memory used (#8095) --- cli/clistat/stat.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cli/clistat/stat.go b/cli/clistat/stat.go index 1c19e33ef5..dffabd2cec 100644 --- a/cli/clistat/stat.go +++ b/cli/clistat/stat.go @@ -186,6 +186,10 @@ func (s *Statter) HostMemory() (*Result, error) { return nil, xerrors.Errorf("get memory info: %w", err) } r.Total = ptr.To(float64(hm.Total)) - r.Used = float64(hm.Used) + // On Linux, hm.Used equates to MemTotal - MemFree in /proc/stat. + // This includes buffers and cache. + // So use MemAvailable instead, which only equates to physical memory. + // On Windows, this is also calculated as Total - Available. + r.Used = float64(hm.Total - hm.Available) return r, nil }