Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
21b5abd
feat: add stack-walk and metadata primitives for profiling
jayakasadev Sep 12, 2026
6ffc57e
feat(profile): add heap sampling core behind SNMALLOC_PROFILE
jayakasadev Sep 12, 2026
e92e90a
feat(profile): wire alloc, dealloc and realloc hooks
jayakasadev Sep 12, 2026
4dc6c00
feat(stats): add tiered allocator telemetry
jayakasadev Sep 12, 2026
a2976bb
feat(rust): add profiling APIs and analysis tools
jayakasadev Sep 12, 2026
31cc50c
build: add Bazel, PGO, docs, and CI for profiling
jayakasadev Sep 12, 2026
fb35b5c
Fix sampler weights, refill reseed, slot recycling, and teardown; add…
jayakasadev Dec 2, 2026
68b693b
Fix secondary-storage profiling: indexed store, interior lookup, per-…
jayakasadev Dec 3, 2026
e64f7eb
Make profiler locks fork-safe
jayakasadev Dec 3, 2026
fcbad31
pprof: set drop_frames for allocator entry points; match Mach-O symbo…
jayakasadev Dec 3, 2026
81bb1e3
docs: drop stale benchmark table and verdict; note GWP-ASan and drop_…
jayakasadev Dec 3, 2026
76ffa19
ci: test secondary and refill+secondary profiling builds
jayakasadev Dec 3, 2026
0c53d08
Rename spike headers and namespace; drop plan-numbered names
jayakasadev Dec 3, 2026
5730952
Keep the requested size of secondary samples; test aligned estimates
jayakasadev Dec 3, 2026
c288982
Check the pagemap before asking the secondary allocator; replace the …
jayakasadev Dec 3, 2026
918da40
Call only the sample-holding secondary allocator on the fast path; se…
jayakasadev Dec 3, 2026
c1c60fd
Move refill-sampling hooks out of corealloc.h into inline no-op hooks
jayakasadev Dec 3, 2026
b41cbbc
Share secondary-allocator detection; use address_t for lookups; share…
jayakasadev Dec 3, 2026
01a684a
Release pending samples at thread exit; retire samples freed inside t…
jayakasadev Dec 3, 2026
9978692
rust: strip inlined allocator frames and match hashed Rust names in p…
jayakasadev Dec 3, 2026
cde4045
Fix set_decay_rate docs, rename plan-numbered hooks in tests, tidy be…
jayakasadev Dec 3, 2026
b6bea57
Apply clang-format 15 to files this branch touches
jayakasadev Dec 3, 2026
9fbd407
Fix stats counters on thread exit and remote free; test and CI coverage
jayakasadev Dec 3, 2026
1b40ac1
Fix gcc builds, stats config and pool races; count small objects only
jayakasadev Dec 3, 2026
7e9da40
snmalloc-sys: match frontend counter docs to small-object semantics
jayakasadev Dec 3, 2026
5c26a10
realloc: check the sizeclass before secondary ownership
jayakasadev Dec 3, 2026
6f4c84a
rust_realloc: check the sizeclass before secondary ownership; drop th…
jayakasadev Dec 4, 2026
b6b4d27
docs: add benchmark results for the profiling designs
jayakasadev Dec 4, 2026
5498c68
refill sampling: keep the refill out of the inlined malloc path
jayakasadev Dec 4, 2026
c9a2c1b
secondary store: keep only the pending check inline in allocate
jayakasadev Dec 4, 2026
4a19477
profile: touch sample-node pool pages only as nodes are used
jayakasadev Dec 4, 2026
7b521f0
docs: update benchmark results after the fast-path and pool fixes
jayakasadev Dec 4, 2026
8831dcb
profile: count a drop on every acquire after a failed pool mapping
jayakasadev Dec 4, 2026
89635d9
profile: unmap the node pool without running destructors
jayakasadev Dec 4, 2026
4a447e8
test: release the node acquire returned in the lazy-pool reuse check
jayakasadev Dec 4, 2026
762d4d1
profile: recheck the free list before dropping a sample when fresh no…
jayakasadev Dec 4, 2026
64dcc33
test: tighten the lazy-pool residency bound to the pages handed out
jayakasadev Dec 4, 2026
992c377
profile: say that NodePool::init only reserves storage
jayakasadev Dec 4, 2026
52bacbb
test: keep transparent huge pages off the lazy-pool test mapping
jayakasadev Dec 4, 2026
c52fdc8
test: skip the lazy-pool residency checks when mincore is unavailable
jayakasadev Dec 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ test --test_output=streamed
build:macos --macos_minimum_os=10.15
build:macos --no@fuzztest//fuzztest:use_riegeli

# rust_test writes to stderr; show it so CI failures are diagnosable.
test --test_output=errors

try-import %workspace%/fuzztest.bazelrc
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.2.1
8.7.0
66 changes: 66 additions & 0 deletions .github/workflows/bazel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Bazel build

# Smoke test that the Bazel targets still build alongside the Cargo build.
# Covers the rust_library variants and one rust_test.

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
bazel:
name: bazel build + test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

# bazelisk is the recommended launcher on CI: it uses the version
# pinned by `.bazelversion` or MODULE.bazel, not the system bazel.
- name: Install bazelisk
run: |
BAZELISK_SHA256=5a408715e932c0250d28bd84555f12edbf70117de42f9181691c736eacc4a992
sudo curl -L -o /usr/local/bin/bazel \
https://github.com/bazelbuild/bazelisk/releases/download/v1.29.0/bazelisk-linux-amd64
echo "${BAZELISK_SHA256} /usr/local/bin/bazel" | sha256sum --check -
sudo chmod +x /usr/local/bin/bazel
bazel --version

# Caching lets later runs skip the rules_rust toolchain download
# (~150 MB) and the cmake action. The key includes
# MODULE.bazel.lock, so any dependency bump invalidates the cache.
- name: Cache Bazel
uses: actions/cache@v4
with:
path: |
~/.cache/bazel
key: bazel-${{ runner.os }}-${{ hashFiles('MODULE.bazel.lock', 'MODULE.bazel') }}-${{ github.sha }}
restore-keys: |
bazel-${{ runner.os }}-${{ hashFiles('MODULE.bazel.lock', 'MODULE.bazel') }}-
bazel-${{ runner.os }}-

- name: "Bazel build :: snmalloc-rs Rust library (default)"
run: bazel build //snmalloc-rs:snmalloc_rs

- name: "Bazel build :: snmalloc-sys Rust library (default + profiling)"
run: |
bazel build \
//snmalloc-rs/snmalloc-sys:snmalloc_sys \
//snmalloc-rs/snmalloc-sys:snmalloc_sys_profiling \
//snmalloc-rs/snmalloc-sys:snmalloc_sys_profile_refill_secondary \
//snmalloc-rs:snmalloc_rs_profile_refill_secondary

- name: "Bazel build :: C++ allocator shims"
run: |
bazel build -c opt \
//:snmalloc \
//:snmalloc-profile \
//:snmalloc-rs \
//:snmalloc-rs-profile \
//:snmalloc-rs-profile-refill-secondary

- name: "Bazel test :: snmalloc-rs integration tests"
run: bazel test //snmalloc-rs:all
129 changes: 129 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,48 @@ jobs:
build-type: Release
extra-cmake-flags: "-DSNMALLOC_TRACING=On"
build-only: true
- os: "ubuntu-24.04"
variant: "Profile Build (gcc)"
build-type: Release
extra-cmake-flags: "-DSNMALLOC_PROFILE=ON"
build-only: true
- os: "ubuntu-24.04"
variant: "Profile Build (clang)"
build-type: Release
extra-cmake-flags: >-
-DCMAKE_CXX_COMPILER=clang++
-DSNMALLOC_PROFILE=ON
build-only: true
- os: "ubuntu-24.04"
variant: "Profile Refill Sampling"
build-type: Release
extra-cmake-flags: >-
-DSNMALLOC_PROFILE=ON
-DSNMALLOC_PROFILE_REFILL_SAMPLING=ON
- os: "ubuntu-24.04"
variant: "Profile Secondary Storage"
build-type: Release
extra-cmake-flags: >-
-DSNMALLOC_PROFILE=ON
-DSNMALLOC_PROFILE_SECONDARY_STORAGE=ON
- os: "ubuntu-24.04"
variant: "Profile Refill + Secondary"
build-type: Release
extra-cmake-flags: >-
-DSNMALLOC_PROFILE=ON
-DSNMALLOC_PROFILE_REFILL_SECONDARY=ON
- os: "ubuntu-24.04"
variant: "Profile + Full Stats"
build-type: Release
extra-cmake-flags: >-
-DSNMALLOC_PROFILE=ON
-DSNMALLOC_STATS_FULL=ON
- os: "ubuntu-24.04"
variant: "Basic Stats gcc"
build-type: Release
extra-cmake-flags: >-
-DSNMALLOC_STATS_BASIC=ON
-DCMAKE_CXX_COMPILER=g++-14
- os: "ubuntu-22.04"
variant: "clang libstdc++ (Build only)"
build-type: Release
Expand Down Expand Up @@ -125,6 +167,30 @@ jobs:
dependencies: "sudo apt install -y ninja-build libc++-dev"
test-exclude-pattern: "memcpy|external_pointer"
test-extra-args: "--repeat-until-fail 2"
# Heap-profiling paths under ThreadSanitizer. Uses libc++ because
# TSan needs an instrumented C++ runtime and Ubuntu's libstdc++ is
# not instrumented. `-R profile_` limits the run to the profile
# tests, keeping sanitizer overhead inside the CI budget.
- os: "ubuntu-24.04"
variant: "Profile + TSan (clang)"
build-type: "Debug"
extra-cmake-flags: >-
-DSNMALLOC_PROFILE=ON
-DSNMALLOC_SANITIZER=thread
-DCMAKE_CXX_COMPILER=clang++
-DCMAKE_CXX_FLAGS=-stdlib="libc++ -g"
dependencies: "sudo apt install -y ninja-build libc++-dev"
test-extra-args: "-R profile_"
# Heap-profiling paths under AddressSanitizer. ASan works with
# libstdc++, so ninja is the only extra dependency.
- os: "ubuntu-24.04"
variant: "Profile + ASan (clang)"
build-type: "Debug"
extra-cmake-flags: >-
-DSNMALLOC_PROFILE=ON
-DSNMALLOC_SANITIZER=address
-DCMAKE_CXX_COMPILER=clang++
test-extra-args: "-R profile_"
uses: ./.github/workflows/reusable-cmake-build.yml
with:
os: ${{matrix.os}}
Expand Down Expand Up @@ -190,6 +256,11 @@ jobs:
build-type: Release
extra-cmake-flags: "-DSNMALLOC_ENABLE_PAC=ON"
variant: "PAC"
# Profile build with heap profiling support enabled
- os: "macos-15"
build-type: Release
extra-cmake-flags: "-DSNMALLOC_PROFILE=ON"
variant: "Profile Build (clang)"
uses: ./.github/workflows/reusable-cmake-build.yml
with:
os: ${{matrix.os}}
Expand Down Expand Up @@ -474,6 +545,63 @@ jobs:
cd ${{github.workspace}}/build
ctest --parallel --output-on-failure

# ============================================================================
# Profile + PGO (clang) — two-stage profile-guided optimization build
#
# Runs scripts/run-pgo-build.sh: stage 1 builds an instrumented snmalloc
# plus func-profile_overhead-fast and runs it to produce .profraw data,
# llvm-profdata merges that, and stage 2 rebuilds with
# -fprofile-use=<merged.profdata>. The resulting libsnmallocshim-rust.a is
# uploaded so downstream consumers can use the PGO-optimized archive.
#
# Linux only. On macOS the profraw format is pinned per Xcode image, which
# would force a re-merge on every runner upgrade; run
# scripts/run-pgo-build.sh locally instead.
#
# LLVM 19 matches COMPILER_RT_LLVM_VERSION at the top of this file and the
# coverage.yml job, so the raw-profile format is the same across CI jobs.
# ============================================================================
pgo:
name: Profile + PGO (clang)
runs-on: ubuntu-24.04
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: Install clang-19 + llvm-19 + ninja
run: |
sudo apt-get update
sudo apt-get install -y ninja-build clang-19 llvm-19
- name: Run two-stage PGO build
env:
# Absolute paths under the runner workspace, so the upload step
# below finds the artifacts wherever the script's repo_root lands.
CC: clang-19
CXX: clang++-19
PGO_STAGE1_DIR: ${{ github.workspace }}/build-pgo-gen
PGO_STAGE2_DIR: ${{ github.workspace }}/build-pgo-use
PGO_PROFILE_DATA_DIR: ${{ github.workspace }}/build-pgo-gen/pgo-data
PGO_PROFILE_FILE: ${{ github.workspace }}/build-pgo-gen/pgo.profdata
# SNMALLOC_RUST_SUPPORT=ON produces libsnmallocshim-rust.a in the
# stage-2 build directory, which is the artifact uploaded below.
# Name the clang binaries explicitly so configure does not fall
# back to the system gcc.
PGO_EXTRA_CMAKE_FLAGS: >-
-G Ninja
-DSNMALLOC_RUST_SUPPORT=ON
-DCMAKE_C_COMPILER=clang-19
-DCMAKE_CXX_COMPILER=clang++-19
run: scripts/run-pgo-build.sh
- name: Verify PGO artifact
run: |
ls -l "${{ github.workspace }}/build-pgo-use/libsnmallocshim-rust.a"
- name: Upload PGO artifact (libsnmallocshim-rust.a)
uses: actions/upload-artifact@v4
with:
name: pgo-libsnmallocshim-rust-linux-x64
path: ${{ github.workspace }}/build-pgo-use/libsnmallocshim-rust.a
if-no-files-found: error
retention-days: 14

# ============================================================================
# vcpkg integration
# ============================================================================
Expand Down Expand Up @@ -559,6 +687,7 @@ jobs:
qemu-crossbuild,
windows,
format,
pgo,
vcpkg-integration
]
runs-on: ubuntu-24.04
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,69 @@ jobs:
- name: Run tests
run: cargo +${{ matrix.rust }} test -p snmalloc-rs ${{ matrix.args }}

# ============================================================================
# Heap-profiling feature build
#
# Exercises the `profiling` cargo feature, which makes snmalloc-sys pass
# SNMALLOC_PROFILE=ON to the C++ build. Linux and macOS only, matching
# where the C++ matrix covers the profile code paths.
# ============================================================================
profiling:
runs-on: ${{ matrix.os }}
name: "profiling-${{ matrix.os }}-${{ matrix.release.name }}"
defaults:
run:
shell: bash
working-directory:
./snmalloc-rs
strategy:
matrix:
os: [ubuntu-latest, macos-14, macos-15]
rust: [stable]
release:
- name: release
flag: "--release"
- name: debug
flag: ""
fail-fast: false
steps:
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
- name: Checkout
uses: actions/checkout@v4
- name: update dependency
run: |
if bash -c 'uname -s | grep 'Linux' >/dev/null'; then
sudo apt-get update -y && sudo apt-get --reinstall install -y libc6-dev
fi
shell: bash
- name: Build (profiling)
run: cargo build ${{ matrix.release.flag }} --verbose --features profiling
- name: Run tests (profiling)
run: cargo test ${{ matrix.release.flag }} --all --features profiling
- name: Run tests (profile-refill-sampling)
run: cargo test ${{ matrix.release.flag }} -p snmalloc-rs --features profile-refill-sampling
- name: Run tests (profile-secondary-storage)
run: cargo test ${{ matrix.release.flag }} -p snmalloc-rs --features profile-secondary-storage
- name: Run tests (profile-refill-secondary)
run: cargo test ${{ matrix.release.flag }} -p snmalloc-rs --features profile-refill-secondary
- name: Run tests (profiling, symbolicate)
run: cargo test ${{ matrix.release.flag }} -p snmalloc-rs --features profiling,symbolicate
- name: Run tests (profile-refill-secondary, symbolicate)
run: cargo test ${{ matrix.release.flag }} -p snmalloc-rs --features profile-refill-secondary,symbolicate
- name: Run tests (stats-full)
run: cargo test ${{ matrix.release.flag }} -p snmalloc-rs --features stats-full
- name: Run tests (profiling, stats-full)
run: cargo test ${{ matrix.release.flag }} -p snmalloc-rs --features profiling,stats-full
- name: Run tests (profile-refill-secondary, stats-full)
run: cargo test ${{ matrix.release.flag }} -p snmalloc-rs --features profile-refill-secondary,stats-full
- name: Build benches
run: |
cargo bench --no-run -p snmalloc-rs
cargo bench --no-run -p snmalloc-rs --features profiling
cargo bench --no-run -p snmalloc-rs --features profile-refill-sampling

publish-scan:
runs-on: ubuntu-latest
name: publish-scan
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@
# rust target
/target
/PLAN.md

# bazel convenience symlinks (created in the workspace root by `bazel
# build` / `bazel test`). The actual outputs live under the user's
# bazel cache so the symlinks are pure noise on commit.
/bazel-*

# root workspace lock file
/Cargo.lock
Loading
Loading