calculateMemUsageUnixNoCache calculate memory usage of the container. Cache is intentionally excluded to avoid misinterpretation of the output. On cgroup v1 host, the result is `mem.Usage - mem.Stats["total_inactive_file"]` . On cgroup v2 host, the result is `mem.Usage - mem.Stats["inactive_file"]
(mem container.MemoryStats)
| 252 | // On Docker 19.03 and older, the result was `mem.Usage - mem.Stats["cache"]`. |
| 253 | // See https://github.com/moby/moby/issues/40727 for the background. |
| 254 | func calculateMemUsageUnixNoCache(mem container.MemoryStats) float64 { |
| 255 | // cgroup v1 |
| 256 | if v, isCgroup1 := mem.Stats["total_inactive_file"]; isCgroup1 && v < mem.Usage { |
| 257 | return float64(mem.Usage - v) |
| 258 | } |
| 259 | // cgroup v2 |
| 260 | if v := mem.Stats["inactive_file"]; v < mem.Usage { |
| 261 | return float64(mem.Usage - v) |
| 262 | } |
| 263 | return float64(mem.Usage) |
| 264 | } |
| 265 | |
| 266 | func calculateMemPercentUnixNoCache(limit float64, usedNoCache float64) float64 { |
| 267 | // MemoryStats.Limit will never be 0 unless the container is not running and we haven't |
no outgoing calls
searching dependent graphs…