mirror of
https://gitee.com/ThingsGateway/ThingsGateway.git
synced 2025-10-25 12:43:09 +08:00
修改可用内存策略
This commit is contained in:
@@ -683,13 +683,36 @@ public class MachineInfo : IExtend
|
|||||||
if (dic.TryGetValue("MemTotal", out var str) && !str.IsNullOrEmpty())
|
if (dic.TryGetValue("MemTotal", out var str) && !str.IsNullOrEmpty())
|
||||||
Memory = (UInt64)str.TrimEnd(" kB").ToLong();
|
Memory = (UInt64)str.TrimEnd(" kB").ToLong();
|
||||||
|
|
||||||
if (dic.TryGetValue("MemAvailable", out str) && !str.IsNullOrEmpty())
|
/*
|
||||||
AvailableMemory = (UInt64)str.TrimEnd(" kB").ToLong();
|
指标 含义 是否可回收
|
||||||
else if (dic.TryGetValue("MemFree", out str) && !str.IsNullOrEmpty())
|
MemTotal 系统总物理内存 ❌ 固定值
|
||||||
AvailableMemory =
|
MemFree 完全未使用的内存(不含缓存/缓冲区) ✅ 100% 可用
|
||||||
(UInt64)(str.TrimEnd(" kB").ToLong() +
|
MemAvailable 内核估计的可用内存(含可回收缓存和缓冲区) ✅ 最权威的保守估计
|
||||||
dic["Buffers"]?.TrimEnd(" kB").ToLong() ?? 0 +
|
Cached 文件系统缓存(Page Cache),可完全回收 ✅ 100% 可回收
|
||||||
dic["Cached"]?.TrimEnd(" kB").ToLong() ?? 0);
|
SReclaimable Slab 缓存中可回收的部分(如 dentry/inode) ✅ 大部分可回收(80%~90%)
|
||||||
|
Buffers 磁盘块缓存(现代内核中值较小,可回收) ✅ 可回收
|
||||||
|
Slab 内核对象缓存总大小(含可回收和不可回收部分) ⚠️ 需区分 SReclaimable
|
||||||
|
SwapCached 被缓存到 Swap 的内存(可回收,但性能较差) ✅ 可回收但不建议依赖
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
var ma = (UInt64)(dic["MemAvailable"]?.TrimEnd(" kB").ToLong() ?? 0);
|
||||||
|
var mf = (UInt64)(dic["MemFree"]?.TrimEnd(" kB").ToLong() ?? 0);
|
||||||
|
var mc = (UInt64)(dic["Cached"]?.TrimEnd(" kB").ToLong() ?? 0);
|
||||||
|
|
||||||
|
if (dic.TryGetValue("SReclaimable", out str) && !str.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
var sr = (UInt64)(str?.TrimEnd(" kB").ToLong() ?? 0);
|
||||||
|
mf += (ulong)(sr * 0.9);
|
||||||
|
}
|
||||||
|
if (dic.TryGetValue("Buffers", out str) && !str.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
var bf = (UInt64)(str?.TrimEnd(" kB").ToLong() ?? 0);
|
||||||
|
mf += bf;
|
||||||
|
}
|
||||||
|
mf += mc;
|
||||||
|
|
||||||
|
AvailableMemory = ma > mf ? ma : mf;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A2/A4温度获取,Buildroot,CPU温度和主板温度
|
// A2/A4温度获取,Buildroot,CPU温度和主板温度
|
||||||
|
|||||||
@@ -39,8 +39,7 @@ public abstract class DriverBase : DisposableObject, IDriver
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前设备
|
/// 当前设备
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DeviceRuntime? CurrentDevice => WeakReferenceCurrentDevice?.TryGetTarget(out var target) == true ? target : null;
|
public DeviceRuntime? CurrentDevice { get; private set; }
|
||||||
private WeakReference<DeviceRuntime> WeakReferenceCurrentDevice { get; set; }
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前设备Id
|
/// 当前设备Id
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -208,7 +207,7 @@ public abstract class DriverBase : DisposableObject, IDriver
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal void InitDevice(DeviceRuntime device)
|
internal void InitDevice(DeviceRuntime device)
|
||||||
{
|
{
|
||||||
WeakReferenceCurrentDevice = new WeakReference<DeviceRuntime>(device);
|
CurrentDevice = device;
|
||||||
|
|
||||||
_logger = App.RootServices.GetService<Microsoft.Extensions.Logging.ILoggerFactory>().CreateLogger($"Driver[{CurrentDevice.Name}]");
|
_logger = App.RootServices.GetService<Microsoft.Extensions.Logging.ILoggerFactory>().CreateLogger($"Driver[{CurrentDevice.Name}]");
|
||||||
|
|
||||||
|
|||||||
@@ -505,6 +505,7 @@ public partial class MqttClient : BusinessBaseWithCacheIntervalScriptAll
|
|||||||
|
|
||||||
private async ValueTask<OperResult> TryMqttClientAsync(CancellationToken cancellationToken)
|
private async ValueTask<OperResult> TryMqttClientAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
System.Console.WriteLine($"{this.DeviceName} TryMqttClientAsync {DateTime.Now:HH:mm:ss.fff}");
|
||||||
if (_mqttClient?.IsConnected == true)
|
if (_mqttClient?.IsConnected == true)
|
||||||
return OperResult.Success;
|
return OperResult.Success;
|
||||||
return await Client().ConfigureAwait(false);
|
return await Client().ConfigureAwait(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user