From 2c3949a687e0935929bef8a11cd75fcf6811737c Mon Sep 17 00:00:00 2001 From: jianbosun Date: Fri, 3 Apr 2015 15:50:13 +0800 Subject: [PATCH] Change memory usage by minus cache memory Signed-off-by: Sun Jianbo Add stats.cache into MemoryStats add cache to the output then client can clarify the results. Signed-off-by: Sun Jianbo Do not subtract cache from usage Signed-off-by: Michael Crosby --- cgroups/fs/memory.go | 1 + cgroups/fs/memory_test.go | 2 +- cgroups/stats.go | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cgroups/fs/memory.go b/cgroups/fs/memory.go index b99f8168..d5dbaf65 100644 --- a/cgroups/fs/memory.go +++ b/cgroups/fs/memory.go @@ -95,6 +95,7 @@ func (s *MemoryGroup) GetStats(path string, stats *cgroups.Stats) error { return fmt.Errorf("failed to parse memory.usage_in_bytes - %v", err) } stats.MemoryStats.Usage = value + stats.MemoryStats.Cache = stats.MemoryStats.Stats["cache"] value, err = getCgroupParamUint(path, "memory.max_usage_in_bytes") if err != nil { return fmt.Errorf("failed to parse memory.max_usage_in_bytes - %v", err) diff --git a/cgroups/fs/memory_test.go b/cgroups/fs/memory_test.go index 1e939c4e..60edc67a 100644 --- a/cgroups/fs/memory_test.go +++ b/cgroups/fs/memory_test.go @@ -128,7 +128,7 @@ func TestMemoryStats(t *testing.T) { if err != nil { t.Fatal(err) } - expectedStats := cgroups.MemoryStats{Usage: 2048, MaxUsage: 4096, Failcnt: 100, Stats: map[string]uint64{"cache": 512, "rss": 1024}} + expectedStats := cgroups.MemoryStats{Usage: 2048, Cache: 512, MaxUsage: 4096, Failcnt: 100, Stats: map[string]uint64{"cache": 512, "rss": 1024}} expectMemoryStatEquals(t, expectedStats, actualStats.MemoryStats) } diff --git a/cgroups/stats.go b/cgroups/stats.go index dc5dbb3c..25c8f199 100644 --- a/cgroups/stats.go +++ b/cgroups/stats.go @@ -33,6 +33,8 @@ type CpuStats struct { type MemoryStats struct { // current res_counter usage for memory Usage uint64 `json:"usage,omitempty"` + // memory used for cache + Cache uint64 `json:"cache,omitempty"` // maximum usage ever recorded. MaxUsage uint64 `json:"max_usage,omitempty"` // TODO(vishh): Export these as stronger types.