@@ -53,6 +53,8 @@ const (
53
53
ProtocolDial = "dial"
54
54
)
55
55
56
+ // EnvProcMemNice determines whether we attempt to manage
57
+ // process CPU and OOM Killer priority.
56
58
const EnvProcMemNice = "CODER_PROC_MEMNICE_ENABLE"
57
59
58
60
type Options struct {
@@ -73,7 +75,6 @@ type Options struct {
73
75
ReportMetadataInterval time.Duration
74
76
ServiceBannerRefreshInterval time.Duration
75
77
Syscaller agentproc.Syscaller
76
- ProcessManagementTick <- chan time.Time
77
78
ModifiedProcesses chan []* agentproc.Process
78
79
}
79
80
@@ -128,7 +129,7 @@ func New(options Options) Agent {
128
129
}
129
130
130
131
if options .Syscaller == nil {
131
- options .Syscaller = agentproc.UnixSyscaller {}
132
+ options .Syscaller = agentproc .NewSyscaller ()
132
133
}
133
134
134
135
ctx , cancelFunc := context .WithCancel (context .Background ())
@@ -155,7 +156,6 @@ func New(options Options) Agent {
155
156
subsystems : options .Subsystems ,
156
157
addresses : options .Addresses ,
157
158
syscaller : options .Syscaller ,
158
- processManagementTick : options .ProcessManagementTick ,
159
159
modifiedProcs : options .ModifiedProcesses ,
160
160
161
161
prometheusRegistry : prometheusRegistry ,
@@ -209,11 +209,10 @@ type agent struct {
209
209
210
210
connCountReconnectingPTY atomic.Int64
211
211
212
- prometheusRegistry * prometheus.Registry
213
- metrics * agentMetrics
214
- processManagementTick <- chan time.Time
215
- modifiedProcs chan []* agentproc.Process
216
- syscaller agentproc.Syscaller
212
+ prometheusRegistry * prometheus.Registry
213
+ metrics * agentMetrics
214
+ modifiedProcs chan []* agentproc.Process
215
+ syscaller agentproc.Syscaller
217
216
}
218
217
219
218
func (a * agent ) TailnetConn () * tailnet.Conn {
@@ -1299,9 +1298,12 @@ func (a *agent) manageProcessPriorityLoop(ctx context.Context) {
1299
1298
1300
1299
manage ()
1301
1300
1301
+ ticker := time .NewTicker (time .Second )
1302
+ defer ticker .Stop ()
1303
+
1302
1304
for {
1303
1305
select {
1304
- case <- a . processManagementTick :
1306
+ case <- ticker . C :
1305
1307
manage ()
1306
1308
case <- ctx .Done ():
1307
1309
return
@@ -1313,7 +1315,7 @@ func (a *agent) manageProcessPriority(ctx context.Context) ([]*agentproc.Process
1313
1315
const (
1314
1316
procDir = agentproc .DefaultProcDir
1315
1317
niceness = 10
1316
- oomScoreAdj = - 1000
1318
+ oomScoreAdj = - 500
1317
1319
)
1318
1320
1319
1321
procs , err := agentproc .List (a .filesystem , a .syscaller , agentproc .DefaultProcDir )
@@ -1357,6 +1359,11 @@ func (a *agent) manageProcessPriority(ctx context.Context) ([]*agentproc.Process
1357
1359
)
1358
1360
continue
1359
1361
}
1362
+
1363
+ // We only want processes that don't have a nice value set
1364
+ // so we don't override user nice values.
1365
+ // Getpriority actually returns priority for the nice value
1366
+ // which is niceness + 20, so here 20 = a niceness of 0 (aka unset).
1360
1367
if score != 20 {
1361
1368
a .logger .Error (ctx , "skipping process due to custom niceness" ,
1362
1369
slog .F ("name" , proc .Name ()),
0 commit comments