@@ -15,11 +15,35 @@ import (
15
15
"github.com/gitpod-io/gitpod/common-go/log"
16
16
)
17
17
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 {
19
26
WriteBytesPerSecond int64
20
27
ReadBytesPerSecond int64
21
- ReadIOPs int64
22
28
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
+ }
23
47
}
24
48
25
49
func (c * IOLimiterV2 ) Name () string { return "iolimiter-v2" }
@@ -42,19 +66,15 @@ func (c *IOLimiterV2) Apply(ctx context.Context, basePath, cgroupPath string) er
42
66
// Prior to shutting down though, we need to reset the IO limits to ensure we don't have
43
67
// processes stuck in the uninterruptable "D" (disk sleep) state. This would prevent the
44
68
// workspace pod from shutting down.
45
- c .WriteBytesPerSecond = 0
46
- c .ReadBytesPerSecond = 0
47
- c .WriteIOPs = 0
48
- c .ReadIOPs = 0
49
69
50
- err := c .writeIOMax (ioMaxFile )
70
+ err := c .writeIOMax (ioMaxFile , clearLimits )
51
71
if err != nil {
52
72
log .WithError (err ).WithField ("cgroupPath" , cgroupPath ).Error ("cannot write IO limits" )
53
73
}
54
74
log .WithField ("cgroupPath" , cgroupPath ).Debug ("stopping io limiting" )
55
75
return
56
76
case <- ticker .C :
57
- err := c .writeIOMax (ioMaxFile )
77
+ err := c .writeIOMax (ioMaxFile , c . limits )
58
78
if err != nil {
59
79
log .WithError (err ).WithField ("cgroupPath" , cgroupPath ).Error ("cannot write IO limits" )
60
80
}
@@ -64,7 +84,7 @@ func (c *IOLimiterV2) Apply(ctx context.Context, basePath, cgroupPath string) er
64
84
return nil
65
85
}
66
86
67
- func (c * IOLimiterV2 ) writeIOMax (cgroupPath string ) error {
87
+ func (c * IOLimiterV2 ) writeIOMax (cgroupPath string , options ioLimitOptions ) error {
68
88
iostat , err := os .ReadFile (filepath .Join (string (cgroupPath ), "io.stat" ))
69
89
if os .IsNotExist (err ) {
70
90
// cgroup gone is ok due to the dispatch/container race
@@ -80,7 +100,6 @@ func (c *IOLimiterV2) writeIOMax(cgroupPath string) error {
80
100
// 9 block Metadisk (RAID) devices
81
101
// source https://www.kernel.org/doc/Documentation/admin-guide/devices.txt
82
102
var classesToLimit = []string {"8" , "9" }
83
-
84
103
var devs []string
85
104
for _ , line := range strings .Split (string (iostat ), "\n " ) {
86
105
fields := strings .Fields (line )
@@ -100,10 +119,10 @@ func (c *IOLimiterV2) writeIOMax(cgroupPath string) error {
100
119
limit := fmt .Sprintf (
101
120
"%s wbps=%s rbps=%s wiops=%s riops=%s" ,
102
121
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 ),
107
126
)
108
127
109
128
log .WithField ("limit" , limit ).WithField ("ioMaxPath" , ioMaxPath ).Debug ("creating io.max limit" )
0 commit comments