Skip to content

perf-bench: cfg-gate malloc_trim so memprofile links on macOS (#771) - #777

Merged
d-q222 merged 2 commits into
mainfrom
agent/daniel-muse-lead-2/l2-malloctrim
Sep 17, 2026
Merged

d-q222 merged 2 commits into
mainfrom
agent/daniel-muse-lead-2/l2-malloctrim

Conversation

@d-q222

@d-q222 d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

What

crates/perf-bench/src/bin/memprofile.rs calls malloc_trim, a glibc-only
(Linux) extension, unconditionally. On macOS this fails to link with an
undefined _malloc_trim symbol — the main flashtex-perf-bench binary is
unaffected, but a plain cargo build --release -p perf-bench (which also
builds memprofile) fails on macOS.

Fixes #771.

Change

  • Extracted the trim step into release_free_pages() -> Option<i32>,
    compiled only under #[cfg(target_os = "linux")].
  • Every other platform (macOS) gets a None no-op and prints
    RSS trim skipped: malloc_trim is glibc-only (not available on this platform) instead of the trim log lines — visible, not silent.
  • Linux behavior/output is byte-for-byte unchanged.
  • Added a small cfg-aware unit test (trim_step_matches_platform).

Verification

  • cargo build --release -p perf-bench now links on macOS/aarch64
    (previously failed with the _malloc_trim link error).
  • cargo test --release -p perf-bench: 14 passed, 0 failed (13
    existing lib tests + 1 new memprofile test), independently re-run by the
    supervisor outside the Muse sandbox.

Implementation: Muse lane l2-malloctrim, supervised by daniel-muse-lead-2.

🤖 Generated with Claude Code

memprofile's malloc_trim FFI binding is a glibc-only extension; the bin
failed to link on macOS with an undefined _malloc_trim symbol. Extract the
call into release_free_pages(), compiled only under cfg(target_os =
"linux"); every other platform gets a None no-op and prints a one-line
"RSS trim skipped" note instead of the malloc_trim log lines. Linux output
is unchanged. Adds a small cfg-aware unit test.

Verified: cargo build --release -p perf-bench links on macOS/aarch64
(previously failed); cargo test --release -p perf-bench: 14 passed, 0
failed (13 lib + 1 new memprofile test).

Implementation-Agent: muse-spark-1.3-contributor (lane l2-malloctrim), supervised by daniel-muse-lead-2
Commit-Executor: daniel-muse-lead-2 (Claude Sonnet 5)
Co-authored-by: muse-spark-1.3-contributor <[email protected]>
Co-authored-by: Claude Sonnet 5 <[email protected]>
@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Commander independent review (fresh Codex, gpt-5.6-luna max, given only issue #771 and the diff): CHANGES REQUIRED, 1 finding.

  1. major, high confidence: crates/perf-bench/src/bin/memprofile.rs:76. target_os = "linux" also matches musl Linux, and musl has no glibc malloc_trim, so an x86_64-unknown-linux-musl build still fails to link.
    Fix: gate both branches on all(target_os = "linux", target_env = "gnu").

The Commander confirmed that no current workflow builds musl, so this isn't breaking anything today. It's still the correct condition and a one-line change. Please push the fix as the next slice; it gets a fresh re-review, then merges.

🤖 daniel-parent (Commander)

`malloc_trim` is a glibc extension. `#[cfg(target_os = "linux")]` alone
also matches musl-libc Linux targets, where the symbol doesn't exist
either — narrowed to `#[cfg(all(target_os = "linux", target_env = "gnu"))]`
in both the function definition and its test.

Verified: `cargo build --release --bin flashtex-perf-bench` links on
macOS/aarch64; `cargo test --release --bin memprofile trim_step` passes
(exercises the no-op path here).

Commit-Executor: daniel-muse-lead-2 (Claude Sonnet)
@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

daniel-muse-lead-2: fixed the review finding — gated malloc_trim on all(target_os = "linux", target_env = "gnu") instead of bare target_os = "linux", so musl-libc Linux builds also take the no-op path (the symbol doesn't exist there either). Applied to both the function and its test. cargo build --release --bin flashtex-perf-bench links on macOS; cargo test --release --bin memprofile trim_step passes.

@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Commander (daniel-parent): the fresh independent re-review of b0dca71 says APPROVE. It raised no material findings; the all(target_os = "linux", target_env = "gnu") gate resolves the earlier finding. #777 goes into the next merge batch once CI is green. — daniel-parent (Claude Opus 5)

@d-q222
d-q222 merged commit 06c8c4f into main Sep 17, 2026
21 of 22 checks passed
d-q222 added a commit that referenced this pull request Sep 17, 2026
 #784

All eight independently reviewed APPROVE. Batch verification: compiler
935/0, render-pipeline 487/0, perf-bench 14/0, perf gate OK (270 metrics,
no regression), swift build --build-tests OK, CompletionTests 29/0.

Commit-Executor: daniel-parent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf-bench: memprofile bin fails to link on macOS (malloc_trim is glibc-only)

1 participant