Repository navigation
Phase 11.9: combined-counter approach for dealloc-side stats - #62
Merged
Merged
Conversation
Mirrors the Phase 11.8 batched-counter pattern on the dealloc side: drop the per-dealloc `stats.fast_path_deallocs++` store at the local-owner branch of `Allocator::dealloc` and pre-credit `stats.fast_path_deallocs += refill_count` at slab refill in `small_refill` / `small_refill_slow`. Each object placed onto the fast free list is assumed to be freed locally; cross-thread frees still bump `remote_deallocs` per-object, so the granting thread's `fast_path_deallocs` is over-credited by the count of objects freed by another thread (drift is bounded by program behaviour and documented on the field). The `frontend_stats.rs::fast_path_alloc_counter_grows` test now measures the cumulative dealloc count against the `before` snapshot rather than `after_alloc`, since the credit lands at slab-grant time (before the explicit dealloc loop) -- same end-to-end invariant, just a different measurement window. Apples-to-apples 2-run mean on the same host vs the 11.8 baseline at HEAD: small_allocs: 0.9960 (11.8) -> 1.0006 (11.9), both PASS medium_allocs: 1.0616 (11.8) -> 1.0611 (11.9), both FAIL mixed: 1.0271 (11.8) -> 1.0244 (11.9), both FAIL The dealloc store is gone but `medium_allocs` did not close -- the residual ~5-6% on this host is not store-bound; the bench ratio for medium_allocs is unchanged between 11.8 and 11.9. Likely candidates are bytes_in_use atomics on the slab refill path and codegen differences between OFF and BASIC compiles. Closing that gap requires either a sampled-counter tier or spec relaxation; tracked in docs/heap-profiling-benchmarks.md (Phase 11.9 section).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
stats.fast_path_deallocs++store at the local-owner branch ofAllocator::deallocis removed;stats.fast_path_deallocs += refill_countis pre-credited at the existing Phase 11.8 sites insmall_refill/small_refill_slow.Bench results (apples-to-apples 2-run mean on same host)
small_allocsmedium_allocsmixedA separate 5-run BASIC-only sweep showed
small_allocs0.9986,medium_allocs1.0530,mixed1.0272.Acceptance verdict: PARTIAL
small_allocs-- PASS (already PASS at 11.8; no regression).medium_allocs-- still FAIL at ~1.06 on this host. Critically, the 11.8 baseline on the same host also sits at 1.062 (the original 1.020 doc figure does not reproduce on the present hardware state). The dealloc store is gone but the bench needle did not move on this group, so the residual is not store-bound -- most likely it is thebytes_in_useatomics on the slab-refill path and/or codegen differences between OFF and BASIC builds.mixed-- still FAIL but improves marginally (1.0271 -> 1.0244) because half of the mixed-size distribution routes through small-class allocs/frees which now pays one fewer store per local free.The
frontend_stats.rs::fast_path_alloc_counter_growstest was adjusted to measure the cumulative dealloc count against thebeforesnapshot (rather thanafter_alloc), since the credit now lands at slab-grant time before the explicit dealloc loop.Recommendation
Ship Phase 11.9 as the correct symmetric counterpart to Phase 11.8 (no regressions, marginal mixed improvement, cleaner dealloc hot path), and treat the remaining
medium_allocs/mixedgap as fundamental to the BASIC tier on this hardware. Closing it further is a different lever:SNMALLOC_STATS_SAMPLEDtier (count 1/K allocs+deallocs, multiply at query) -- could approach 1.005.medium_allocs/mixed, since the small-class path now meets the strict bar.Filing a follow-up ticket is not recommended at this point -- batching + combined counters are exhausted as levers.
ClickUp
Test plan
cmake -B build -DSNMALLOC_STATS_BASIC=ON && cmake --build build -j4(100% target build)cmake -B build-off -DSNMALLOC_STATS_BASIC=OFF && cmake --build build-off -j4 --target snmallocshim(off-tier build also clean)cargo test --features stats-basic(all 33+ test binaries pass;frontend_statsboth cases PASS)cargo bench --features stats-basic --bench stats_bench5-run sweep + apples-to-apples 2-run A/B vs 11.8 baseline at HEAD