{"thread":{"id":"63557","subject":"Re: [PATCH] builtin/gc: correct physical memory detection for OpenBSD / NetBSD","startedAt":"2025-06-02T01:34:13Z","lastAt":"2025-06-02T02:00:20Z","messageCount":2,"participants":["Collin Funk","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"519363","messageId":"87h60z6i5o.fsf@gmail.com","threadId":"63557","inReplyTo":null,"subject":"Re: [PATCH] builtin/gc: correct physical memory detection for OpenBSD / NetBSD","fromName":"Collin Funk","fromEmail":"collin.funk1@gmail.com","sentAt":"2025-06-02T01:34:11Z","receivedAt":"2025-06-02T01:34:13Z","isPatch":true,"sender":{"key":"collin.funk1@gmail.com","avatar":"https://avatars.githubusercontent.com/u/65689063?v=4"},"body":"Hi Brad,\n\nYou wrote:\n\n> OpenBSD / NetBSD use HW_PHYSMEM64 to detect the amount of physical\n> memory in a system. HW_PHYSMEM will not provide the correct amount\n> on a system with >=4GB of memory.\n>\n> Signed-off-by: Brad Smith <brad@comstyle.com>\n> ---\n> builtin/gc.c | 4 +++-\n> 1 file changed, 3 insertions(+), 1 deletion(-)\n\nI confirm this patch is correct.\n\nReviewed-by: Collin Funk <collin.funk1@gmail.com>\n\nI also used the following test program:\n\n------------------------------------------------------------------------\n#include <inttypes.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <sys/sysctl.h>\n#define ARRAY_SIZE(array) (sizeof array / sizeof *array)\nint\nmain (void)\n{\n  {\n    unsigned int physmem;\n    size_t len = sizeof physmem;\n    static int mib[2] = { CTL_HW, HW_PHYSMEM };\n    if (!(sysctl (mib, ARRAY_SIZE (mib), &physmem, &len, NULL, 0) == 0\n          && len == sizeof (physmem)))\n      abort ();\n    printf (\"HW_PHYSMEM: %jd\\n\", (intmax_t) physmem);\n  }\n  {\n    int64_t physmem;\n    size_t len = sizeof physmem;\n    static int mib[2] = { CTL_HW, HW_PHYSMEM64 };\n    if (!(sysctl (mib, ARRAY_SIZE (mib), &physmem, &len, NULL, 0) == 0\n          && len == sizeof (physmem)))\n      abort ();\n    printf (\"HW_PHYSMEM64: %jd\\n\", (intmax_t) physmem);\n  }\n  return 0;\n}\n------------------------------------------------------------------------\n\nOn NetBSD 10.0:\n\n    $ ./a.out\n    HW_PHYSMEM: 4294967295\n    HW_PHYSMEM64: 17153662976\n\nOpenBSD 7.6:\n\n    $ ./a.out\n    HW_PHYSMEM: 4286128128\n    HW_PHYSMEM64: 17171030016\n\nThanks for the fix.\n\nCollin\n"},{"id":"519364","messageId":"xmqqr002vr66.fsf@gitster.g","threadId":"63557","inReplyTo":"87h60z6i5o.fsf@gmail.com","subject":"Re: [PATCH] builtin/gc: correct physical memory detection for OpenBSD / NetBSD","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-06-02T02:00:17Z","receivedAt":"2025-06-02T02:00:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Collin Funk <collin.funk1@gmail.com> writes:\n\n> Hi Brad,\n>\n> You wrote:\n>\n>> OpenBSD / NetBSD use HW_PHYSMEM64 to detect the amount of physical\n>> memory in a system. HW_PHYSMEM will not provide the correct amount\n>> on a system with >=4GB of memory.\n>>\n>> Signed-off-by: Brad Smith <brad@comstyle.com>\n>> ---\n>> builtin/gc.c | 4 +++-\n>> 1 file changed, 3 insertions(+), 1 deletion(-)\n>\n> I confirm this patch is correct.\n>\n> Reviewed-by: Collin Funk <collin.funk1@gmail.com>\n\nThanks (also thanks for the online_cpus() one).\n"}]}