git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Collin Funk <collin.funk1@gmail.com>
To: Brad Smith <brad@comstyle.com>, git@vger.kernel.org
Subject: Re: [PATCH] builtin/gc: correct physical memory detection for OpenBSD / NetBSD
Date: Sun, 01 Jun 2025 18:34:11 -0700	[thread overview]
Message-ID: <87h60z6i5o.fsf@gmail.com> (raw)

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

             reply	other threads:[~2025-06-02  1:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-02  1:34 Collin Funk [this message]
2025-06-02  2:00 ` [PATCH] builtin/gc: correct physical memory detection for OpenBSD / NetBSD Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2025-06-01  8:24 Brad Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h60z6i5o.fsf@gmail.com \
    --to=collin.funk1@gmail.com \
    --cc=brad@comstyle.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).