Skip to content

feat: add freelist prefix close and frame-pointer stack walker - #912

Draft
Jaya Kasa (jayakasadev) wants to merge 1 commit into
microsoft:mainfrom
jayakasadev:pr2-freelist-stackwalker
Draft

Jaya Kasa (jayakasadev) wants to merge 1 commit into
microsoft:mainfrom
jayakasadev:pr2-freelist-stackwalker

Conversation

@jayakasadev

Copy link
Copy Markdown
Contributor

What

Adds two standalone primitives for heap profiling (#853), not yet wired into malloc or free:

  • freelist::Builder::close_prefix() and count() (src/snmalloc/mem/freelist.h) to hand out at most N entries from a slab free-queue builder while keeping the rest.
  • Frame-pointer stack walker (src/snmalloc/pal/pal_stack_walker.h) for Linux/macOS on x86_64 and aarch64 (with PAC stripping and stack-bounds checks), and a no-op fallback elsewhere.

Why

Refill-boundary heap profiling trims a slab refill to the exact number of objects before the next sample and captures the caller's stack on sampled allocations. Landing these primitives first keeps the later profiler PRs small and easy to review.

Cost

Zero runtime cost on existing builds: neither close_prefix() nor stack_walk() is called by the allocator yet. Builder::close() resets tracked length only when TRACK_LENGTH is enabled.

Test plan

Run on macOS arm64 (670ab11):

  • Debug CMake (-fast + -check): ctest -j8 92/92 passed (including new freelist_prefix test and stack_walker_bench)
  • Release CMake (-fast + -check): ctest -j8 92/92 passed
  • Whole-tree clang-format 15.0.7 --dry-run -Werror clean

Add two standalone primitives needed by refill-boundary heap profiling, with
zero change to existing allocation or deallocation paths:

- freelist::Builder::close_prefix() and count() (mem/freelist.h) to close at
  most N entries from a slab free-queue builder while retaining the remainder
- Frame-pointer stack walker (pal/pal_stack_walker.h, included from pal/pal.h)
  for x86_64/aarch64 on Linux/macOS with PAC stripping and stack-bounds checks,
  plus a NullStackWalker fallback elsewhere
- Unit test (freelist_prefix) and microbenchmark (stack_walker_bench)
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