MCPcopy
hub / github.com/NVIDIA/aistore / container

Method container

sys/mem_linux.go:84–119  ·  view source on GitHub ↗

Returns host stats if memory is not limited via cgroups "memory.limit_in_bytes".

()

Source from the content-addressed store, hash-verified

82
83// Returns host stats if memory is not limited via cgroups "memory.limit_in_bytes".
84func (mem *MemStat) container() error {
85 if err := mem.host(); err != nil {
86 return err
87 }
88 memLimit, err := cos.ReadOneUint64(contMemLimitPath)
89 if err != nil {
90 return nil
91 }
92 // It is safe to assume that the value greater than MaxInt64/2 indicates "no limit"
93 // https://unix.stackexchange.com/questions/420906/what-is-the-value-for-the-cgroups-limit-in-bytes-if-the-memory-is-not-restricte
94 if memLimit > math.MaxInt64/2 {
95 return nil
96 }
97
98 // this one is an approximate value that includes buff/cache
99 // (ie., kernel buffers and page caches that can be reclaimed)
100 memUsed, err := cos.ReadOneUint64(contMemUsedPath)
101 if err != nil {
102 return nil
103 }
104 mem.Total = memLimit
105 mem.Used = memUsed
106 mem.Free = mem.Total - mem.Used
107
108 // calculate memory used for buffcache
109 err = cos.ReadLines(contMemStatPath, mem.cgroupParse)
110 if err != nil {
111 debug.AssertNoErr(err)
112 // NOTE: returning host memory
113 return nil
114 }
115
116 mem.ActualUsed = memUsed - mem.BuffCache
117 mem.ActualFree = mem.Total - mem.ActualUsed
118 return nil
119}

Callers 2

GetMethod · 0.95
TestMemoryStatsFunction · 0.95

Calls 4

hostMethod · 0.95
ReadOneUint64Function · 0.92
ReadLinesFunction · 0.92
AssertNoErrFunction · 0.92

Tested by 1

TestMemoryStatsFunction · 0.76