Skip to content

Commit 11ab047

Browse files
committed
Revert "only prioritize ourselves"
This reverts commit 5020eb4.
1 parent 5020eb4 commit 11ab047

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

agent/agent.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ type Options struct {
7979
ModifiedProcesses chan []*agentproc.Process
8080
// ProcessManagementTick is used for testing process priority management.
8181
ProcessManagementTick <-chan time.Time
82-
// PrioritizedPIDs are processes that should have preferred CPU allocation
83-
// and be de-prioritized for OOM Killer selection.
84-
PrioritizedPIDs []int
8582
}
8683

8784
type Client interface {
@@ -164,7 +161,6 @@ func New(options Options) Agent {
164161
syscaller: options.Syscaller,
165162
modifiedProcs: options.ModifiedProcesses,
166163
processManagementTick: options.ProcessManagementTick,
167-
prioritizedPIDs: options.PrioritizedPIDs,
168164

169165
prometheusRegistry: prometheusRegistry,
170166
metrics: newAgentMetrics(prometheusRegistry),
@@ -225,9 +221,6 @@ type agent struct {
225221
modifiedProcs chan []*agentproc.Process
226222
// processManagementTick is used for testing process priority management.
227223
processManagementTick <-chan time.Time
228-
// prioritizedPIDs are processes that should have preferred CPU allocation
229-
// and be de-prioritized for OOM Killer selection.
230-
prioritizedPIDs []int
231224
}
232225

233226
func (a *agent) TailnetConn() *tailnet.Conn {
@@ -1285,6 +1278,8 @@ func (a *agent) startReportingConnectionStats(ctx context.Context) {
12851278
}
12861279
}
12871280

1281+
var prioritizedProcs = []string{"coder"}
1282+
12881283
func (a *agent) manageProcessPriorityLoop(ctx context.Context) {
12891284
if val := a.envVars[EnvProcPrioMgmt]; val == "" || runtime.GOOS != "linux" {
12901285
a.logger.Debug(ctx, "process priority not enabled, agent will not manage process niceness/oom_score_adj ",
@@ -1342,9 +1337,11 @@ func (a *agent) manageProcessPriority(ctx context.Context) ([]*agentproc.Process
13421337
slog.F("pid", proc.PID),
13431338
)
13441339

1340+
// Trim off the path e.g. "./coder" -> "coder"
1341+
name := filepath.Base(proc.Name())
13451342
// If the process is prioritized we should adjust
13461343
// it's oom_score_adj and avoid lowering its niceness.
1347-
if slices.Contains(a.prioritizedPIDs, int(proc.PID)) {
1344+
if slices.Contains(prioritizedProcs, name) {
13481345
err = proc.SetOOMAdj(oomScoreAdj)
13491346
if err != nil {
13501347
logger.Warn(ctx, "unable to set proc oom_score_adj",

agent/agent_test.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,13 +2411,12 @@ func TestAgent_ManageProcessPriority(t *testing.T) {
24112411
}
24122412

24132413
var (
2414-
expectedProcs = map[int32]agentproc.Process{}
2415-
fs = afero.NewMemMapFs()
2416-
syscaller = agentproctest.NewMockSyscaller(gomock.NewController(t))
2417-
ticker = make(chan time.Time)
2418-
modProcs = make(chan []*agentproc.Process)
2419-
logger = slog.Make(sloghuman.Sink(io.Discard))
2420-
prioritizedProc = 123
2414+
expectedProcs = map[int32]agentproc.Process{}
2415+
fs = afero.NewMemMapFs()
2416+
syscaller = agentproctest.NewMockSyscaller(gomock.NewController(t))
2417+
ticker = make(chan time.Time)
2418+
modProcs = make(chan []*agentproc.Process)
2419+
logger = slog.Make(sloghuman.Sink(io.Discard))
24212420
)
24222421

24232422
// Create some processes.
@@ -2430,15 +2429,12 @@ func TestAgent_ManageProcessPriority(t *testing.T) {
24302429
proc = agentproctest.GenerateProcess(t, fs,
24312430
func(p *agentproc.Process) {
24322431
p.CmdLine = "./coder\x00agent\x00--no-reap"
2433-
p.PID = int32(prioritizedProc)
2432+
p.PID = 1
24342433
},
24352434
)
24362435
} else {
24372436
// The rest are peasants.
24382437
proc = agentproctest.GenerateProcess(t, fs)
2439-
if proc.PID == int32(prioritizedProc) {
2440-
proc.PID = 1234
2441-
}
24422438
syscaller.EXPECT().SetPriority(proc.PID, 10).Return(nil)
24432439
syscaller.EXPECT().GetPriority(proc.PID).Return(20, nil)
24442440
}
@@ -2456,7 +2452,6 @@ func TestAgent_ManageProcessPriority(t *testing.T) {
24562452
o.Filesystem = fs
24572453
o.Logger = logger
24582454
o.ProcessManagementTick = ticker
2459-
o.PrioritizedPIDs = []int{prioritizedProc}
24602455
})
24612456
actualProcs := <-modProcs
24622457
require.Len(t, actualProcs, 4)
@@ -2465,7 +2460,7 @@ func TestAgent_ManageProcessPriority(t *testing.T) {
24652460
expectedScore := "0"
24662461
expected, ok := expectedProcs[actual.PID]
24672462
require.True(t, ok)
2468-
if expected.PID == int32(prioritizedProc) {
2463+
if expected.PID == 1 {
24692464
expectedScore = "-500"
24702465
}
24712466

cli/agent.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
299299
// Intentionally set this to nil. It's mainly used
300300
// for testing.
301301
ModifiedProcesses: nil,
302-
PrioritizedPIDs: []int{os.Getpid()},
303302
})
304303

305304
prometheusSrvClose := ServeHandler(ctx, logger, prometheusMetricsHandler(prometheusRegistry, logger), prometheusAddress, "prometheus")

0 commit comments

Comments
 (0)