Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calculateMemUsageUnixNoCache: subtract total_inactive_file, not cache #2415

Merged
merged 1 commit into from
Apr 10, 2020

Conversation

AkihiroSuda
Copy link
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
Copy link
Collaborator Author

CI failure is unrelated: #2412

@thaJeztah
Copy link
Member

Previous change related to was #80

Copy link
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
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
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
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
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
Member

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

@AkihiroSuda
Copy link
Collaborator Author

rebased

@thaJeztah
Copy link
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