Skip to content

Commit d132480

Browse files
committed
remove oom_score_adj
1 parent 46ef05a commit d132480

File tree

8 files changed

+3
-237
lines changed

8 files changed

+3
-237
lines changed

agent/agent.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,8 +1327,7 @@ func (a *agent) manageProcessPriorityLoop(ctx context.Context) {
13271327

13281328
func (a *agent) manageProcessPriority(ctx context.Context) ([]*agentproc.Process, error) {
13291329
const (
1330-
niceness = 10
1331-
oomScoreAdj = -500
1330+
niceness = 10
13321331
)
13331332

13341333
procs, err := agentproc.List(a.filesystem, a.syscaller)
@@ -1351,18 +1350,10 @@ func (a *agent) manageProcessPriority(ctx context.Context) ([]*agentproc.Process
13511350
contains := strings.Contains(proc.Cmd(), e)
13521351
return contains
13531352
}
1353+
13541354
// If the process is prioritized we should adjust
13551355
// it's oom_score_adj and avoid lowering its niceness.
13561356
if slices.ContainsFunc[[]string, string](prioritizedProcs, containsFn) {
1357-
err = proc.SetOOMAdj(oomScoreAdj)
1358-
if err != nil {
1359-
logger.Warn(ctx, "unable to set proc oom_score_adj",
1360-
slog.F("oom_score_adj", oomScoreAdj),
1361-
slog.Error(err),
1362-
)
1363-
continue
1364-
}
1365-
modProcs = append(modProcs, proc)
13661357
continue
13671358
}
13681359

agent/agent_test.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,20 +2460,7 @@ func TestAgent_ManageProcessPriority(t *testing.T) {
24602460
o.ProcessManagementTick = ticker
24612461
})
24622462
actualProcs := <-modProcs
2463-
require.Len(t, actualProcs, 4)
2464-
2465-
for _, actual := range actualProcs {
2466-
expectedScore := "0"
2467-
expected, ok := expectedProcs[actual.PID]
2468-
require.True(t, ok)
2469-
if expected.PID == 0 {
2470-
expectedScore = "-500"
2471-
}
2472-
2473-
score, err := afero.ReadFile(fs, filepath.Join(actual.Dir, "oom_score_adj"))
2474-
require.NoError(t, err)
2475-
require.Equal(t, expectedScore, strings.TrimSpace(string(score)))
2476-
}
2463+
require.Len(t, actualProcs, len(expectedProcs)-1)
24772464
})
24782465

24792466
t.Run("IgnoreCustomNice", func(t *testing.T) {

agent/agentproc/agentproctest/proc.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ func GenerateProcess(t *testing.T, fs afero.Fs, muts ...func(*agentproc.Process)
3131
process := agentproc.Process{
3232
CmdLine: cmdline,
3333
PID: int32(pid),
34-
FS: fs,
3534
}
3635

3736
for _, mut := range muts {
@@ -46,8 +45,5 @@ func GenerateProcess(t *testing.T, fs afero.Fs, muts ...func(*agentproc.Process)
4645
err = afero.WriteFile(fs, fmt.Sprintf("%s/cmdline", process.Dir), []byte(process.CmdLine), 0o444)
4746
require.NoError(t, err)
4847

49-
err = afero.WriteFile(fs, fmt.Sprintf("%s/oom_score_adj", process.Dir), []byte("0"), 0o444)
50-
require.NoError(t, err)
51-
5248
return process
5349
}

agent/agentproc/proc_other.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ import (
77
"github.com/spf13/afero"
88
)
99

10-
func (p *Process) SetOOMAdj(score int) error {
11-
return errUnimplemented
12-
}
13-
1410
func (p *Process) Niceness(sc Syscaller) (int, error) {
1511
return 0, errUnimplemented
1612
}

agent/agentproc/proc_test.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package agentproc_test
22

33
import (
4-
"fmt"
54
"runtime"
6-
"strings"
75
"syscall"
86
"testing"
97

@@ -137,23 +135,6 @@ func TestProcess(t *testing.T) {
137135
t.Skipf("skipping non-linux environment")
138136
}
139137

140-
t.Run("SetOOMAdj", func(t *testing.T) {
141-
t.Parallel()
142-
143-
var (
144-
fs = afero.NewMemMapFs()
145-
proc = agentproctest.GenerateProcess(t, fs)
146-
expectedScore = -1000
147-
)
148-
149-
err := proc.SetOOMAdj(expectedScore)
150-
require.NoError(t, err)
151-
152-
actualScore, err := afero.ReadFile(fs, fmt.Sprintf("/proc/%d/oom_score_adj", proc.PID))
153-
require.NoError(t, err)
154-
require.Equal(t, fmt.Sprintf("%d", expectedScore), strings.TrimSpace(string(actualScore)))
155-
})
156-
157138
t.Run("SetNiceness", func(t *testing.T) {
158139
t.Parallel()
159140

agent/agentproc/proc_unix.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ func List(fs afero.Fs, syscaller Syscaller) ([]*Process, error) {
5454
PID: int32(pid),
5555
CmdLine: string(cmdline),
5656
Dir: filepath.Join(defaultProcDir, entry),
57-
FS: fs,
5857
})
5958
}
6059

@@ -85,20 +84,6 @@ func isProcessExist(syscaller Syscaller, pid int32) (bool, error) {
8584
return false, xerrors.Errorf("kill: %w", err)
8685
}
8786

88-
func (p *Process) SetOOMAdj(score int) error {
89-
path := filepath.Join(p.Dir, "oom_score_adj")
90-
err := afero.WriteFile(p.FS,
91-
path,
92-
[]byte(strconv.Itoa(score)),
93-
0o644,
94-
)
95-
if err != nil {
96-
return xerrors.Errorf("write %q: %w", path, err)
97-
}
98-
99-
return nil
100-
}
101-
10287
func (p *Process) Niceness(sc Syscaller) (int, error) {
10388
nice, err := sc.GetPriority(p.PID)
10489
if err != nil {

agent/agentproc/syscaller.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package agentproc
22

33
import (
44
"syscall"
5-
6-
"github.com/spf13/afero"
75
)
86

97
type Syscaller interface {
@@ -18,5 +16,4 @@ type Process struct {
1816
Dir string
1917
CmdLine string
2018
PID int32
21-
FS afero.Fs
2219
}

agent/out.txt

Lines changed: 0 additions & 167 deletions
This file was deleted.

0 commit comments

Comments
 (0)