close
Skip to content

calculateMemUsageUnixNoCache: subtract total_inactive_file, not cache#2415

Merged
thaJeztah merged 1 commit intodocker:masterfrom
AkihiroSuda:stats-memory-cache
Apr 10, 2020
Merged

calculateMemUsageUnixNoCache: subtract total_inactive_file, not cache#2415
thaJeztah merged 1 commit intodocker:masterfrom
AkihiroSuda:stats-memory-cache

Conversation

@AkihiroSuda
Copy link
Copy Markdown
Collaborator

- What I did
Changed mem.Usage - mem.Stats["cache"] in calculateMemUsageUnixNoCache() used by docker stats CLI to mem.Usage - mem.Stats["total_inactive_file"].

Fix moby/moby#40727

- How I did it

The new stat definition corresponds to containerd/CRI and cadvisor.

https://github.com/containerd/cri/blob/c1115d4e57f55a5f45fb3efd29d3181ce26d5c6a/pkg/server/container_stats_list_unix.go#L106-L129
google/cadvisor@307d1b1

- How to verify it
See moby/moby#40727

- Description for the changelog

Changed mem.Usage - mem.Stats["cache"] in calculateMemUsageUnixNoCache() used by docker stats CLI to mem.Usage - mem.Stats["total_inactive_file"].

- A picture of a cute animal (not mandatory but encouraged)
🐧

@AkihiroSuda AkihiroSuda force-pushed the stats-memory-cache branch 2 times, most recently from 15c3d1c to f6ef10b Compare April 3, 2020 21:01
@AkihiroSuda AkihiroSuda requested a review from thaJeztah as a code owner April 3, 2020 21:01
@AkihiroSuda AkihiroSuda force-pushed the stats-memory-cache branch 2 times, most recently from 4e0b583 to e4ac9b1 Compare April 3, 2020 21:06
@AkihiroSuda
Copy link
Copy Markdown
Collaborator Author

CI failure is unrelated: #2412

@thaJeztah
Copy link
Copy Markdown
Member

Previous change related to was #80

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

but pinging @cpuguy83 @crosbymichael @tiborvass for review as well

func calculateMemUsageUnixNoCache(mem types.MemoryStats) float64 {
return float64(mem.Usage - mem.Stats["cache"])
// cgroup v1
if v, isCgroup1 := mem.Stats["total_inactive_file"]; isCgroup1 && v < mem.Usage {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we use this information elsewhere (in the daemon) as well? Just making sure that there's no logic somewhere using the old calculation.

Also /cc @SamWhited (I think UCP does some similar calculations for the UI)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in the daemon AFAIK

Copy link
Copy Markdown
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Collaborator

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I'm not too worried about the CLI reporting slightly different numbers as long as the formula for the calculation is accurate and documented.

@thaJeztah
Copy link
Copy Markdown
Member

@AkihiroSuda can you rebase to make CI go green? I'll merge after that

@AkihiroSuda
Copy link
Copy Markdown
Collaborator Author

rebased

@thaJeztah
Copy link
Copy Markdown
Member

thanks! all green - merging

@thaJeztah thaJeztah merged commit 96e1d1d into docker:master Apr 10, 2020
@thaJeztah thaJeztah added this to the 20.03.0 milestone Apr 19, 2020
LarsMichelsen pushed a commit to Checkmk/checkmk that referenced this pull request Mar 17, 2021
Docker 20.10 changed the way how memory usage of docker containers is
calculated, the docker check was adapted accordingly.

See docker/cli#2415 for more information.

CMK-5224

Change-Id: Ib6c6aa21f61f5cd750209dc3b3bda82041f9d49c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docker stats memory doesn't include tmpfs usage

4 participants