Skip to content

fix(foundation): use HW_PHYSMEM for physical memory detection on FreeBSD#1093

Open
PR9000 wants to merge 1 commit into
DeusData:mainfrom
PR9000:freebsd-hw-physmem
Open

fix(foundation): use HW_PHYSMEM for physical memory detection on FreeBSD#1093
PR9000 wants to merge 1 commit into
DeusData:mainfrom
PR9000:freebsd-hw-physmem

Conversation

@PR9000

@PR9000 PR9000 commented Jul 15, 2026

Copy link
Copy Markdown

What does this PR do?

This PR fixes physical memory detection on FreeBSD by using the standard HW_PHYSMEM sysctl in detect_system_bsd().

On FreeBSD 15.1-STABLE, the current implementation using HW_PHYSMEM64 does not return the expected physical memory size during system initialization. This change routes FreeBSD through the existing HW_PHYSMEM code path already used by OpenBSD.

Changes

  • Updated src/foundation/system_info.c.
  • Extended the BSD-specific condition:
#if defined(__OpenBSD__)

to:

#if defined(__OpenBSD__) || defined(__FreeBSD__)

so FreeBSD uses HW_PHYSMEM for physical memory detection.

Testing

Tested on FreeBSD 15.1-STABLE (amd64).

Validation performed:

  • Successfully built codebase-memory-mcp using:
gmake -f Makefile.cbm cbm
  • Successfully ran the CI linters:
gmake -f Makefile.cbm lint-ci CLANG_FORMAT=clang-format21

Result:

=== cppcheck ===
=== clang-format ===
=== NOLINT check ===
=== CI linters passed ===
  • Verified that the detected physical memory size is reported correctly after this change.

The test suite was also executed:

gmake -f Makefile.cbm test

However, the test build currently fails during linking with an unrelated AddressSanitizer duplicate symbol error:

duplicate symbol: bsearch
>>> defined at asan_interceptors.cpp
>>> defined at internal/cbm/vendored/grammars/perl/bsearch.h

This failure is independent from this change and occurs in the test infrastructure/linking stage before the tests are executed.

Why this is safe

This is a small, localized, platform-specific change affecting only the FreeBSD BSD implementation path.

Linux, macOS, Windows, and other supported platforms are unaffected. The change reuses the existing HW_PHYSMEM implementation already used for OpenBSD and does not modify the behavior of other operating systems.

Checklist

  • Every commit is signed off (git commit -s) — required, CI rejects unsigned commits ([DCO](../DCO), see [CONTRIBUTING.md](../CONTRIBUTING.md))
  • Tests pass locally (make -f Makefile.cbm test)
  • Lint passes (make -f Makefile.cbm lint-ci)
  • New behavior is covered by a test (reproduce-first for bug fixes)

Signed-off-by: Pedro Ramos <131530838+pr9000@users.noreply.github.com>
@PR9000 PR9000 requested a review from DeusData as a code owner July 15, 2026 00:48
@DeusData DeusData added bug Something isn't working stability/performance Server crashes, OOM, hangs, high CPU/memory priority/high Needs near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker. labels Jul 15, 2026
@DeusData DeusData added this to the 0.9.1-rc milestone Jul 15, 2026
@DeusData

Copy link
Copy Markdown
Owner

Thanks for the focused FreeBSD fix and the on-platform validation. FreeBSD's current sys/sysctl.h defines HW_PHYSMEM for this MIB and not HW_PHYSMEM64, so the direction is correct. I have triaged this as a high-priority 0.9.1-rc stability bug. The one-line diff adds no dependency, network, secret, or broader runtime surface.

The remaining blocker is the repository's reproduce-first requirement: the PR currently has no automated guard that fails on main. Because the normal matrix has no FreeBSD runner, please add the smallest testable regression or propose a narrow test seam for the MIB-selection contract before changing CI. Do not add a new workflow or dependency without design approval. The unrelated Perl/ASan duplicate-symbol problem should stay outside this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working priority/high Needs near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker. stability/performance Server crashes, OOM, hangs, high CPU/memory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants