Skip to content

Phase 11.10: diagnose + pad backend atomics for false-sharing - #63

Merged
jayakasadev merged 1 commit into
mainfrom
feature/phase-11-10-diagnose-basic-overhead
Jun 12, 2026
Merged

Phase 11.10: diagnose + pad backend atomics for false-sharing#63
jayakasadev merged 1 commit into
mainfrom
feature/phase-11-10-diagnose-basic-overhead

Conversation

@jayakasadev

Copy link
Copy Markdown
Owner

Summary

  • Root-cause hypothesis for the residual SNMALLOC_STATS_BASIC overhead on medium_allocs (~1.05) and mixed (~1.03): false-sharing on process-global backend atomics
  • Two locations: BackendFragCounters (bytes_committed + bytes_decommitted_to_os) and StatsRange::Type (current_usage + peak_usage)
  • Applied alignas(64) to each atomic so each lives on its own cache line

ClickUp

  • 86aj11nwy

Test plan

  • cmake build clean with -DSNMALLOC_STATS_BASIC=ON -DCMAKE_BUILD_TYPE=Release
  • cargo bench --features stats-basic --bench stats_bench — bench validation deferred (predecessor agent budget exhausted mid-bench); to be re-run after merge to verify the medium_allocs / mixed drop
  • No functional change — atomics are unchanged in semantics, only placed in their own cache lines

Diagnostic

Full write-up: docs/heap-profiling-diagnostic-11-10.md. Cost of padding: ~96 bytes BSS per template instantiation. Correctness unaffected.

Follow-up if bench shows no improvement

File Phase 11.11 — disassembly diff (objdump -d) BASIC vs OFF on Allocator<...>::alloc to identify the actual hot-path delta. False-sharing was the highest-probability hypothesis; if disproved, codegen drift is next.

`BackendFragCounters::bytes_committed` + `bytes_decommitted_to_os`
shared a cache line, as did `StatsRange::current_usage` +
`peak_usage`. Every `notify_using` invalidated the line that the
matching `notify_not_using` had just read, and the
`current_usage`/`peak_usage` CAS dance bounced the line for no
reason.

Add `alignas(64)` to each global atomic so each lives on its own
cache line. Cost: ~96 bytes of additional BSS per template
instantiation. Correctness unchanged.

Diagnostic write-up + recommended next steps in
docs/heap-profiling-diagnostic-11-10.md.
@jayakasadev
jayakasadev merged commit f3ee3a1 into main Jun 12, 2026
16 of 211 checks passed
@jayakasadev
jayakasadev deleted the feature/phase-11-10-diagnose-basic-overhead branch June 12, 2026 19:06
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.

1 participant