Skip to content

Commit 5559a45

Browse files
authored
Merge pull request #1139 from tonistiigi/oomscoreadj
runcexecutor: avoid setting oomscoreadj from main process
2 parents c16bf8f + 25ebc26 commit 5559a45

1 file changed

Lines changed: 6 additions & 24 deletions

File tree

executor/runcexecutor/executor.go

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import (
44
"context"
55
"encoding/json"
66
"io"
7-
"io/ioutil"
87
"os"
98
"os/exec"
109
"path/filepath"
11-
"strconv"
1210
"strings"
1311
"syscall"
1412
"time"
@@ -25,7 +23,6 @@ import (
2523
"github.com/moby/buildkit/solver/pb"
2624
"github.com/moby/buildkit/util/network"
2725
rootlessspecconv "github.com/moby/buildkit/util/rootless/specconv"
28-
specs "github.com/opencontainers/runtime-spec/specs-go"
2926
"github.com/pkg/errors"
3027
"github.com/sirupsen/logrus"
3128
)
@@ -42,8 +39,9 @@ type Opt struct {
4239
ProcessMode oci.ProcessMode
4340
IdentityMapping *idtools.IdentityMapping
4441
// runc run --no-pivot (unrecommended)
45-
NoPivot bool
46-
DNS *oci.DNSConfig
42+
NoPivot bool
43+
DNS *oci.DNSConfig
44+
OOMScoreAdj *int
4745
}
4846

4947
var defaultCommandCandidates = []string{"buildkit-runc", "runc"}
@@ -59,6 +57,7 @@ type runcExecutor struct {
5957
idmap *idtools.IdentityMapping
6058
noPivot bool
6159
dns *oci.DNSConfig
60+
oomScoreAdj *int
6261
}
6362

6463
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
118117
idmap: opt.IdentityMapping,
119118
noPivot: opt.NoPivot,
120119
dns: opt.DNS,
120+
oomScoreAdj: opt.OOMScoreAdj,
121121
}
122122
return w, nil
123123
}
@@ -244,9 +244,7 @@ func (w *runcExecutor) Exec(ctx context.Context, meta executor.Meta, root cache.
244244
}
245245
}
246246

247-
if err := setOOMScoreAdj(spec); err != nil {
248-
return err
249-
}
247+
spec.Process.OOMScoreAdj = w.oomScoreAdj
250248
if w.rootless {
251249
if err := rootlessspecconv.ToRootless(spec); err != nil {
252250
return err
@@ -338,19 +336,3 @@ func (s *forwardIO) Stdout() io.ReadCloser {
338336
func (s *forwardIO) Stderr() io.ReadCloser {
339337
return nil
340338
}
341-
342-
// setOOMScoreAdj comes from https://github.com/genuinetools/img/blob/2fabe60b7dc4623aa392b515e013bbc69ad510ab/executor/runc/executor.go#L182-L192
343-
func setOOMScoreAdj(spec *specs.Spec) error {
344-
// Set the oom_score_adj of our children containers to that of the current process.
345-
b, err := ioutil.ReadFile("/proc/self/oom_score_adj")
346-
if err != nil {
347-
return errors.Wrap(err, "failed to read /proc/self/oom_score_adj")
348-
}
349-
s := strings.TrimSpace(string(b))
350-
oom, err := strconv.Atoi(s)
351-
if err != nil {
352-
return errors.Wrapf(err, "failed to parse %s as int", s)
353-
}
354-
spec.Process.OOMScoreAdj = &oom
355-
return nil
356-
}

0 commit comments

Comments
 (0)