8000 Change container workload's default OOM Score by alexmwu · Pull Request #522 · google/go-tpm-tools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Change container workload's default OOM Score #522

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

merged 1 commit into from
Jan 6, 2025
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
13 changes: 13 additions & 0 deletions launcher/container_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ const (
defaultRefreshJitter = 0.1
)

// Default OOM score for a CS container.
const defaultOOMScore = 1000

// NewRunner returns a runner.
func NewRunner(ctx context.Context, cdClient *containerd.Client, token oauth2.Token, launchSpec spec.LaunchSpec, mdsClient *metadata.Client, tpm io.ReadWriteCloser, logger logging.Logger, serialConsole *os.File) (*ContainerRunner, error) {
image, err := initImage(ctx, cdClient, launchSpec, token)
Expand Down Expand Up @@ -163,6 +166,7 @@ func NewRunner(ctx context.Context, cdClient *containerd.Client, token oauth2.To
oci.WithHostNamespace(specs.NetworkNamespace),
oci.WithEnv([]string{fmt.Sprintf("HOSTNAME=%s", hostname)}),
withRlimits(rlimits),
withOOMScoreAdj(defaultOOMScore),
}
if launchSpec.DevShmSize != 0 {
specOpts = append(specOpts, oci.WithDevShmSize(launchSpec.DevShmSize))
Expand All @@ -186,6 +190,7 @@ func NewRunner(ctx context.Context, cdClient *containerd.Client, token oauth2.To
if err != nil {
return nil, &RetryableError{err}
}

// Container process Args length should be strictly longer than the Cmd
// override length set by the operator, as we want the Entrypoint filed
// to be mandatory for the image.
Expand Down Expand Up @@ -743,3 +748,11 @@ func withRlimits(rlimits []specs.POSIXRlimit) oci.SpecOpts {
return nil
}
}

// Set the container process's OOM score.
func withOOMScoreAdj(oomScore int) oci.SpecOpts {
return func(_ context.Context, _ oci.Client, _ *containers.Container, s *oci.Spec) error {
s.Process.OOMScoreAdj = &oomScore
return nil
}
}
2 changes: 1 addition & 1 deletion launcher/launcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func main() {

logger, err = logging.NewLogger(ctx)
if err != nil {
log.Default().Printf("failed to initialize logging")
log.Default().Printf("failed to initialize logging: %v", err)
exitCode = failRC
log.Default().Printf("%s, exit code: %d (%s)\n", exitMessage, exitCode, rcMessage[exitCode])
return
Expand Down
Loading
0