Phase 13-B: TinyHeapV2 supply path with dual-mode A/B framework (Stealing vs Leftover)
Summary: - Implemented free path supply with ENV-gated A/B modes (HAKMEM_TINY_HEAP_V2_LEFTOVER_MODE) - Mode 0 (Stealing, default): L0 gets freed blocks first → +18% @ 32B - Mode 1 (Leftover): L1 primary owner, L0 gets leftovers → Box-clean but -5% @ 16B - Decision: Default to Stealing for performance (ChatGPT analysis: L0 doesn't corrupt learning layer signals) Performance (100K iterations, workset=128): - 16B: 43.9M → 45.6M ops/s (+3.9%) - 32B: 41.9M → 49.6M ops/s (+18.4%) ✅ - 64B: 51.2M → 51.5M ops/s (+0.6%) - 100% magazine hit rate (supply from free path working correctly) Implementation: - tiny_free_fast_v2.inc.h: Dual-mode supply (lines 134-166) - tiny_heap_v2.h: Add tiny_heap_v2_leftover_mode() flag + rationale doc - tiny_alloc_fast.inc.h: Alloc hook with tiny_heap_v2_alloc_by_class() - CURRENT_TASK.md: Updated Phase 13-B status (complete) with A/B results ENV flags: - HAKMEM_TINY_HEAP_V2=1 # Enable TinyHeapV2 - HAKMEM_TINY_HEAP_V2_LEFTOVER_MODE=0 # Mode 0 (Stealing, default) - HAKMEM_TINY_HEAP_V2_CLASS_MASK=0xE # C1-C3 only (skip C0 -5% regression) - HAKMEM_TINY_HEAP_V2_STATS=1 # Print statistics 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -28,6 +28,7 @@
|
||||
#include "hakmem_tiny_integrity.h" // PRIORITY 1-4: Corruption detection
|
||||
#ifdef HAKMEM_TINY_HEADER_CLASSIDX
|
||||
#include "front/tiny_front_c23.h" // Phase B: Ultra-simple C2/C3 front
|
||||
#include "front/tiny_heap_v2.h" // Phase 13-A: TinyHeapV2 magazine front
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
@ -601,6 +602,17 @@ static inline void* tiny_alloc_fast(size_t size) {
|
||||
}
|
||||
#endif
|
||||
|
||||
// Phase 13-A: TinyHeapV2 (per-thread magazine, experimental)
|
||||
// ENV-gated: HAKMEM_TINY_HEAP_V2=1
|
||||
// Targets class 0-3 (8-64B) only, falls back to existing path if NULL
|
||||
// PERF: Pass class_idx directly to avoid redundant size→class conversion
|
||||
if (__builtin_expect(tiny_heap_v2_enabled(), 0) && class_idx <= 3) {
|
||||
void* base = tiny_heap_v2_alloc_by_class(class_idx);
|
||||
if (base) {
|
||||
HAK_RET_ALLOC(class_idx, base); // Header write + return USER pointer
|
||||
}
|
||||
}
|
||||
|
||||
// NEW: Front-Direct/SLL-OFF bypass control (TLS cached, lazy init)
|
||||
static __thread int s_front_direct_alloc = -1;
|
||||
if (__builtin_expect(s_front_direct_alloc == -1, 0)) {
|
||||
|
||||
Reference in New Issue
Block a user