MCPcopy Index your code
hub / github.com/docker/cli / calculateMemUsageUnixNoCache

Function calculateMemUsageUnixNoCache

cli/command/container/stats_helpers.go:254–264  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
254func 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
266func calculateMemPercentUnixNoCache(limit float64, usedNoCache float64) float64 {
267 // MemoryStats.Limit will never be 0 unless the container is not running and we haven't

Callers 2

collectFunction · 0.85

Calls

no outgoing calls

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…