# Re: [PATCH] builtin/gc: correct physical memory detection for OpenBSD / NetBSD

2 messages from 2025-06-02 to 2025-06-02. Participants: Collin Funk, Junio C Hamano.
Thread: https://gitlist.dev/t/63557

## Collin Funk, 2025-06-02 01:34

Subject: Re: [PATCH] builtin/gc: correct physical memory detection for OpenBSD / NetBSD
Message-ID: <87h60z6i5o.fsf@gmail.com>
URL: https://gitlist.dev/e/87h60z6i5o.fsf%40gmail.com

```
Hi Brad,

You wrote:

> OpenBSD / NetBSD use HW_PHYSMEM64 to detect the amount of physical
> memory in a system. HW_PHYSMEM will not provide the correct amount
> on a system with >=4GB of memory.
>
> Signed-off-by: Brad Smith <brad@comstyle.com>
> ---
> builtin/gc.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)

I confirm this patch is correct.

Reviewed-by: Collin Funk <collin.funk1@gmail.com>

I also used the following test program:

------------------------------------------------------------------------
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/sysctl.h>
#define ARRAY_SIZE(array) (sizeof array / sizeof *array)
int
main (void)
{
  {
    unsigned int physmem;
    size_t len = sizeof physmem;
    static int mib[2] = { CTL_HW, HW_PHYSMEM };
    if (!(sysctl (mib, ARRAY_SIZE (mib), &physmem, &len, NULL, 0) == 0
          && len == sizeof (physmem)))
      abort ();
    printf ("HW_PHYSMEM: %jd\n", (intmax_t) physmem);
  }
  {
    int64_t physmem;
    size_t len = sizeof physmem;
    static int mib[2] = { CTL_HW, HW_PHYSMEM64 };
    if (!(sysctl (mib, ARRAY_SIZE (mib), &physmem, &len, NULL, 0) == 0
          && len == sizeof (physmem)))
      abort ();
    printf ("HW_PHYSMEM64: %jd\n", (intmax_t) physmem);
  }
  return 0;
}
------------------------------------------------------------------------

On NetBSD 10.0:

    $ ./a.out
    HW_PHYSMEM: 4294967295
    HW_PHYSMEM64: 17153662976

OpenBSD 7.6:

    $ ./a.out
    HW_PHYSMEM: 4286128128
    HW_PHYSMEM64: 17171030016

Thanks for the fix.

Collin

```

## Junio C Hamano, 2025-06-02 02:00

Subject: Re: [PATCH] builtin/gc: correct physical memory detection for OpenBSD / NetBSD
Message-ID: <xmqqr002vr66.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqr002vr66.fsf%40gitster.g
In-Reply-To: <87h60z6i5o.fsf@gmail.com>

```
Collin Funk <collin.funk1@gmail.com> writes:

> Hi Brad,
>
> You wrote:
>
>> OpenBSD / NetBSD use HW_PHYSMEM64 to detect the amount of physical
>> memory in a system. HW_PHYSMEM will not provide the correct amount
>> on a system with >=4GB of memory.
>>
>> Signed-off-by: Brad Smith <brad@comstyle.com>
>> ---
>> builtin/gc.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> I confirm this patch is correct.
>
> Reviewed-by: Collin Funk <collin.funk1@gmail.com>

Thanks (also thanks for the online_cpus() one).

```
