git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3] builtin/gc: correct total_ram calculation with HAVE_BSD_SYSCTL

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 2, 2025, 22:59 UTC
Message-ID
<xmqq1pqyci6o.fsf@gitster.g>
In-Reply-To
<ep4q5xwbys4qwpkmmo5jujzjorrb24v5na4yuwpjr5owojwk2q@omb7xpp4oov5>
Carlo Marcelo Arenas Belón <carenas@gmail.com> writes:
Show 9 quoted lines
>> > +			physical_memory <<= bits;
>> > +			physical_memory >>= bits;
>> 
>> I do not quite understand this version.  Does the correctness of
>> this depend on the machine having a certain byte-order?  
> ...
> the shifting was meant to be a cooler way to get those bits cleared,
> because I thought that relying in the initialization wasn't as cool
> from the previous comments.
I more often have seen a pattern like
	physical_memory &= ((1U << bits) - 1);
for clearing the upper bits, but that's fine.
> a fixed version of this, would allow at least a better return, and
> because most of the extra work is only needed in Big Endian (which
> could only affect Power) then it is almost a free upgrade.

OK. As this is not a performance-critical operation anyway, I am perfectly OK with the dumb "we ask for 8 and be happy if the answer is 8 bytes long. Otherwise if the answer is 4, we prepare a u32 and ask again with 4; other "possible" answer width like 2 or 6 are probably not worth worrying about" ;-).

Thanks.
Previous: Carlo Marcelo Arenas BelónNext: Carlo Marcelo Arenas Belón
Message 11 of 15 in “builtin/gc: improve total_ram calculation for HAVE_BSD_SYSCTL”
  1. builtin/gc: improve total_ram calculation for HAVE_BSD_SYSCTLCarlo Marcelo Arenas Belón, Jul 2, 2025
  2. Patrick SteinhardtJul 2, 2025
  3. Carlo Marcelo Arenas BelónJul 2, 2025
  4. builtin/gc: protect against sysctl() failure in total_ramCarlo Marcelo Arenas Belón, Jul 2, 2025
  5. Junio C HamanoJul 2, 2025
  6. Carlo Marcelo Arenas BelónJul 2, 2025
  7. Junio C HamanoJul 2, 2025
  8. builtin/gc: correct total_ram calculation with HAVE_BSD_SYSCTLCarlo Marcelo Arenas Belón, Jul 2, 2025
  9. Junio C HamanoJul 2, 2025
  10. Carlo Marcelo Arenas BelónJul 2, 2025
  11. Junio C HamanoJul 2, 2025
  12. builtin/gc: correct total_ram calculation with HAVE_BSD_SYSCTLCarlo Marcelo Arenas Belón, Jul 3, 2025
  13. Junio C HamanoJul 7, 2025
  14. builtin/gc: correct total_ram calculation with HAVE_BSD_SYSCTLCarlo Marcelo Arenas Belón, Jul 7, 2025
  15. Junio C HamanoJul 7, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.