-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 ulimit issue #18721
fix ulimit issue #18721
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
//go:build freebsd | ||
// +build freebsd | ||
|
||
package generate | ||
package libpod | ||
|
||
type rlimT int64 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
//go:build linux || darwin | ||
// +build linux darwin | ||
|
||
package generate | ||
package libpod | ||
|
||
type rlimT uint64 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,72 +7,17 @@ import ( | |
"github.com/containers/common/libimage" | ||
"github.com/containers/common/pkg/config" | ||
"github.com/containers/podman/v4/libpod/define" | ||
"github.com/containers/podman/v4/pkg/rootless" | ||
"github.com/containers/podman/v4/pkg/specgen" | ||
"github.com/opencontainers/runtime-tools/generate" | ||
"github.com/sirupsen/logrus" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func addRlimits(s *specgen.SpecGenerator, g *generate.Generator) { | ||
var ( | ||
isRootless = rootless.IsRootless() | ||
nofileSet = false | ||
nprocSet = false | ||
) | ||
|
||
if s.Rlimits == nil { | ||
g.Config.Process.Rlimits = nil | ||
return | ||
} | ||
g.Config.Process.Rlimits = nil | ||
|
||
for _, u := range s.Rlimits { | ||
name := "RLIMIT_" + strings.ToUpper(u.Type) | ||
if name == "RLIMIT_NOFILE" { | ||
nofileSet = true | ||
} else if name == "RLIMIT_NPROC" { | ||
nprocSet = true | ||
} | ||
g.AddProcessRlimits(name, u.Hard, u.Soft) | ||
} | ||
|
||
// If not explicitly overridden by the user, default number of open | ||
// files and number of processes to the maximum they can be set to | ||
// (without overriding a sysctl) | ||
if !nofileSet { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am pretty sure we actually want this. The problem is that we only set it once on create instead of for each start. So I think this must be moved into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a problem with leaving the ulimits in the spec file empty? The container process should inherit the limits, right? Is that generateSpec invoked on each run and the spec passed to crun, or is it also saved on disk for the next time the container is started? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, so I'll also disable the new test for rootfull, as this issue is not really applicable to rootfull. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this approach works on my end. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorporated into latest version of this PR |
||
max := rlimT(define.RLimitDefaultValue) | ||
current := rlimT(define.RLimitDefaultValue) | ||
if isRootless { | ||
var rlimit unix.Rlimit | ||
if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rlimit); err != nil { | ||
logrus.Warnf("Failed to return RLIMIT_NOFILE ulimit %q", err) | ||
} | ||
if rlimT(rlimit.Cur) < current { | ||
current = rlimT(rlimit.Cur) | ||
} | ||
if rlimT(rlimit.Max) < max { | ||
max = rlimT(rlimit.Max) | ||
} | ||
} | ||
g.AddProcessRlimits("RLIMIT_NOFILE", uint64(max), uint64(current)) | ||
} | ||
if !nprocSet { | ||
max := rlimT(define.RLimitDefaultValue) | ||
current := rlimT(define.RLimitDefaultValue) | ||
if isRootless { | ||
var rlimit unix.Rlimit | ||
if err := unix.Getrlimit(unix.RLIMIT_NPROC, &rlimit); err != nil { | ||
logrus.Warnf("Failed to return RLIMIT_NPROC ulimit %q", err) | ||
} | ||
if rlimT(rlimit.Cur) < current { | ||
current = rlimT(rlimit.Cur) | ||
} | ||
if rlimT(rlimit.Max) < max { | ||
max = rlimT(rlimit.Max) | ||
} | ||
} | ||
g.AddProcessRlimits("RLIMIT_NPROC", uint64(max), uint64(current)) | ||
} | ||
} | ||
|
||
// Produce the final command for the container. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove this? This sets the limit based on containers.conf defaults so we need to keep it. Although doing this in Validate() looks wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm under the impression that it's already set by
podman/pkg/specgenutil/specgen.go
Line 771 in 77bd041
Doing a quick test it looks like a ulimit from containers.conf still makes it into a container, so this was redundant. However it's in there twice right now. So I think the containers.conf defaults also make it to:
podman/pkg/specgen/generate/container_create.go
Line 34 in 77bd041
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue with the limits being in the list twice is fixed.