Phase 13-B: TinyHeapV2 free path supply hook (magazine population)
Implement magazine supply from free path to enable TinyHeapV2 L0 cache
Changes:
1. core/tiny_free_fast_v2.inc.h (Line 24, 134-143):
- Include tiny_heap_v2.h for magazine API
- Add supply hook after BASE pointer conversion (Line 134-143)
- Try to push freed block to TinyHeapV2 magazine (C0-C3 only)
- Falls back to TLS SLL if magazine full (existing behavior)
2. core/front/tiny_heap_v2.h (Line 24-46):
- Move TinyHeapV2Mag / TinyHeapV2Stats typedef from hakmem_tiny.c
- Add extern declarations for TLS variables
- Define TINY_HEAP_V2_MAG_CAP (16 slots)
- Enables use from tiny_free_fast_v2.inc.h
3. core/hakmem_tiny.c (Line 1270-1276, 1766-1768):
- Remove duplicate typedef definitions
- Move TLS storage declarations after tiny_heap_v2.h include
- Reason: tiny_heap_v2.h must be included AFTER tiny_alloc_fast.inc.h
- Forward declarations remain for early reference
Supply Hook Flow:
```
hak_free_at(ptr) → hak_tiny_free_fast_v2(ptr)
→ class_idx = read_header(ptr)
→ base = ptr - 1
→ if (class_idx <= 3 && tiny_heap_v2_enabled())
→ tiny_heap_v2_try_push(class_idx, base)
→ success: return (magazine supplied)
→ full: fall through to TLS SLL
→ tls_sll_push(class_idx, base) # existing path
```
Benefits:
- Magazine gets populated from freed blocks (L0 cache warm-up)
- Next allocation hits magazine (fast L0 path, no backend refill)
- Expected: 70-90% hit rate for fixed-size workloads
- Expected: +200-500% performance for C0-C3 classes
Build & Smoke Test:
- ✅ Build successful
- ✅ bench_fixed_size 256B workset=50: 33M ops/s (stable)
- ✅ bench_fixed_size 16B workset=60: 30M ops/s (stable)
- 🔜 A/B test (hit rate measurement) deferred to next commit
Implementation Status:
- ✅ Phase 13-A: Alloc hook + stats (completed, committed)
- ✅ Phase 13-B: Free path supply (THIS COMMIT)
- 🔜 Phase 13-C: Evaluation & tuning
Notes:
- Supply hook is C0-C3 only (TinyHeapV2 target range)
- Magazine capacity=16 (same as Phase 13-A)
- No performance regression (hook is ENV-gated: HAKMEM_TINY_HEAP_V2=1)
🤝 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>