github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/mem/system_1.19.go (about)

     1  // Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
     2  //go:build go1.19
     3  
     4  package memutils
     5  
     6  import (
     7  	"runtime/debug"
     8  )
     9  
    10  // 设置软内存最大值
    11  func setMaxMemory(memoryGB int) {
    12  	if memoryGB <= 0 {
    13  		memoryGB = 1
    14  	}
    15  
    16  	var maxMemoryBytes = (int64(memoryGB) << 30) * 80 / 100 // 默认 80%
    17  	debug.SetMemoryLimit(maxMemoryBytes)
    18  }