aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-07-14 11:19:22 -0700
committerJunio C Hamano <gitster@pobox.com>2025-07-14 11:19:23 -0700
commite02d718846dbae971fe3605fa8e90db54fc5c9bb (patch)
treef2a814685b86dcf5c40e7595296fc23135808f06
parentcc876f2c7fa470e3e2cc949377b4f33ba3f36803 (diff)
parent781c1cf5712f1768278f7f926f39ebad3be4aae0 (diff)
downloadgit-e02d718846dbae971fe3605fa8e90db54fc5c9bb.tar.gz
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
-rw-r--r--builtin/gc.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/builtin/gc.c b/builtin/gc.c
index 845876ff02..523e3de111 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -539,7 +539,7 @@ static uint64_t total_ram(void)
return total;
}
#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];
size_t length;
@@ -551,9 +551,16 @@ static uint64_t total_ram(void)
# else
mib[1] = HW_PHYSMEM;
# endif
- length = sizeof(int64_t);
- if (!sysctl(mib, 2, &physical_memory, &length, NULL, 0))
+ length = sizeof(physical_memory);
+ 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;
+ }
#elif defined(GIT_WINDOWS_NATIVE)
MEMORYSTATUSEX memInfo;