mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-09 18:43:14 +00:00
24 lines
520 B
Go
24 lines
520 B
Go
package libbox
|
|
|
|
import (
|
|
"math"
|
|
runtimeDebug "runtime/debug"
|
|
|
|
"github.com/sagernet/sing-box/common/conntrack"
|
|
)
|
|
|
|
func SetMemoryLimit(enabled bool) {
|
|
const memoryLimit = 45 * 1024 * 1024
|
|
const memoryLimitGo = memoryLimit / 1.5
|
|
if enabled {
|
|
runtimeDebug.SetGCPercent(10)
|
|
runtimeDebug.SetMemoryLimit(memoryLimitGo)
|
|
conntrack.KillerEnabled = true
|
|
conntrack.MemoryLimit = memoryLimit
|
|
} else {
|
|
runtimeDebug.SetGCPercent(100)
|
|
runtimeDebug.SetMemoryLimit(math.MaxInt64)
|
|
conntrack.KillerEnabled = false
|
|
}
|
|
}
|