mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-08 19:00:54 +08:00
增加软内存最大值限制
This commit is contained in:
@@ -23,5 +23,11 @@ func SystemMemoryGB() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
systemTotalMemory = int(stat.Total / 1024 / 1024 / 1024)
|
systemTotalMemory = int(stat.Total / 1024 / 1024 / 1024)
|
||||||
|
if systemTotalMemory <= 0 {
|
||||||
|
systemTotalMemory = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
setMaxMemory(systemTotalMemory)
|
||||||
|
|
||||||
return systemTotalMemory
|
return systemTotalMemory
|
||||||
}
|
}
|
||||||
|
|||||||
23
internal/utils/system_1.19.go
Normal file
23
internal/utils/system_1.19.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// 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
|
||||||
|
}
|
||||||
|
var maxMemoryBytes int64 = 0
|
||||||
|
if memoryGB > 10 {
|
||||||
|
maxMemoryBytes = int64(memoryGB-2) << 30 // 超过10G内存的允许剩余2G内存
|
||||||
|
} else {
|
||||||
|
maxMemoryBytes = (int64(memoryGB) << 30) * 100 / 80 // 默认 80%
|
||||||
|
}
|
||||||
|
|
||||||
|
debug.SetMemoryLimit(maxMemoryBytes)
|
||||||
|
}
|
||||||
9
internal/utils/system_before_1.19.go
Normal file
9
internal/utils/system_before_1.19.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
//go:build !go1.19
|
||||||
|
|
||||||
|
package utils
|
||||||
|
|
||||||
|
// 设置软内存最大值
|
||||||
|
func setMaxMemory(memoryGB int) {
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user