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

fix: nerdctl stats on containers without a memory limit returns host memory limit #3369

Merged
merged 1 commit into from
Oct 15, 2024

Conversation

cezar-r
Copy link
Contributor

@cezar-r cezar-r commented Aug 26, 2024

Fix: runfinch/finch#45

  • Fixed bug where nerdctl stats would show 16 exbibytes of memory limit when memory limit on container was not set.

go.mod Outdated
github.com/containerd/stargz-snapshotter v0.15.2-0.20240709063920-1dac5ef89319
github.com/containerd/stargz-snapshotter/estargz v0.15.2-0.20240709063920-1dac5ef89319
github.com/containerd/stargz-snapshotter/ipfs v0.15.2-0.20240709063920-1dac5ef89319
github.com/containerd/stargz-snapshotter v0.15.2-0.20240826180748-fbc3f6a1d4aa
Copy link
Contributor

Choose a reason for hiding this comment

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

avoid updating hash for unrelated things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These changes occurred after running go mod tidy, which I needed to run after adding the gopsutil package. Let me see how I can work around this

Copy link
Contributor

Choose a reason for hiding this comment

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

probably is fine

Copy link
Contributor

Choose a reason for hiding this comment

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

Tried it, and go mod tidy did not up these dependencies.
Maybe you did go get -u somehow?
Anyhow, I don't think we should touch these at this time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in latest push

@@ -73,6 +72,27 @@ func SetCgroup2StatsFields(previousStats *ContainerStats, metrics *v2.Metrics, l

}

func getMemLimit(metrics *v1.Metrics) float64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

getCgroupMemLimit

return memLimit
}

func getMemLimit2(metrics *v2.Metrics) float64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

getCgroup2MemLimit

}

func getHostMemoryLimit() uint64 {
virtualMemLimit, _ := mem.VirtualMemory()
Copy link
Contributor

Choose a reason for hiding this comment

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

why virtual memory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Followed their documentation - https://github.com/shirou/gopsutil?tab=readme-ov-file#usage
I didn't catch any other relevant methods

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah seems its called virtualmemory

go.mod Outdated
@@ -59,6 +59,7 @@ require (
github.com/pelletier/go-toml/v2 v2.2.3
github.com/rootless-containers/bypass4netns v0.4.1
github.com/rootless-containers/rootlesskit/v2 v2.3.1
github.com/shirou/gopsutil/v3 v3.24.5
Copy link
Contributor

Choose a reason for hiding this comment

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

hey @cezar-r - is there a reason to not use /v4?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the recommended version that was prompted by Go and I was having some issues with v4 as well in go.sum but I can re-evaluate if needed @apostasie

Copy link
Contributor

Choose a reason for hiding this comment

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

My concern is that v3 will drop out of support soon. Back in May: v3 will not be updated except for high level security issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, updated it to v4 in latest push

@cezar-r cezar-r marked this pull request as ready for review August 27, 2024 17:14
@cezar-r cezar-r force-pushed the stats-bug branch 6 times, most recently from 6e1679a to 9469eb3 Compare August 28, 2024 18:42
go.mod Outdated
@@ -59,6 +59,7 @@ require (
github.com/pelletier/go-toml/v2 v2.2.3
github.com/rootless-containers/bypass4netns v0.4.1
github.com/rootless-containers/rootlesskit/v2 v2.3.1
github.com/shirou/gopsutil/v4 v4.24.7
Copy link
Member

Choose a reason for hiding this comment

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

This seems to introduce a bunch of other deps that should not be necessary for fixing the issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, will explore other options

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

@cezar-r cezar-r marked this pull request as draft September 19, 2024 20:25
@cezar-r cezar-r force-pushed the stats-bug branch 2 times, most recently from e40e14f to 87686d0 Compare September 19, 2024 20:31
@cezar-r
Copy link
Contributor Author

cezar-r commented Sep 19, 2024

This seems to introduce a bunch of other deps that should not be necessary for fixing the issue

Apologies for the delay, the latest commit implements the fix without the need for other deps.

I do want to note; it seems like there was a discussion upstream in the containerd cgroups package relating to this issue (containerd/cgroups#265) that never got resolved. Is there alignment for the one of 4 options from that discussion? Should this fix even be implemented in this package or should it be in containerd?

Let me know your thoughts @AkihiroSuda

@AkihiroSuda
Copy link
Member

Should this fix even be implemented in this package or should it be in containerd?

This package

@Shubhranshu153
Copy link
Contributor

@AkihiroSuda

Following this discussion:
is the recommendation to have config value (via os environment or config.json irrespective) that users can configure and return the value and if not then return not configured/nil (option 4)

If not configured:
should we return the system max value, as that what docker seems to return and people trying to integrate with systems which were based on docker might want this to return max system limit of the current system. We probably can do it in finch under dockercompat flags, but feels like the right place for it is nerdctl.

Thanks

@AkihiroSuda
Copy link
Member

AFAICS I don't think this has to be configurable. It should just follow Docker's behavior.

@Shubhranshu153
Copy link
Contributor

Thanks @AkihiroSuda
In that case we can return the max system limit of the current system: (this is from a 15.26 GB system)

% grep MemTotal /proc/meminfo
MemTotal:       16004064 kB
CONTAINER ID   NAME            CPU %     MEM USAGE / LIMIT   MEM %     NET I/O     BLOCK I/O   PIDS
2b07ca5e9b88   goofy_khorana   0.00%     276KiB / 15.26GiB   0.00%     720B / 0B   0B / 0B     1

… memory limit

Signed-off-by: Cezar Rata <[email protected]>

Signed-off-by: Cezar Rata <[email protected]>

Signed-off-by: Cezar Rata <[email protected]>

Signed-off-by: Cezar Rata <[email protected]>
@cezar-r cezar-r marked this pull request as ready for review October 14, 2024 22:21
@cezar-r
Copy link
Contributor Author

cezar-r commented Oct 14, 2024

Reopened the PR as it seems the implementation is aligned with what we need

@AkihiroSuda AkihiroSuda added this to the v2.0.0 milestone Oct 15, 2024
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda AkihiroSuda merged commit 380d703 into containerd:main Oct 15, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

finch stats on a container without a memory limit reports 16 exbibytes
4 participants