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

Re: [PATCH] builtin/gc: improve total_ram calculation for HAVE_BSD_SYSCTL

From
Carlo Marcelo Arenas Belón <carenas@gmail.com>
Date
Jul 2, 2025, 17:04 UTC
Message-ID
<372xg2ktahmd2whngeqitkotdez4zy7irvabns6bgkr3mdqiab@aeuofua6j7ya>
In-Reply-To
<aGVO3ej7bEo5swih@pks.im>
On Wed, Jul 02, 2025 at 05:23:09PM -0800, Patrick Steinhardt wrote:
Show 15 quoted lines
> On Wed, Jul 02, 2025 at 07:42:44AM -0700, Carlo Marcelo Arenas Belón wrote:
> > In BSD systems other than macOS, since 9806f5a7bf (gc --auto:
> > exclude base pack if not enough mem to "repack -ad", 2018-04-15),
> > sysctl() use HW_PHYSMEM with the wrong size for the target.
> > 
> > Use the correct type for physical_memory on each option and make
> > sure it is initialized, so it is safe to use even if sysctl() fails.
> 
> We don't use it though when sysctl(3) fails, do we? We only return
> `physical_memory` in case sysctl(3) returned zero, which indicates
> success. Which raises the question whether that function ever returns a
> zero value without writing the value to the pointer.
> 
> Not that it would really hurt to initialize the value, but I found this
> explanation to be puzzling.

Correct; the issue I was trying to address with the initialization was that the function would return 0, but if there is a size mismatch between the variable used and the size of HW_PHYSMEM then the other half of the variable was used uninitialized.

Initializing it, "solves" the problem by making sure that (at least in little endian) boxes the result was still valid.

Carlo
Previous: Patrick SteinhardtNext: Carlo Marcelo Arenas Belón
Message 3 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.