Skip to content

Add H3 + H4 dealloc edge-case hooks and integration test (Phase 3.4) - #9

Merged
jayakasadev merged 1 commit into
mainfrom
feature/phase-3-4-h3-h4-hooks
Jun 11, 2026
Merged

jayakasadev merged 1 commit into
mainfrom
feature/phase-3-4-h3-h4-hooks

Conversation

@jayakasadev

Copy link
Copy Markdown
Owner

Summary

Phase 3.4 — closes dealloc-side coverage. Completes the milestone's H1–H4 hook set.

  • H3 at corealloc.h:1458Allocator::dealloc_remote SecondaryAllocator escape arm. Catches GWP-ASan / non-snmalloc pointers that bypass the snmalloc-owned pagemap.
  • H4 at corealloc.h:1522Allocator::dealloc_remote_slow lazy-init recursion lambda, immediately before recursive a->dealloc(p). Pairs with H1 for tight recursion-guard.
  • Both gated by #ifdef SNMALLOC_PROFILE. Default Config OFF build byte-identical to Phase 3.3.
  • Both reuse record_dealloc<Config>. Idempotence guaranteed by clear_profile_slot CAS + ReentrancyGuard. No new state machines.

Test plan

  • 96/96 ctest with SNMALLOC_PROFILE=OFF
  • 96/96 ctest with SNMALLOC_PROFILE=ON
  • profile_h3_h4: triple/quadruple-clear idempotence, nullptr robustness, fresh-thread remote-free stress, default-Config compile-time no-op
  • profile_integration (ticket 86ahrfx9g): 16 threads × 100k allocs × {16,64,256,1024} size ladder, ~50/50 same/cross-thread free + one-producer-many-consumers stress
  • Sample count within 6σ of Poisson at 128 KiB rate
  • Post-free leak ≤ documented tolerance (1% + 4 abs)
  • Global SampledList drains to zero
  • Teardown-straggler ratio improves from ~1/1250 (Phase 3.3 e2e) to ~1/4000 (16-thread integration) — ~3× reduction at 2× thread count

Tickets closed: 86ahzwj2f (H3 + H4), 86ahrfx9g (multi-threaded alloc + cross-thread dealloc integration)

- Install H3 heap-profile hook in Allocator::dealloc_remote on the
  SecondaryAllocator branch (catches GWP-ASan / non-snmalloc pointers
  that bypass the snmalloc-owned pagemap).
- Install H4 heap-profile hook in Allocator::dealloc_remote_slow's
  lazy-init recursion lambda, immediately before the recursive
  a->dealloc(p). Pairs with H1 to keep the recursion-guard tight.
- Both hooks live entirely under #ifdef SNMALLOC_PROFILE; default
  Config OFF build is byte-identical to Phase 3.3.
- Both hooks reuse profile::record_dealloc<Config>; idempotence is
  guaranteed by the CAS in clear_profile_slot and the per-thread
  ReentrancyGuard. No new state machines, no new allocations on the
  free path.
- New test: src/test/func/profile_h3_h4/profile_h3_h4.cc.
  Triple- and quadruple-clear idempotence, nullptr robustness,
  fresh-thread remote-free stress, default-Config compile-time no-op.
- New test: src/test/func/profile_integration/profile_integration.cc.
  16 threads x 100k allocs x varied size ladder, ~50/50 same-thread
  vs cross-thread free, plus a one-producer-many-consumers stress.
  Asserts sample count within 6 sigma of Poisson expectation,
  post-free leak <= documented tolerance (<= 1% + 4), and that the
  global SampledList drains to zero. Sampling rate (128 KiB) sized
  so expected samples stay well below the NodePool capacity ceiling.
- Wires ticket 86ahrfx9g (multi-threaded alloc + cross-thread dealloc
  integration stress).
- Observed teardown-straggler ratio improves from ~1/1250 in the
  Phase 3.3 8-thread e2e test to ~1/4000 in the new 16-thread
  integration test, a ~3x reduction.
@jayakasadev
jayakasadev merged commit d2a8f93 into main Jun 11, 2026
139 of 163 checks passed
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