Files
EdgeNode/internal/utils/system_1.19.go

24 lines
524 B
Go
Raw Normal View History

2023-03-05 12:34:46 +08:00
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build go1.19
package utils
import (
"runtime/debug"
)
// 设置软内存最大值
func setMaxMemory(memoryGB int) {
if memoryGB <= 0 {
memoryGB = 1
}
2023-08-08 15:39:00 +08:00
var maxMemoryBytes int64
2023-03-05 12:34:46 +08:00
if memoryGB > 10 {
maxMemoryBytes = int64(memoryGB-2) << 30 // 超过10G内存的允许剩余2G内存
} else {
2023-03-05 21:19:10 +08:00
maxMemoryBytes = (int64(memoryGB) << 30) * 80 / 100 // 默认 80%
2023-03-05 12:34:46 +08:00
}
debug.SetMemoryLimit(maxMemoryBytes)
}