HMCL icon indicating copy to clipboard operation
HMCL copied to clipboard

修复 macOS 下剩余内存读取问题

Open WhatDamon opened this issue 1 month ago • 1 comments

Fix #3980

实现逻辑:通过 vm_stat 命令获取空闲内存,内存读取较原有逻辑误差显著降低

受限于手头设备原因,这可能需要额外的测试来证明代码可用性

Before

Before

After

After

误差原因:这是同时计算了 vm_stat 输出的 Pages inactivePages free,可能逻辑与检测工具之间存在差异


附: vm_stat 示例输出:

Mach Virtual Memory Statistics: (page size of 16384 bytes)
Pages free:                                3857.
Pages active:                            446206.
Pages inactive:                          443760.
Pages speculative:                         1075.
Pages throttled:                              0.
Pages wired down:                        181483.
Pages purgeable:                          17340.
"Translation faults":                8667427138.
Pages copy-on-write:                  156847509.
Pages zero filled:                   4902315421.
Pages reactivated:                    586001636.
Pages purged:                         174538344.
File-backed pages:                       294894.
Anonymous pages:                         596147.
Pages stored in compressor:             1943619.
Pages occupied by compressor:            442179.
Decompressions:                       591661242.
Compressions:                         654599489.
Pageins:                              134108004.
Pageouts:                              31713991.
Swapins:                                1582661.
Swapouts:                               2698721.

WhatDamon avatar Nov 28 '25 19:11 WhatDamon

上一个提交修改了计算公式:(pagesFree - pagesSpeculative + pagesInactive + pagesPurgeable) * pageSize 这是 ChatGPT 的建议,当然相比用 JNI/JNA 调用系统函数,准确性依旧一般

对于此修改,需要更多的平台测试,例如 Intel Mac 下是否可以相对正确的返回内存数据

WhatDamon avatar Dec 12 '25 16:12 WhatDamon