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

config: do not set the default nproc to the max available #2199

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ func defaultConfig() (*Config, error) {
DNSServers: attributedstring.Slice{},
DefaultCapabilities: attributedstring.NewSlice(DefaultCapabilities),
DefaultSysctls: attributedstring.Slice{},
DefaultUlimits: attributedstring.NewSlice(getDefaultProcessLimits()),
Devices: attributedstring.Slice{},
EnableKeyring: true,
EnableLabeling: selinuxEnabled(),
Expand Down
34 changes: 0 additions & 34 deletions pkg/config/default_linux.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,13 @@
package config

import (
"fmt"
"os"
"strconv"
"strings"

"golang.org/x/sys/unix"
)

const (
oldMaxSize = uint64(1048576)
)

func getDefaultCgroupsMode() string {
return "enabled"
}

// getDefaultProcessLimits returns the nproc for the current process in ulimits format
// Note that nfile sometimes cannot be set to unlimited, and the limit is hardcoded
// to (oldMaxSize) 1048576 (2^20), see: http://stackoverflow.com/a/1213069/1811501
// In rootless containers this will fail, and the process will just use its current limits
func getDefaultProcessLimits() []string {
rlim := unix.Rlimit{Cur: oldMaxSize, Max: oldMaxSize}
oldrlim := rlim
// Attempt to set file limit and process limit to pid_max in OS
dat, err := os.ReadFile("/proc/sys/kernel/pid_max")
if err == nil {
val := strings.TrimSuffix(string(dat), "\n")
maxLimit, err := strconv.ParseUint(val, 10, 64)
if err == nil {
rlim = unix.Rlimit{Cur: maxLimit, Max: maxLimit}
}
}
defaultLimits := []string{}
if err := unix.Setrlimit(unix.RLIMIT_NPROC, &rlim); err == nil {
defaultLimits = append(defaultLimits, fmt.Sprintf("nproc=%d:%d", rlim.Cur, rlim.Max))
} else if err := unix.Setrlimit(unix.RLIMIT_NPROC, &oldrlim); err == nil {
defaultLimits = append(defaultLimits, fmt.Sprintf("nproc=%d:%d", oldrlim.Cur, oldrlim.Max))
}
return defaultLimits
}

// getDefaultTmpDir for linux
func getDefaultTmpDir() string {
// first check the TMPDIR env var
Expand Down