From 04ae8fa4a0897b0ea143aa7c09e1eb9c4a5ff4f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Thu, 2 Mar 2023 10:54:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E5=86=85=E5=AD=98=E4=B8=8D?= =?UTF-8?q?=E8=B6=B3=E6=97=B6=EF=BC=8C=E5=B0=9D=E8=AF=95=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=9B=9E=E6=94=B6=E5=86=85=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/node_status_executor_unix.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/nodes/node_status_executor_unix.go b/internal/nodes/node_status_executor_unix.go index f134465..dfd28d6 100644 --- a/internal/nodes/node_status_executor_unix.go +++ b/internal/nodes/node_status_executor_unix.go @@ -8,6 +8,8 @@ import ( "github.com/iwind/TeaGo/maps" "github.com/shirou/gopsutil/v3/load" "github.com/shirou/gopsutil/v3/mem" + "runtime" + "runtime/debug" ) // 更新内存 @@ -31,6 +33,18 @@ func (this *NodeStatusExecutor) updateMem(status *nodeconfigs.NodeStatus) { "total": status.MemoryTotal, "used": stat.Used, }) + + // 内存严重不足时自动释放内存 + if stat.Total > 0 { + var minFreeMemory = stat.Total / 8 + if minFreeMemory > 1<<30 { + minFreeMemory = 1 << 30 + } + if stat.Free < minFreeMemory { + runtime.GC() + debug.FreeOSMemory() + } + } } // 更新负载