diff --git a/internal/nodes/node_status_executor_unix.go b/internal/nodes/node_status_executor_unix.go index 9ac47129..4c4e1075 100644 --- a/internal/nodes/node_status_executor_unix.go +++ b/internal/nodes/node_status_executor_unix.go @@ -6,6 +6,8 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "github.com/shirou/gopsutil/v3/load" "github.com/shirou/gopsutil/v3/mem" + "runtime" + "runtime/debug" ) // 更新内存 @@ -22,6 +24,18 @@ func (this *NodeStatusExecutor) updateMem(status *nodeconfigs.NodeStatus) { } status.MemoryTotal = stat.Total + + // 内存严重不足时自动释放内存 + if stat.Total > 0 { + var minFreeMemory = stat.Total / 8 + if minFreeMemory > 1<<30 { + minFreeMemory = 1 << 30 + } + if stat.Free < minFreeMemory { + runtime.GC() + debug.FreeOSMemory() + } + } } // 更新负载