sing-box/experimental/libbox/memory.go

23 lines
484 B
Go
Raw Normal View History

2023-03-02 05:13:12 +00:00
package libbox
2023-03-16 02:55:06 +00:00
import (
2023-07-11 13:22:33 +00:00
"math"
2023-03-16 02:55:06 +00:00
runtimeDebug "runtime/debug"
"github.com/sagernet/sing-box/common/dialer/conntrack"
)
2023-07-11 13:22:33 +00:00
func SetMemoryLimit(enabled bool) {
const memoryLimit = 30 * 1024 * 1024
if enabled {
runtimeDebug.SetGCPercent(10)
runtimeDebug.SetMemoryLimit(memoryLimit)
conntrack.KillerEnabled = true
conntrack.MemoryLimit = memoryLimit
} else {
runtimeDebug.SetGCPercent(100)
runtimeDebug.SetMemoryLimit(math.MaxInt64)
conntrack.KillerEnabled = false
}
2023-03-02 05:13:12 +00:00
}