Repository navigation
Heap profiling - #910
Closed
Jaya Kasa (jayakasadev) wants to merge 40 commits into
Closed
Heap profiling#910Jaya Kasa (jayakasadev) wants to merge 40 commits into
Jaya Kasa (jayakasadev) wants to merge 40 commits into
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
… regression tests
…Config sample routing
…frames; restore alloc_free_list comment
…store's address range with a granule filter
…rve a chain member's pending sample first
… profiler page mapping; trim aligned large samples
…prof and CallSite
…nch variant names
- Per-size-class counters are now two monotone counts per thread, and the snapshot sums every allocator in the pool. The old teardown drain into a global could double-count or drop a thread, and the derived cumulative_alloc fell when an owner received remote frees. - Snapshot clamps peak >= in use and mapped >= committed. - snmalloc-sys rebuilds when the C++ sources change. - Tests: regression tests for the above, DROP_FRAMES and hashed crate names; serialise tests that change the global sampling rate or read global counters. - CI: symbolicate and stats-full Rust steps, a full-stats CMake config. - Docs: bench README and sanitizer claims match the code.
- freelist count() is a plain member again, so gcc and newer clang build the default config. - Remote-dealloc stats move into dealloc_remote's success paths, so free(NULL) is not counted and the read-only default allocator is never written. - snmalloc_get_full_stats is built once per library after the library picks its config, so profile builds of the C/C++ shims read the right allocator. - AllocPool::iterate reads the list head under the pool lock. - The frontend alloc and dealloc counters cover small objects only. - subtract_request clamps instead of branching, which gcc's -Wstringop-overflow otherwise flags in profile Release builds. - Tests: shim stats regression, concurrent snapshot under TSan, large object and free(NULL) checks, subtract_request saturation. - CI: gcc basic-stats job; secondary-storage Rust stats step.
With the default pass-through secondary this keeps realloc's codegen identical to upstream.
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.
What
Adds opt-in heap profiling (
SNMALLOC_PROFILE), allocator stats (SNMALLOC_STATS_BASIC/SNMALLOC_STATS_FULL), Rust APIs withpprofand flamegraph output (snmalloc-rs), and CLI analysis tools (snmalloc-tools) for #853.Everything is off by default. When off, profiling hooks compile away and stats take 0 bytes.
Includes four profiling modes to compare two choices:
SNMALLOC_PROFILE_REFILL_SAMPLING)SNMALLOC_PROFILE_SECONDARY_STORAGE)Organized into 6 commits: core primitives, profiling core, stats, allocator hooks, Rust/tools, and build/CI/docs.
Why
Users need a way to see which call stacks allocate memory and how the allocator is behaving, without slowing down normal builds. Comparing all four modes side by side shows which design is cheapest before splitting the winner into small upstream PRs on #853.
Cost
Measured on Apple M4 Pro (macOS,
Release, 1 thread, 32 B objects, 512 KiB sampling, 10 runs, mean ± 95% CI). Full tables indocs/heap-profiling-experimental.md.Test plan
Run on macOS arm64 against the final tree (
bf6aa13):Release,-fastand-checktests): 8 configs (off, all 4 profiling modes, basic stats, full stats, profile + full stats) —141/141ctesteachDebug): 3 configs (profile, refill + side heap, profile + full stats) —42/42profile_|fast_path|statisticstests each,0warningssnmalloc-rs):22/22dev + releasecargo testruns across 11 feature sets,0warningsbazel test //snmalloc-rs:all—10/10clang-format 15.0.7andcargo fmt --checkcleanDebugctest, Windows, CHERI, and Rust 1.100allocator-api