platform: Add oom killer

This commit is contained in:
世界
2023-03-16 10:55:06 +08:00
parent 2cb0e37f50
commit cc9cb0b477
6 changed files with 80 additions and 33 deletions

View File

@@ -2,9 +2,17 @@
package libbox
import "runtime/debug"
import (
runtimeDebug "runtime/debug"
"github.com/sagernet/sing-box/common/dialer/conntrack"
)
const memoryLimit = 30 * 1024 * 1024
func SetMemoryLimit() {
debug.SetGCPercent(10)
debug.SetMemoryLimit(30 * 1024 * 1024)
runtimeDebug.SetGCPercent(10)
runtimeDebug.SetMemoryLimit(memoryLimit)
conntrack.KillerEnabled = true
conntrack.MemoryLimit = memoryLimit
}