From 25ebc26d216c4b0bb80691a660b85f4a3656510d Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 15 Aug 2019 22:53:54 -0700 Subject: [PATCH] runcexecutor: avoid setting oomscoreadj from main process Signed-off-by: Tonis Tiigi --- executor/runcexecutor/executor.go | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/executor/runcexecutor/executor.go b/executor/runcexecutor/executor.go index 7434409d..1875c261 100644 --- a/executor/runcexecutor/executor.go +++ b/executor/runcexecutor/executor.go @@ -4,11 +4,9 @@ import ( "context" "encoding/json" "io" - "io/ioutil" "os" "os/exec" "path/filepath" - "strconv" "strings" "syscall" "time" @@ -25,7 +23,6 @@ import ( "github.com/moby/buildkit/solver/pb" "github.com/moby/buildkit/util/network" rootlessspecconv "github.com/moby/buildkit/util/rootless/specconv" - specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -42,8 +39,9 @@ type Opt struct { ProcessMode oci.ProcessMode IdentityMapping *idtools.IdentityMapping // runc run --no-pivot (unrecommended) - NoPivot bool - DNS *oci.DNSConfig + NoPivot bool + DNS *oci.DNSConfig + OOMScoreAdj *int } var defaultCommandCandidates = []string{"buildkit-runc", "runc"} @@ -59,6 +57,7 @@ type runcExecutor struct { idmap *idtools.IdentityMapping noPivot bool dns *oci.DNSConfig + oomScoreAdj *int } func New(opt Opt, networkProviders map[pb.NetMode]network.Provider) (executor.Executor, error) { @@ -118,6 +117,7 @@ func New(opt Opt, networkProviders map[pb.NetMode]network.Provider) (executor.Ex idmap: opt.IdentityMapping, noPivot: opt.NoPivot, dns: opt.DNS, + oomScoreAdj: opt.OOMScoreAdj, } return w, nil } @@ -242,9 +242,7 @@ func (w *runcExecutor) Exec(ctx context.Context, meta executor.Meta, root cache. } } - if err := setOOMScoreAdj(spec); err != nil { - return err - } + spec.Process.OOMScoreAdj = w.oomScoreAdj if w.rootless { if err := rootlessspecconv.ToRootless(spec); err != nil { return err @@ -336,19 +334,3 @@ func (s *forwardIO) Stdout() io.ReadCloser { func (s *forwardIO) Stderr() io.ReadCloser { return nil } - -// setOOMScoreAdj comes from https://github.com/genuinetools/img/blob/2fabe60b7dc4623aa392b515e013bbc69ad510ab/executor/runc/executor.go#L182-L192 -func setOOMScoreAdj(spec *specs.Spec) error { - // Set the oom_score_adj of our children containers to that of the current process. - b, err := ioutil.ReadFile("/proc/self/oom_score_adj") - if err != nil { - return errors.Wrap(err, "failed to read /proc/self/oom_score_adj") - } - s := strings.TrimSpace(string(b)) - oom, err := strconv.Atoi(s) - if err != nil { - return errors.Wrapf(err, "failed to parse %s as int", s) - } - spec.Process.OOMScoreAdj = &oom - return nil -}