Merge branch 'cb/total-ram-bsd-fix'

Use of sysctl() system call to learn the total RAM size used on
BSDs has been corrected.

* cb/total-ram-bsd-fix:
  builtin/gc: correct total_ram calculation with HAVE_BSD_SYSCTL
This commit is contained in:
Junio C Hamano
2025-07-14 11:19:22 -07:00

View File

@@ -539,7 +539,7 @@ static uint64_t total_ram(void)
return total; return total;
} }
#elif defined(HAVE_BSD_SYSCTL) && (defined(HW_MEMSIZE) || defined(HW_PHYSMEM) || defined(HW_PHYSMEM64)) #elif defined(HAVE_BSD_SYSCTL) && (defined(HW_MEMSIZE) || defined(HW_PHYSMEM) || defined(HW_PHYSMEM64))
int64_t physical_memory; uint64_t physical_memory;
int mib[2]; int mib[2];
size_t length; size_t length;
@@ -551,9 +551,16 @@ static uint64_t total_ram(void)
# else # else
mib[1] = HW_PHYSMEM; mib[1] = HW_PHYSMEM;
# endif # endif
length = sizeof(int64_t); length = sizeof(physical_memory);
if (!sysctl(mib, 2, &physical_memory, &length, NULL, 0)) if (!sysctl(mib, 2, &physical_memory, &length, NULL, 0)) {
if (length == 4) {
uint32_t mem;
if (!sysctl(mib, 2, &mem, &length, NULL, 0))
physical_memory = mem;
}
return physical_memory; return physical_memory;
}
#elif defined(GIT_WINDOWS_NATIVE) #elif defined(GIT_WINDOWS_NATIVE)
MEMORYSTATUSEX memInfo; MEMORYSTATUSEX memInfo;