Phase 21-1-B: Ring cache Alloc/Free 統合 - C2/C3 hot path integration

**統合内容**:
- Alloc path (tiny_alloc_fast.inc.h): Ring pop → HeapV2/UltraHot/SLL fallback
- Free path (tiny_free_fast_v2.inc.h): Ring push → HeapV2/SLL fallback
- Lazy init: 最初の alloc/free 時に自動初期化(thread-safe)

**設計**:
- Lazy init パターン(ENV control と同様)
- ring_cache_pop/push 内で slots == NULL チェック → ring_cache_init() 呼び出し
- Include 構造: ファイルトップレベルに #include 追加(関数内 include 禁止)

**Makefile 修正**:
- TINY_BENCH_OBJS_BASE に core/front/tiny_ring_cache.o 追加
- Link エラー修正: 4箇所の object list に追加

**動作確認**:
- Ring OFF (default): 83K ops/s (1K iterations) 
- Ring ON (HAKMEM_TINY_HOT_RING_ENABLE=1): 78K ops/s 
- クラッシュなし、正常動作確認

**次のステップ**: Phase 21-1-C (Refill/Cascade 実装)
This commit is contained in:
Moe Charm (CI)
2025-11-16 07:51:37 +09:00
parent db9c06211e
commit fdbdcdcdb3
11 changed files with 99 additions and 15 deletions

View File

@ -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_ring_cache.h" // Phase 21-1: Ring cache (C2/C3 array-based TLS cache)
#include "front/tiny_heap_v2.h" // Phase 13-A: TinyHeapV2 magazine front
#include "front/tiny_ultra_hot.h" // Phase 14: TinyUltraHot C1/C2 ultra-fast path
#endif
@ -605,6 +606,19 @@ static inline void* tiny_alloc_fast(size_t size) {
}
#endif
// Phase 21-1: Ring Cache (C2/C3 only) - Array-based TLS cache
// ENV-gated: HAKMEM_TINY_HOT_RING_ENABLE=1
// Target: +15-20% (54.4M → 62-65M ops/s) by eliminating pointer chasing
// Design: Ring (L0) → SLL (L1) → SuperSlab (L2) cascade hierarchy
if (class_idx == 2 || class_idx == 3) {
void* base = ring_cache_pop(class_idx);
if (base) {
// Ring hit - return USER pointer (BASE + 1)
HAK_RET_ALLOC(class_idx, base);
}
// Ring miss - fall through to existing path (TLS SLL/UltraHot/HeapV2)
}
// Phase 14-C: TinyUltraHot Borrowing Design (正史から借りる設計)
// ENV-gated: HAKMEM_TINY_ULTRA_HOT=1 (internal control)
// Phase 19-4: HAKMEM_TINY_FRONT_ENABLE_ULTRAHOT=1 to enable (DEFAULT: OFF for +12.9% perf)