Skip to content

Commit aabbe61

Browse files
csweichelroboquat
authored andcommitted
[ws-daemon] Improve cgroup plugin activation count
1 parent 15deb83 commit aabbe61

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

components/ws-daemon/pkg/cgroup/cgroup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (host *PluginHost) WorkspaceAdded(ctx context.Context, ws *dispatch.Workspa
9292
go func(plg Plugin) {
9393
err := plg.Apply(ctx, host.CGroupBasePath, cgroupPath)
9494
if err == context.Canceled || err == context.DeadlineExceeded {
95-
return
95+
err = nil
9696
}
9797
if err != nil {
9898
log.WithError(err).WithFields(ws.OWI()).WithField("plugin", plg.Name()).Error("cgroup plugin failure")

components/ws-daemon/pkg/cgroup/plugin_iolimit_v2.go

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,37 @@ func (c *IOLimiterV2) Name() string { return "iolimiter-v2" }
2626
func (c *IOLimiterV2) Type() Version { return Version2 }
2727

2828
func (c *IOLimiterV2) Apply(ctx context.Context, basePath, cgroupPath string) error {
29-
// We are racing workspacekit and the interaction with disks.
30-
// If we did this just once there's a chance we haven't interacted with all
31-
// devices yet, and hence would not impose IO limits on them.
32-
ticker := time.NewTicker(30 * time.Second)
33-
defer ticker.Stop()
34-
for {
35-
select {
36-
case <-ctx.Done():
37-
// Prior to shutting down though, we need to reset the IO limits to ensure we don't have
38-
// processes stuck in the uninterruptable "D" (disk sleep) state. This would prevent the
39-
// workspace pod from shutting down.
40-
c.WriteBytesPerSecond = 0
41-
c.ReadBytesPerSecond = 0
42-
c.WriteIOPs = 0
43-
c.ReadIOPs = 0
29+
go func() {
30+
// We are racing workspacekit and the interaction with disks.
31+
// If we did this just once there's a chance we haven't interacted with all
32+
// devices yet, and hence would not impose IO limits on them.
33+
ticker := time.NewTicker(30 * time.Second)
34+
defer ticker.Stop()
35+
for {
36+
select {
37+
case <-ctx.Done():
38+
// Prior to shutting down though, we need to reset the IO limits to ensure we don't have
39+
// processes stuck in the uninterruptable "D" (disk sleep) state. This would prevent the
40+
// workspace pod from shutting down.
41+
c.WriteBytesPerSecond = 0
42+
c.ReadBytesPerSecond = 0
43+
c.WriteIOPs = 0
44+
c.ReadIOPs = 0
4445

45-
err := c.writeIOMax(filepath.Join(basePath, cgroupPath))
46-
if err != nil {
47-
return err
48-
}
49-
return ctx.Err()
50-
case <-ticker.C:
51-
err := c.writeIOMax(filepath.Join(basePath, cgroupPath))
52-
if err != nil {
53-
log.WithError(err).WithField("cgroupPath", cgroupPath).Error("cannot write IO limits")
46+
err := c.writeIOMax(filepath.Join(basePath, cgroupPath))
47+
if err != nil {
48+
log.WithError(err).WithField("cgroupPath", cgroupPath).Error("cannot write IO limits")
49+
}
50+
return
51+
case <-ticker.C:
52+
err := c.writeIOMax(filepath.Join(basePath, cgroupPath))
53+
if err != nil {
54+
log.WithError(err).WithField("cgroupPath", cgroupPath).Error("cannot write IO limits")
55+
}
5456
}
5557
}
56-
}
58+
}()
59+
return nil
5760
}
5861

5962
func (c *IOLimiterV2) writeIOMax(loc string) error {

0 commit comments

Comments
 (0)