Skip to content

Commit 4497662

Browse files
committed
Fix io imits not written after workspace stop
1 parent 81cd1f8 commit 4497662

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (host *PluginHost) WorkspaceAdded(ctx context.Context, ws *dispatch.Workspa
8181

8282
cgroupPath, err := disp.Runtime.ContainerCGroupPath(context.Background(), ws.ContainerID)
8383
if err != nil {
84-
return xerrors.Errorf("cannot start governer: %w", err)
84+
return xerrors.Errorf("cannot get cgroup path for container %s: %w", ws.ContainerID, err)
8585
}
8686

8787
for _, plg := range host.Plugins {

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

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,35 @@ import (
1515
"github.com/gitpod-io/gitpod/common-go/log"
1616
)
1717

18-
type IOLimiterV2 struct {
18+
var clearLimits = ioLimitOptions{
19+
WriteBytesPerSecond: 0,
20+
ReadBytesPerSecond: 0,
21+
WriteIOPs: 0,
22+
ReadIOPs: 0,
23+
}
24+
25+
type ioLimitOptions struct {
1926
WriteBytesPerSecond int64
2027
ReadBytesPerSecond int64
21-
ReadIOPs int64
2228
WriteIOPs int64
29+
ReadIOPs int64
30+
}
31+
32+
type IOLimiterV2 struct {
33+
limits ioLimitOptions
34+
}
35+
36+
func NewIOLimiterV2(writeBytesPerSecond, readBytesPerSecond, writeIOPs, readIOPs int64) *IOLimiterV2 {
37+
limits := ioLimitOptions{
38+
WriteBytesPerSecond: writeBytesPerSecond,
39+
ReadBytesPerSecond: readBytesPerSecond,
40+
WriteIOPs: writeIOPs,
41+
ReadIOPs: readIOPs,
42+
}
43+
44+
return &IOLimiterV2{
45+
limits: limits,
46+
}
2347
}
2448

2549
func (c *IOLimiterV2) Name() string { return "iolimiter-v2" }
@@ -42,19 +66,15 @@ func (c *IOLimiterV2) Apply(ctx context.Context, basePath, cgroupPath string) er
4266
// Prior to shutting down though, we need to reset the IO limits to ensure we don't have
4367
// processes stuck in the uninterruptable "D" (disk sleep) state. This would prevent the
4468
// workspace pod from shutting down.
45-
c.WriteBytesPerSecond = 0
46-
c.ReadBytesPerSecond = 0
47-
c.WriteIOPs = 0
48-
c.ReadIOPs = 0
4969

50-
err := c.writeIOMax(ioMaxFile)
70+
err := c.writeIOMax(ioMaxFile, clearLimits)
5171
if err != nil {
5272
log.WithError(err).WithField("cgroupPath", cgroupPath).Error("cannot write IO limits")
5373
}
5474
log.WithField("cgroupPath", cgroupPath).Debug("stopping io limiting")
5575
return
5676
case <-ticker.C:
57-
err := c.writeIOMax(ioMaxFile)
77+
err := c.writeIOMax(ioMaxFile, c.limits)
5878
if err != nil {
5979
log.WithError(err).WithField("cgroupPath", cgroupPath).Error("cannot write IO limits")
6080
}
@@ -64,7 +84,7 @@ func (c *IOLimiterV2) Apply(ctx context.Context, basePath, cgroupPath string) er
6484
return nil
6585
}
6686

67-
func (c *IOLimiterV2) writeIOMax(cgroupPath string) error {
87+
func (c *IOLimiterV2) writeIOMax(cgroupPath string, options ioLimitOptions) error {
6888
iostat, err := os.ReadFile(filepath.Join(string(cgroupPath), "io.stat"))
6989
if os.IsNotExist(err) {
7090
// cgroup gone is ok due to the dispatch/container race
@@ -80,7 +100,6 @@ func (c *IOLimiterV2) writeIOMax(cgroupPath string) error {
80100
// 9 block Metadisk (RAID) devices
81101
// source https://www.kernel.org/doc/Documentation/admin-guide/devices.txt
82102
var classesToLimit = []string{"8", "9"}
83-
84103
var devs []string
85104
for _, line := range strings.Split(string(iostat), "\n") {
86105
fields := strings.Fields(line)
@@ -100,10 +119,10 @@ func (c *IOLimiterV2) writeIOMax(cgroupPath string) error {
100119
limit := fmt.Sprintf(
101120
"%s wbps=%s rbps=%s wiops=%s riops=%s",
102121
dev,
103-
getLimit(c.WriteBytesPerSecond),
104-
getLimit(c.ReadBytesPerSecond),
105-
getLimit(c.WriteIOPs),
106-
getLimit(c.ReadIOPs),
122+
getLimit(options.WriteBytesPerSecond),
123+
getLimit(options.ReadBytesPerSecond),
124+
getLimit(options.WriteIOPs),
125+
getLimit(options.ReadIOPs),
107126
)
108127

109128
log.WithField("limit", limit).WithField("ioMaxPath", ioMaxPath).Debug("creating io.max limit")

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,7 @@ func NewDaemon(config Config, reg prometheus.Registerer) (*Daemon, error) {
5757
&cgroup.CacheReclaim{},
5858
&cgroup.FuseDeviceEnablerV1{},
5959
&cgroup.FuseDeviceEnablerV2{},
60-
&cgroup.IOLimiterV2{
61-
WriteBytesPerSecond: config.IOLimit.WriteBWPerSecond.Value(),
62-
ReadBytesPerSecond: config.IOLimit.ReadBWPerSecond.Value(),
63-
WriteIOPs: config.IOLimit.WriteIOPS,
64-
ReadIOPs: config.IOLimit.ReadIOPS,
65-
},
60+
cgroup.NewIOLimiterV2(config.IOLimit.WriteBWPerSecond.Value(), config.IOLimit.ReadBWPerSecond.Value(), config.IOLimit.WriteIOPS, config.IOLimit.ReadIOPS),
6661
)
6762
if err != nil {
6863
return nil, err

0 commit comments

Comments
 (0)