Change memory usage by minus cache memory

Signed-off-by: Sun Jianbo <wonderflow@zju.edu.cn>

Add stats.cache into MemoryStats

add cache to the output then client can clarify the results.

Signed-off-by: Sun Jianbo <wonderflow@zju.edu.cn>

Do not subtract cache from usage

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
jianbosun 2015-04-03 15:50:13 +08:00 committed by Michael Crosby
parent b0fbd0591a
commit 2c3949a687
3 changed files with 4 additions and 1 deletions

View File

@ -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) return fmt.Errorf("failed to parse memory.usage_in_bytes - %v", err)
} }
stats.MemoryStats.Usage = value stats.MemoryStats.Usage = value
stats.MemoryStats.Cache = stats.MemoryStats.Stats["cache"]
value, err = getCgroupParamUint(path, "memory.max_usage_in_bytes") value, err = getCgroupParamUint(path, "memory.max_usage_in_bytes")
if err != nil { if err != nil {
return fmt.Errorf("failed to parse memory.max_usage_in_bytes - %v", err) return fmt.Errorf("failed to parse memory.max_usage_in_bytes - %v", err)

View File

@ -128,7 +128,7 @@ func TestMemoryStats(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) 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) expectMemoryStatEquals(t, expectedStats, actualStats.MemoryStats)
} }

View File

@ -33,6 +33,8 @@ type CpuStats struct {
type MemoryStats struct { type MemoryStats struct {
// current res_counter usage for memory // current res_counter usage for memory
Usage uint64 `json:"usage,omitempty"` Usage uint64 `json:"usage,omitempty"`
// memory used for cache
Cache uint64 `json:"cache,omitempty"`
// maximum usage ever recorded. // maximum usage ever recorded.
MaxUsage uint64 `json:"max_usage,omitempty"` MaxUsage uint64 `json:"max_usage,omitempty"`
// TODO(vishh): Export these as stronger types. // TODO(vishh): Export these as stronger types.