Phase FREE-LEGACY-OPT-4-2/4-3: C6 ULTRA-free TLS cache + segment learning

Phase 4-2:
- Add TinyC6UltraFreeTLS structure with 128-slot TLS freelist
- Implement tiny_c6_ultra_free_fast/slow for C6 free hot path
- Add c6_ultra_free_fast counter to FreePathStats
- ENV gate: HAKMEM_TINY_C6_ULTRA_FREE_ENABLED (default: OFF)

Phase 4-3:
- Add segment learning on first C6 free via ss_fast_lookup()
- Learn seg_base/seg_end from SuperSlab for range check
- Increase cache capacity from 32 to 128 blocks

Results:
- Segment learning works: fast path captures blocks in segment
- However, without alloc integration, cache fills up and overflows to legacy
- Net effect: +1-3% (within noise range)
- Drain strategy also tested: no benefit (equal overhead)

Conclusion:
- Free-only TLS cache is limited without alloc-side integration
- Core v6 already has alloc/free integrated TLS (but -12% slower)
- Keep as research box (ENV default OFF)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Moe Charm (CI)
2025-12-11 18:34:27 +09:00
parent 210633117a
commit 1b196b3ac0
8 changed files with 382 additions and 25 deletions

View File

@ -46,6 +46,7 @@
// Phase FREE-LEGACY-BREAKDOWN-1: v6 は型エラーがあるため一時的にコメントアウト(デフォルト OFF なので影響なし)
// #include "../box/smallobject_core_v6_box.h" // SmallObject Core v6 (C6-only route stub, Phase v6-1)
#include "../box/tiny_c7_ultra_box.h" // C7 ULTRA stub (UF-1, delegates to v3)
#include "../box/tiny_c6_ultra_free_box.h" // Phase 4-2: C6 ULTRA-free (free-only, C6-only)
#include "../box/tiny_front_v3_env_box.h" // Tiny front v3 snapshot gate
#include "../box/tiny_heap_env_box.h" // ENV gate for TinyHeap front (A/B)
#include "../box/tiny_route_env_box.h" // Route snapshot (Heap vs Legacy)
@ -80,6 +81,35 @@ static inline int front_gate_unified_enabled(void) {
return g_enable;
}
// ============================================================================
// Phase 4-2: Legacy free helper (shared implementation in tiny_c6_ultra_free_box.c)
// ============================================================================
// Helper function to perform legacy free (used in both regular path and C6 ULTRA fallback)
__attribute__((always_inline))
static inline void hak_tiny_free_legacy_inline(void* base, uint32_t class_idx) {
const TinyFrontV3Snapshot* front_snap =
__builtin_expect(tiny_front_v3_enabled(), 0) ? tiny_front_v3_snapshot_get() : NULL;
// Legacy fallback - Unified Cache push
if (!front_snap || front_snap->unified_cache_on) {
if (unified_cache_push(class_idx, HAK_BASE_FROM_RAW(base))) {
FREE_PATH_STAT_INC(legacy_fallback);
// Phase 4-1: Legacy per-class breakdown
if (__builtin_expect(free_path_stats_enabled(), 0)) {
if (class_idx < 8) {
g_free_path_stats.legacy_by_class[class_idx]++;
}
}
return;
}
}
// Final fallback
tiny_hot_free_fast(class_idx, base);
}
// ============================================================================
// Phase 4-Step2: malloc_tiny_fast() - Hot/Cold Path Box (ACTIVE)
// ============================================================================
@ -289,6 +319,12 @@ static inline int free_tiny_fast(void* ptr) {
return 1;
}
// Phase 4-2: C6 ULTRA-free (C6-only, free-only, ENV gated)
if (class_idx == 6 && tiny_c6_ultra_free_enabled()) {
tiny_c6_ultra_free_fast(base, class_idx);
return 1;
}
// C7 v3 fast classify: bypass classify_ptr/ss_map_lookup for clear hits
if (class_idx == 7 &&
tiny_front_v3_enabled() &&
@ -457,26 +493,9 @@ static inline int free_tiny_fast(void* ptr) {
}
#endif
int pushed = 0;
if (!front_snap || front_snap->unified_cache_on) {
pushed = unified_cache_push(class_idx, HAK_BASE_FROM_RAW(base));
}
if (__builtin_expect(pushed, 1)) {
// Phase FREE-LEGACY-BREAKDOWN-1: カウンタ散布 (10. legacy fallback)
FREE_PATH_STAT_INC(legacy_fallback);
// Phase 4-1: Legacy per-class breakdown
if (__builtin_expect(free_path_stats_enabled(), 0)) {
if (class_idx >= 0 && class_idx < 8) {
g_free_path_stats.legacy_by_class[class_idx]++;
}
}
return 1; // Success
}
// Unified Cache full → 通常 free 経路へ
return 0;
// Phase 4-2: Legacy fallback (use inline helper)
hak_tiny_free_legacy_inline(base, class_idx);
return 1;
#else
// No header mode - fall back to normal free
return 0;