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: return total system memory if the memory limit is not specified #265

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ningziwen
Copy link

Signed-off-by: Ziwen Ning [email protected]

containerd/nerdctl#1589

go.mod Outdated
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/shirou/gopsutil v2.21.11+incompatible // indirect
Copy link
Member

Choose a reason for hiding this comment

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

gopsutil is a direct dependency so should be in the first require clause; go mod tidy should have put this in the correct place in go.mod; either way, that is why the CI project check failed.

go.mod Outdated
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/shirou/gopsutil v2.21.11+incompatible // indirect
Copy link
Member

Choose a reason for hiding this comment

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

gopsutil is a direct dependency so should be in the first require clause; go mod tidy should have put this in the correct place in go.mod; either way, that is why the CI project check failed.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks! Fixed. I'm still figuring out how to test it and how to fix v1 so it is in draft.

@ningziwen ningziwen force-pushed the mem branch 3 times, most recently from c53d623 to 37c15a2 Compare January 5, 2023 04:28
Signed-off-by: Ziwen Ning <[email protected]>
@@ -8,15 +8,22 @@ require (
github.com/docker/go-units v0.4.0
github.com/godbus/dbus/v5 v5.0.4
github.com/opencontainers/runtime-spec v1.0.2
github.com/shirou/gopsutil/v3 v3.22.12
Copy link
Member

@kzys kzys Jan 10, 2023

Choose a reason for hiding this comment

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

Is it hard to implement by ourselves? cgroups is Linux-only whereas gopsutil supports other OSes and brings a bunch of dependencies.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah I can implement it without adding gopsutil.

@kzys
Copy link
Member

kzys commented Jan 13, 2023

  1. I prefer to not have this type of Do What I Mean behavior in low-level packages. There may be customers who want to check whether the limit is configured or not. The current behavior (returning MaxUint64) may not be the best, but the new behavior is even harder for them.
  2. There are other limits we can set on cgroups (see https://github.com/containerd/cgroups/search?q=limit). Would we do the same for others?

@ningziwen
Copy link
Author

ningziwen commented Feb 5, 2023

  1. I prefer to not have this type of Do What I Mean behavior in low-level packages. There may be customers who want to check whether the limit is configured or not. The current behavior (returning MaxUint64) may not be the best, but the new behavior is even harder for them.
  2. There are other limits we can set on cgroups (see https://github.com/containerd/cgroups/search?q=limit). Would we do the same for others?

@kzys

If we change this in containerd, there is not a perfect way to check if the memory is configured. Returning Math.max memory can not only mean the memory is not configured, it can also mean the memory is really set to Math.max (that may be not possible today but may cause issue one day later). Do you think it is ok to use Math.max to check in containerd?

Similarily, if other consumers are using Math.max to judge if the memory is configured, they are currently having same defects.

So there are a few options below:

Option 1 transfer from Math.max to host memory limit in containerd and keep cgroup same.

Pros:

  • lowest risk to impact other consumers of cgroup

Cons:

  • not perfectly logical to use Math.max to check if memory is configured in containerd, and other cgroup consuemrs. May cause issues in the future.

Option 2 Change default memory limit to host memory limit.
Pros:

  • Consumers don't have to handle the default memory limit overwriting.

Cons:

  • May break existing consumer's workflow.

Option 3 Change default memory limit to NA in cgroup layer. Containerd and other consumers can transfer to NA to whatever they want (such as host memory limit).

Pros:

  • Consumer's conditional check will be logical.

Cons:

  • May break existing consumer's workflow.

Option 4 Keep cgroup same. Do some refactoring to add additional response field to tell the consumers that the memory limit is not configured. Containerd and other consumers can overwrite the memory limit to whatever they want when the memory limit is not configured

Pros:

  • Won't break any consumers.
  • Consumer's conditional check will be logical.

Cons:

  • Cgroup will need to return an additional field in the Stat() response.

Considering option 2 is not preferred, I'm slightly leaning to Option 4. We can just add a field around here to show if the memory limit is configured.

UsageLimit uint64 `protobuf:"varint,33,opt,name=usage_limit,json=usageLimit,proto3" json:"usage_limit,omitempty"`

(Similar for cgroup v1)

For the second question, I think we can apply the same option for other limits to keep them consistent.

Let me know if you have better ideas.

@dcantah
Copy link
Member

dcantah commented Feb 6, 2023

I'll give some thought to what might make sense to return here as well, but for the introduction of the new dependency it really should not be needed. It just reads /proc/meminfo, splits by line and then we just need the MemTotal section:

dcantah@dcantah ~ $ cat /proc/meminfo
MemTotal:       16338456 kB
MemFree:         5120496 kB
MemAvailable:   11223128 kB
Buffers:          889596 kB
... omitted for brevity

@ningziwen ningziwen requested a review from kzys February 10, 2023 06:12
@kzys
Copy link
Member

kzys commented Feb 10, 2023

I like Option 1 or Option 4.

@AkihiroSuda What do you think?

@ningziwen
Copy link
Author

@AkihiroSuda WDYT?

@AkihiroSuda
Copy link
Member

Returning Math.max memory can not only mean the memory is not configured, it can also mean the memory is really set to Math.max (that may be not possible today but may cause issue one day later). Do you think it is ok to use Math.max to check in containerd?

I think this is fine.
Nobody will actually set the cgroup memory limit to 16EB until the ecosystem migrates to an 128-bit arch with >= 64-bit physical address bus, which isn’t realistic in this century.

@AkihiroSuda
Copy link
Member

But I agree Option 4 looks better

@AkihiroSuda
Copy link
Member

We can just add a field around here to show if the memory limit is configured.

Can we just use zero or nil value to indicate that without adding a new field?

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.

5 participants