Prevent GC from schedule itself with 0 period.
On startup `gcTimeSum` might work fast and return `0`, so on this case the algorithm turns in infinity loop which simple consume CPU on timer which fires without any interval. Use `5ms` as fallback to have interval `245ms` for that case. Closes: https://github.com/containerd/containerd/issues/5089 Signed-off-by: Kirill A. Korinsky <kirill@korins.ky>
This commit is contained in:
parent
f1a3c3705f
commit
c8766123d9
@ -234,6 +234,7 @@ func schedule(d time.Duration) (<-chan time.Time, *time.Time) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *gcScheduler) run(ctx context.Context) {
|
func (s *gcScheduler) run(ctx context.Context) {
|
||||||
|
const minimumGCTime = float64(5 * time.Millisecond)
|
||||||
var (
|
var (
|
||||||
schedC <-chan time.Time
|
schedC <-chan time.Time
|
||||||
|
|
||||||
@ -331,6 +332,11 @@ func (s *gcScheduler) run(ctx context.Context) {
|
|||||||
// runtime in between gc to reach the pause threshold.
|
// runtime in between gc to reach the pause threshold.
|
||||||
// Pause threshold is always 0.0 < threshold <= 0.5
|
// Pause threshold is always 0.0 < threshold <= 0.5
|
||||||
avg := float64(gcTimeSum) / float64(collections)
|
avg := float64(gcTimeSum) / float64(collections)
|
||||||
|
// Enforce that avg is no less than minimumGCTime
|
||||||
|
// to prevent immediate rescheduling
|
||||||
|
if avg < minimumGCTime {
|
||||||
|
avg = minimumGCTime
|
||||||
|
}
|
||||||
interval = time.Duration(avg/s.pauseThreshold - avg)
|
interval = time.Duration(avg/s.pauseThreshold - avg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user