github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/experimental/libbox/memory.go (about)

     1  package libbox
     2  
     3  import (
     4  	"math"
     5  	runtimeDebug "runtime/debug"
     6  
     7  	"github.com/inazumav/sing-box/common/dialer/conntrack"
     8  )
     9  
    10  func SetMemoryLimit(enabled bool) {
    11  	const memoryLimit = 30 * 1024 * 1024
    12  	if enabled {
    13  		runtimeDebug.SetGCPercent(10)
    14  		runtimeDebug.SetMemoryLimit(memoryLimit)
    15  		conntrack.KillerEnabled = true
    16  		conntrack.MemoryLimit = memoryLimit
    17  	} else {
    18  		runtimeDebug.SetGCPercent(100)
    19  		runtimeDebug.SetMemoryLimit(math.MaxInt64)
    20  		conntrack.KillerEnabled = false
    21  	}
    22  }