File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -55,10 +55,13 @@ const (
5555
5656func (t traceout ) s () string { return string (t ) }
5757
58+ const minMemLimit = 512 * 1024 * 1024 // 512MiB
59+ const maxMemLimit = 4 * 1024 * 1024 * 1024 // 4GiB
60+
5861func init () {
5962 // increase garbage collection frequency: archive.is/WQBf7
6063 debug .SetGCPercent (25 )
61- debug .SetMemoryLimit (1024 * 1024 * 1024 * 4 ) // 4GB
64+ debug .SetMemoryLimit (maxMemLimit )
6265 debug .SetPanicOnFault (true )
6366}
6467
@@ -152,6 +155,7 @@ func FlightRecorder(y bool) (bool, error) {
152155// LowMem triggers garbage collection cycle & allows for
153156// setting maximum memory limit, if limit > 0.
154157func LowMem (limitBytes int64 ) {
158+ limitBytes = max (limitBytes , minMemLimit )
155159 prevLimit := debug .SetMemoryLimit (limitBytes )
156160 go debug .FreeOSMemory ()
157161 log .I ("tun: lowmem; limits => new: %d, prev: %d" , limitBytes , prevLimit )
You can’t perform that action at this time.
0 commit comments