Skip to content

Commit 6764046

Browse files
author
Tony Tang
committed
runtime: add comments for gcCPULimiter testcases
add comments to explain some constant values used in testcases.
1 parent 5dcaf9a commit 6764046

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/runtime/mgclimit_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ func TestGCCPULimiter(t *testing.T) {
154154
// Drain the bucket by half.
155155
l.AddAssistTime(assistTime(CapacityPerProc, 0))
156156
l.Update(advance(CapacityPerProc))
157+
//
158+
// test start condition: l.Fill == l.Capacity
159+
//
160+
// assistTime = 0
161+
// gcTime = CapacityPerProc * procs * GCBackgroundUtilization
162+
// mutatorTime = CapacityPerProc * procs * (1 - GCBackgroundUtilization)
163+
// change = gcTime - mutatorTime
164+
// = CapacityPerProc * procs * (2 * GCBackgroundUtilization - 1)
165+
// l.Fill = l.Fill + change // here change < 0
166+
// = l.Capacity + change
167+
// = CapacityPerProc * procs + change
168+
// = CapacityPerProc * procs * 2 * GCBackgroundUtilization
169+
// = l.Capacity * 2 * GCBackgroundUtilization
170+
// = l.Capacity * 0.5 // by default GCBackgroundUtilization = 0.25
171+
// = l.Capacity / 2
172+
//
157173
if expect := l.Capacity() / 2; l.Fill() != expect {
158174
t.Errorf("failed to drain to %d, got fill %d", expect, l.Fill())
159175
}
@@ -167,6 +183,25 @@ func TestGCCPULimiter(t *testing.T) {
167183
// Test overfilling the bucket.
168184
l.AddAssistTime(assistTime(CapacityPerProc, 1.0-GCBackgroundUtilization))
169185
l.Update(advance(CapacityPerProc))
186+
//
187+
// test start condition: l.Fill == l.Capacity * 2 * GCBackgroundUtilization
188+
//
189+
// assistTime = CapacityPerProc * procs * (1 - GCBackgroundUtilization)
190+
// gcTime = CapacityPerProc * procs * GCBackgroundUtilization + assistTime
191+
// = CapacityPerProc * procs
192+
// = l.Capacity
193+
// mutatorTime = CapacityPerProc * procs * (1 - GCBackgroundUtilization) - assistTime
194+
// = 0
195+
// change = gcTime - mutatorTime
196+
// = l.Capacity
197+
// l.Overflow = l.Fill + change - l.Capacity
198+
// = l.Capacity * 2 * GCBackgroundUtilization + l.Capacity - l.Capacity
199+
// = l.Capacity * 2 * GCBackgroundUtilization
200+
// = l.Capacity * 0.5 // by default GCBackgroundUtilization = 0.25
201+
// = l.Capacity / 2
202+
// = CapacityPerProc * procs / 2
203+
// l.Fill = l.Capacity // because change is too large
204+
//
170205
if l.Fill() != l.Capacity() {
171206
t.Errorf("failed to fill to capacity %d, got fill %d", l.Capacity(), l.Fill())
172207
}

0 commit comments

Comments
 (0)