Expose memory usage statistics to Rust via SnMalloc::memory_stats()#851
Open
jayakasadev wants to merge 2 commits into
Open
Expose memory usage statistics to Rust via SnMalloc::memory_stats()#851jayakasadev wants to merge 2 commits into
jayakasadev wants to merge 2 commits into
Conversation
Wire up the existing `sn_rust_statistics` C export (already present in rust.cc) to Rust. Adds an FFI binding in snmalloc-sys and a safe `SnMalloc::memory_stats()` associated function in snmalloc-rs that returns an `AllocStats` struct with current and peak OS-level memory reservation figures tracked by StatsRange. No C++ changes required — the backend counters are always active.
711d987 to
2be87e1
Compare
…dealloc reduction
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
AllocStats { current_memory_usage, peak_memory_usage }tosnmalloc-rsSnMalloc::memory_stats() -> AllocStatsassociated functionsn_rust_statisticsinsnmalloc-sysNo C++ changes were required —
sn_rust_statisticsalready existed inrust.ccandStatsRangecounters are always active regardless of thestatsbuild feature.The returned values are OS-level memory reservation figures at slab/chunk granularity (tracked atomically by
StatsRange), not the sum of individual live allocation sizes.Usage
Test plan
cargo test --package snmalloc-rs— 7/7 tests pass including newtest_memory_statstest_memory_statsallocates 1 MiB, verifies current/peak are non-decreasing after allocation, and that peak never decreases after free