fix macos x86_64 available mem estimation

This commit is contained in:
Lizonghang 2025-01-29 19:57:06 +04:00
parent 849b47ccd0
commit 4b616baed4

View file

@ -501,13 +501,9 @@ static uint64_t device_host_physical_memory(bool available) {
if (available) { if (available) {
if (host_statistics64(host, HOST_VM_INFO64, (host_info64_t)&vm_stats, &count) == KERN_SUCCESS) { if (host_statistics64(host, HOST_VM_INFO64, (host_info64_t)&vm_stats, &count) == KERN_SUCCESS) {
size_t page_size = sysconf(_SC_PAGESIZE); size_t page_size = get_page_size();
memory = (vm_stats.free_count + vm_stats.inactive_count + vm_stats.purgeable_count) * page_size;
if (is_uma_arch()) { // Mac UMA with ARM64 if (!is_uma_arch()) memory += vm_stats.speculative_count * page_size;
memory = (vm_stats.free_count + vm_stats.inactive_count) * page_size;
} else { // Mac with x86_64
memory = total_memory - (vm_stats.internal_page_count - vm_stats.purgeable_count) * page_size;
}
} else { } else {
LOG_INF("host_statistics64 failed\n"); LOG_INF("host_statistics64 failed\n");
} }