Phase 13-A Step 1 COMPLETE: TinyHeapV2 alloc hook + stats + supply infrastructure
Phase 13-A Status: ✅ COMPLETE - Alloc hook working (hak_tiny_alloc via hakmem_tiny_alloc_new.inc) - Statistics accurate (alloc_calls, mag_hits tracked correctly) - NO-REFILL L0 cache stable (zero performance overhead) - A/B tests: C1 +0.76%, C2 +0.42%, C3 -0.26% (all within noise) Changes: - Added tiny_heap_v2_try_push() infrastructure for Phase 13-B (free path supply) - Currently unused but provides clean API for magazine supply from free path Verification: - Modified bench_fixed_size.c to use hak_alloc_at/hak_free_at (HAKMEM routing) - Verified HAKMEM routing works: workset=10-127 ✅ - Found separate bug: workset=128 hangs (power-of-2 edge case, not HeapV2 related) Phase 13-B: Free path supply deferred - Actual free path: hak_free_at → hak_tiny_free_fast_v2 - Not tiny_free_fast (wrapper-only path) - Requires hak_tiny_free_fast_v2 integration work Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -79,6 +79,41 @@ static inline int tiny_heap_v2_refill_mag(int class_idx) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Phase 13-A Step 2: Try to push a block into TinyHeapV2 magazine
|
||||||
|
// Called from free path to supply magazine with "leftover" blocks.
|
||||||
|
// Returns: 1 if pushed successfully, 0 if magazine is full
|
||||||
|
static inline int tiny_heap_v2_try_push(int class_idx, void* base) {
|
||||||
|
// 1. Check if class is enabled
|
||||||
|
if (class_idx < 0 || class_idx > 3) return 0;
|
||||||
|
if (!tiny_heap_v2_class_enabled(class_idx)) return 0;
|
||||||
|
|
||||||
|
TinyHeapV2Mag* mag = &g_tiny_heap_v2_mag[class_idx];
|
||||||
|
|
||||||
|
// 2. Check if magazine has room
|
||||||
|
if (mag->top >= TINY_HEAP_V2_MAG_CAP) {
|
||||||
|
return 0; // Magazine full
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Push BASE pointer into magazine
|
||||||
|
mag->items[mag->top++] = base;
|
||||||
|
|
||||||
|
// DEBUG: Log push events
|
||||||
|
static int g_push_dbg = -1;
|
||||||
|
if (g_push_dbg == -1) {
|
||||||
|
const char* e = getenv("HAKMEM_TINY_HEAP_V2_DEBUG");
|
||||||
|
g_push_dbg = (e && *e && *e != '0') ? 1 : 0;
|
||||||
|
}
|
||||||
|
if (g_push_dbg) {
|
||||||
|
static __thread int g_push_count[TINY_NUM_CLASSES] = {0};
|
||||||
|
if (g_push_count[class_idx] < 5) {
|
||||||
|
fprintf(stderr, "[HeapV2-PUSH] C%d push #%d, base=%p, mag->top=%d\n",
|
||||||
|
class_idx, g_push_count[class_idx]++, base, mag->top);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1; // Success
|
||||||
|
}
|
||||||
|
|
||||||
// Tiny heap v2 alloc – returns BASE pointer or NULL.
|
// Tiny heap v2 alloc – returns BASE pointer or NULL.
|
||||||
// Phase 13-A Step 1: Minimal "lucky hit" L0 cache (NO REFILL)
|
// Phase 13-A Step 1: Minimal "lucky hit" L0 cache (NO REFILL)
|
||||||
// Strategy: Pop from magazine if available, else return NULL immediately.
|
// Strategy: Pop from magazine if available, else return NULL immediately.
|
||||||
|
|||||||
Reference in New Issue
Block a user