Fix oomkiller
This commit is contained in:
@@ -52,21 +52,6 @@ func NewService(ctx context.Context, logger log.ContextLogger, tag string, optio
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Service) createTimer() {
|
||||
s.adaptiveTimer = newAdaptiveTimer(s.logger, s.network, s.timerConfig, s.writeOOMReport)
|
||||
}
|
||||
|
||||
func (s *Service) startTimer() {
|
||||
s.createTimer()
|
||||
s.adaptiveTimer.start()
|
||||
}
|
||||
|
||||
func (s *Service) stopTimer() {
|
||||
if s.adaptiveTimer != nil {
|
||||
s.adaptiveTimer.stop()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) writeOOMReport(memoryUsage uint64) {
|
||||
now := time.Now().Unix()
|
||||
lastReport := s.lastReportTime.Load()
|
||||
|
||||
@@ -54,7 +54,7 @@ func (s *Service) Start(stage adapter.StartStage) error {
|
||||
return nil
|
||||
}
|
||||
if s.timerConfig.policyMode == policyModeNetworkExtension {
|
||||
s.createTimer()
|
||||
s.adaptiveTimer = newAdaptiveTimer(s.logger, s.network, s.timerConfig, nil)
|
||||
globalAccess.Lock()
|
||||
isFirst := len(globalServices) == 0
|
||||
globalServices = append(globalServices, s)
|
||||
@@ -67,12 +67,15 @@ func (s *Service) Start(stage adapter.StartStage) error {
|
||||
if !s.timerConfig.policyMode.hasTimerMode() {
|
||||
return E.New("memory pressure monitoring is not available on this platform without memory_limit")
|
||||
}
|
||||
s.startTimer()
|
||||
s.adaptiveTimer = newAdaptiveTimer(s.logger, s.network, s.timerConfig, s.writeOOMReport)
|
||||
s.adaptiveTimer.start()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) Close() error {
|
||||
s.stopTimer()
|
||||
if s.adaptiveTimer != nil {
|
||||
s.adaptiveTimer.stop()
|
||||
}
|
||||
if s.timerConfig.policyMode == policyModeNetworkExtension {
|
||||
globalAccess.Lock()
|
||||
for i, svc := range globalServices {
|
||||
|
||||
@@ -14,11 +14,14 @@ func (s *Service) Start(stage adapter.StartStage) error {
|
||||
if !s.timerConfig.policyMode.hasTimerMode() {
|
||||
return E.New("memory pressure monitoring is not available on this platform without memory_limit")
|
||||
}
|
||||
s.startTimer()
|
||||
s.adaptiveTimer = newAdaptiveTimer(s.logger, s.network, s.timerConfig, s.writeOOMReport)
|
||||
s.adaptiveTimer.start()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) Close() error {
|
||||
s.stopTimer()
|
||||
if s.adaptiveTimer != nil {
|
||||
s.adaptiveTimer.stop()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -105,7 +105,6 @@ type adaptiveTimer struct {
|
||||
limitThresholds pressureThresholds
|
||||
|
||||
access sync.Mutex
|
||||
cleanupTriggered bool
|
||||
timer *time.Timer
|
||||
state pressureState
|
||||
currentInterval time.Duration
|
||||
@@ -162,12 +161,6 @@ func (t *adaptiveTimer) poll() {
|
||||
t.access.Unlock()
|
||||
return
|
||||
}
|
||||
if t.timerConfig.policyMode == policyModeNetworkExtension {
|
||||
if t.cleanupTriggered {
|
||||
runtimeDebug.FreeOSMemory()
|
||||
t.cleanupTriggered = true
|
||||
}
|
||||
}
|
||||
if t.pendingPressureBaseline {
|
||||
t.pressureBaseline = sample
|
||||
t.pressureBaselineTime = time.Now()
|
||||
@@ -190,8 +183,8 @@ func (t *adaptiveTimer) poll() {
|
||||
growth := sample.usage - t.pressureBaseline.usage
|
||||
ratePerSecond := float64(growth) / elapsed.Seconds()
|
||||
headroom := t.memoryLimit - sample.usage
|
||||
timeToLimit := time.Duration(float64(headroom)/ratePerSecond) * time.Second
|
||||
if timeToLimit < t.minInterval {
|
||||
secondsUntilLimit := float64(headroom) / ratePerSecond
|
||||
if secondsUntilLimit < t.minInterval.Seconds() {
|
||||
triggered = true
|
||||
rateTriggered = true
|
||||
t.state = pressureStateTriggered
|
||||
@@ -202,8 +195,9 @@ func (t *adaptiveTimer) poll() {
|
||||
if !triggered {
|
||||
return
|
||||
}
|
||||
t.cleanupTriggered = false
|
||||
t.onTriggered(sample.usage)
|
||||
if t.onTriggered != nil {
|
||||
t.onTriggered(sample.usage)
|
||||
}
|
||||
if rateTriggered {
|
||||
if t.killerDisabled {
|
||||
t.logger.Warn("memory growth rate critical (report only), usage: ", byteformats.FormatMemoryBytes(sample.usage), t.logDetails(sample))
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
|
||||
package oomkiller
|
||||
|
||||
import runtimeDebug "runtime/debug"
|
||||
|
||||
func (t *adaptiveTimer) notifyPressure() {
|
||||
runtimeDebug.FreeOSMemory()
|
||||
t.access.Lock()
|
||||
t.startLocked()
|
||||
t.forceMinInterval = true
|
||||
|
||||
Reference in New Issue
Block a user