From 4b616baed4ed53c2ba7014c6ab706bf5ab4643d5 Mon Sep 17 00:00:00 2001 From: Lizonghang <870644199@qq.com> Date: Wed, 29 Jan 2025 19:57:06 +0400 Subject: [PATCH] fix macos x86_64 available mem estimation --- common/profiler.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/common/profiler.cpp b/common/profiler.cpp index 24743c21..2d841768 100644 --- a/common/profiler.cpp +++ b/common/profiler.cpp @@ -501,13 +501,9 @@ static uint64_t device_host_physical_memory(bool available) { if (available) { if (host_statistics64(host, HOST_VM_INFO64, (host_info64_t)&vm_stats, &count) == KERN_SUCCESS) { - size_t page_size = sysconf(_SC_PAGESIZE); - - if (is_uma_arch()) { // Mac UMA with ARM64 - 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; - } + 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()) memory += vm_stats.speculative_count * page_size; } else { LOG_INF("host_statistics64 failed\n"); }