0f15adae4e
Phase ALLOC-GATE-OPT-1: tiny_alloc_gate_fast 統計計測
...
- AllocGateStats 構造体追加(size2class/route/env/class分布)
- malloc_tiny_fast にカウンタ埋め込み
- ENV: HAKMEM_ALLOC_GATE_STATS (default 0)
- 挙動変更なし(計測のみ)
計測結果:
- Mixed: total=542k, size2class=0, route_calls=0, env_checks=275k, C4-C7=95.2%
- size_to_class/route_for_class は完全削減済み(LUT 効果)
- C4-C7 が 95% → ULTRA fast path が有効
- env_checks ≈ c7_calls → C7 ULTRA の ENV gate が毎回呼ばれる
- C6-heavy: total=11 → malloc_tiny_fast はほぼ通らない(mid/pool 主体)
結論:
- alloc gate は既に十分最適化済み(LUT + ULTRA で削減済み)
- さらなる最適化余地は小さい(env_checks は軽量化済み、数%以下の効果)
- 次フェーズでは free dispatcher (29%) や C7 ULTRA refill (7%) など、他のボトルネックを狙う
詳細: docs/analysis/ALLOC_GATE_ANALYSIS.md
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-11 21:32:40 +09:00
753909fa4d
Phase PERF-ULTRA-ALLOC-OPT-1 (改訂版): C7 ULTRA 内部最適化
...
設計判断:
- 寄生型 C7 ULTRA_FREE_BOX を削除(設計的に不整合)
- C7 ULTRA は C4/C5/C6 と異なり専用 segment + TLS を持つ独立サブシステム
- tiny_c7_ultra.c 内部で直接最適化する方針に統一
実装内容:
1. 寄生型パスの削除
- core/box/tiny_c7_ultra_free_box.{h,c} 削除
- core/box/tiny_c7_ultra_free_env_box.h 削除
- Makefile から tiny_c7_ultra_free_box.o 削除
- malloc_tiny_fast.h を元の tiny_c7_ultra_alloc/free 呼び出しに戻す
2. TLS 構造の最適化 (tiny_c7_ultra_box.h)
- count を struct 先頭に移動(L1 cache locality 向上)
- 配列ベース TLS キャッシュに変更(cap=128, C6 同等)
- freelist: linked-list → BASE pointer 配列
- cold フィールド(seg_base/seg_end/meta)を後方配置
3. alloc の純 TLS pop 化 (tiny_c7_ultra.c)
- hot path: 1 分岐のみ(count > 0)
- TLS access は 1 回のみ(ctx に cache)
- ENV check を呼び出し側に移動
- segment/page_meta アクセスは refill 時(cold path)のみ
4. free の UF-3 segment learning 維持
- 最初の free で segment 学習(seg_base/seg_end を TLS に記憶)
- 以降は範囲チェック → TLS push
- 範囲外は v3 free にフォールバック
実測値 (Mixed 16-1024B, 1M iter, ws=400):
- tiny_c7_ultra_alloc self%: 7.66% (維持 - 既に最適化済み)
- tiny_c7_ultra_free self%: 3.50%
- Throughput: 43.5M ops/s
評価: 部分達成
- 設計一貫性の回復: 成功
- Array-based TLS cache 移行: 成功
- pure TLS pop パターン統一: 成功
- perf self% 削減(7.66% → 5-6%): 未達成(既に最適)
C7 ULTRA は独立サブシステムとして tiny_c7_ultra.c に閉じる設計を維持。
次は refill path 最適化または C4-C7 ULTRA free 群の軽量化へ。
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-11 20:39:46 +09:00
fb88725a43
Phase FREE-LEGACY-OPT-6: C4 ULTRA Implementation
...
Implement C4 ULTRA free TLS cache with parasitic free+alloc pattern,
achieving 99.7-99.9% elimination of C4 legacy fallback calls.
Key Features:
- TLS cache cap=64 (tuned for L1 cache fit, smaller than C5/C6's 128)
- Segment learning via ss_fast_lookup() on first free
- Free-side cache push + alloc-side TLS pop pattern
- ENV gate: HAKMEM_TINY_C4_ULTRA_FREE_ENABLED (default OFF)
- Full FREE_PATH_STATS instrumentation
Benchmark Results:
C4-heavy (65-128B range):
- C4 legacy: 591,583 → 1,711 (-99.7%)
- c4_ultra cache hits: ~599k (free) + ~599k (alloc)
- Mixed load: 340,732 → 284 C4 legacy (-99.9%)
Legacy fallback reduction:
- C4-heavy: 589,872 fewer legacy calls (-10.9% total)
- Mixed: 340,448 fewer C4 legacy calls (-12.8% in mixed)
Performance note: ~2% throughput cost in isolated C4-heavy case,
acceptable tradeoff for 99%+ legacy elimination per class.
Files:
NEW: core/box/tiny_c4_ultra_free_box.h/c
NEW: core/box/tiny_c4_ultra_free_env_box.h
MOD: core/box/tiny_ultra_classes_box.h (added C4 macros)
MOD: core/box/free_path_stats_box.h/c (C4 ULTRA counters)
MOD: core/front/malloc_tiny_fast.h (C4 alloc+free integration)
MOD: Makefile (added C4 ULTRA object)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-11 19:38:27 +09:00
ea6ed1a6e4
Phase FREE-LEGACY-OPT-5-1/5-2: C5 ULTRA free+alloc integration
...
Summary:
========
Implemented C5 ULTRA TLS cache pattern following the successful C6 ULTRA design:
- Phase 5-1: Free-side TLS cache + segment learning
- Phase 5-2: Alloc-side TLS pop for complete free+alloc cycle integration
Targets C5 class (129-256B) as next legacy reduction after C6 completion.
Key Changes:
============
1. NEW FILES:
- core/box/tiny_c5_ultra_free_box.h: C5 ULTRA TLS cache structure
- core/box/tiny_c5_ultra_free_box.c: C5 free path implementation (same pattern as C6)
- core/box/tiny_c5_ultra_free_env_box.h: ENV gating (HAKMEM_TINY_C5_ULTRA_FREE_ENABLED)
2. MODIFIED FILES:
- core/front/malloc_tiny_fast.h:
* Added C5 ULTRA includes
* Added C5 alloc-side TLS pop at lines 186-194 (integrated with C6)
* Added C5 free path at lines 333-337 (integrated with C6)
- core/box/tiny_ultra_classes_box.h:
* Added TINY_CLASS_C5 constant
* Added tiny_class_is_c5() macro
* Extended tiny_class_is_ultra() to include C5
- core/box/free_path_stats_box.h:
* Added c5_ultra_free_fast counter
* Added c5_ultra_alloc_hit counter
- core/box/free_path_stats_box.c:
* Updated stats dump to output C5 counters
- Makefile:
* Added core/box/tiny_c5_ultra_free_box.o to all object lists
3. Design Rationale:
- Exact copy of C6 ULTRA pattern (proven effective)
- TLS cache capacity: 128 blocks (same as C6 for consistency)
- Segment learning on first C5 free via ss_fast_lookup()
- Alloc-side pop integrated directly in malloc_tiny_fast.h hotpath
- Legacy fallback unification via tiny_legacy_fallback_free_base()
4. Expected Impact:
- C5 legacy calls: 68,871 → 0 (100% elimination)
- Total legacy reduction: ~53% of remaining 129,623
- Mixed workload: Minimal regression (C5 is smaller class, fewer allocations)
5. Stats Collection:
Run with: HAKMEM_TINY_C5_ULTRA_FREE_ENABLED=1 HAKMEM_FREE_PATH_STATS=1 ./bench_allocators_hakmem
Expected output:
[FREE_PATH_STATS] ... c5_ultra_free=68871 c5_ultra_alloc=68871 ... legacy_fb=60752 ...
[FREE_PATH_STATS_LEGACY_BY_CLASS] ... c5=0 ...
Status:
=======
- Code: ✅ COMPLETE (3 new files + 5 modified files)
- Compilation: ✅ Verified (no errors, only unused variable warnings unrelated to C5)
- Functionality: Ready to benchmark (ENV gating: default OFF, opt-in via ENV)
Phase Progression:
==================
✅ Phase 4-4: C6 ULTRA free+alloc (legacy C6: 137,319 → 0)
✅ Phase 5-1/5-2: C5 ULTRA free+alloc (legacy C5: 68,871 → 0 expected)
⏳ Phase 4.5: C4 ULTRA (34,727 remaining)
📋 Future: C3/C2 ULTRA if beneficial
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-11 19:26:51 +09:00
c848a60696
Phase REFACTOR-3: Inline Pointer Macro Centralization (tiny_base_to_user_inline)
...
Centralize BASE ↔ USER pointer conversions into reusable, zero-cost macros.
Previously, pointer arithmetic (base + 1, ptr - 1) was scattered across
allocation/deallocation code with hardcoded offsets.
Changes:
- NEW: core/box/tiny_ptr_convert_box.h
- tiny_base_to_user_inline(): BASE → USER (base + TINY_HEADER_OFFSET)
- tiny_user_to_base_inline(): USER → BASE (user - TINY_HEADER_OFFSET)
- TINY_HEADER_OFFSET: Centralized constant (currently 1)
- Function variants: tiny_base_to_user(), tiny_user_to_base()
- Modified: core/front/malloc_tiny_fast.h
- L181: return (uint8_t*)base + 1 → tiny_base_to_user_inline(base)
- L299: void* base = (void*)((char*)ptr - 1) → tiny_user_to_base_inline(ptr)
Benefits:
- Self-documenting code (semantic intent is clear)
- Single source of truth for header offset
- Easier to extend (e.g., variable-length headers, alignment changes)
- Type-safe conversions (macro validates pointer types)
- Zero performance cost (inline macro, same compiled code)
Contract:
- Header stored at offset -1 from USER pointer
- Allocation: base → user (user = base + 1)
- Deallocation: user → base (base = user - 1)
No semantic changes - identical logic, just centralized.
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-11 19:02:49 +09:00
0752688785
Phase REFACTOR-2: Legacy Fallback Logic Unification
...
Consolidate duplicated legacy free logic into a single reusable function.
Previously, hak_tiny_free_legacy_inline() and hak_tiny_free_legacy_impl()
contained identical implementations in malloc_tiny_fast.h and
tiny_c6_ultra_free_box.c.
Changes:
- NEW: core/box/tiny_legacy_fallback_box.h
- tiny_legacy_fallback_free_base(): Unified legacy free implementation
- Encapsulates: Unified Cache push + per-class stats + final fallback
- Contract: BASE pointer input (already extracted from USER ptr)
- Modified: core/front/malloc_tiny_fast.h
- Removed: hak_tiny_free_legacy_inline() (lines 96-111)
- Replaced call: hak_tiny_free_legacy_inline → tiny_legacy_fallback_free_base
- Modified: core/box/tiny_c6_ultra_free_box.c
- Removed: hak_tiny_free_legacy_impl() (lines 17-39)
- Replaced call: hak_tiny_free_legacy_impl → tiny_legacy_fallback_free_base
Benefits:
- Single source of truth (DRY principle)
- Easier to maintain and test
- Consistent behavior across all free paths
- No performance impact (always_inline preserved)
No semantic changes - identical logic, just centralized.
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-11 19:01:59 +09:00
3cf88dab84
Phase REFACTOR-1: Magic Number → Named Constants (TINY_CLASS_C6/C7)
...
Replace hardcoded class_idx checks (== 6, == 7) with named macros:
- tiny_class_is_c6(idx) for C6 checks
- tiny_class_is_c7(idx) for C7 checks
- tiny_class_is_ultra(idx) for combined checks
Benefits:
- Self-documenting code (semantic intent is clear)
- Single source of truth for class constants
- Easier to extend to other ULTRA tiers (C5, C8) in future
Changes:
- NEW: core/box/tiny_ultra_classes_box.h (named constants + helpers)
- Modified: core/front/malloc_tiny_fast.h (4 replacements: L181, L193, L326, L337)
No performance impact (zero-cost macros, same compiled code).
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-11 19:00:45 +09:00
9830eff6cc
Phase FREE-LEGACY-OPT-4-4: C6 ULTRA free+alloc integration
...
Parasitic TLS cache: alloc now pops from the TLS freelist filled by free.
Implementation:
- malloc_tiny_fast(): C6 class-specific TLS pop check before route switch
- if (class_idx == 6 && tiny_c6_ultra_free_enabled())
- pop from TinyC6UltraFreeTLS.freelist[--count]
- return USER pointer (BASE + 1)
- FreePathStats: Added c6_ultra_alloc_hit counter for observability
Results (Mixed 16-1024B):
- OFF: 40.2M ops/s baseline
- ON: 42.2M ops/s (+4.9%) stable
Per-profile:
- Mixed: +4.9% (40.2M → 42.2M)
- C6-heavy: +7.6% (40.7M → 43.8M)
Free-alloc loop:
- free: TLS push (all C6 frees)
- alloc: TLS pop (all C6 allocs in steady state)
- Cache never fills, no legacy overflow
- C6 legacy_by_class reduced from 137K to 0 (100% elimination)
Key insight:
- Free-only TLS cache fails without alloc integration
- Once integrated, creates perfect load-balancing loop
- Alloc drains exactly what free fills
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-11 18:47:21 +09:00
1b196b3ac0
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 >
2025-12-11 18:34:27 +09:00
210633117a
Phase FREE-LEGACY-OPT-4-1: Legacy per-class breakdown analysis
...
## 目的
Legacy fallback 49.2% の内訳を per-class で分析し、最も Legacy を使用しているクラスを特定。
## 実装内容
1. FreePathStats 構造体の拡張
- legacy_by_class[8] フィールドを追加(C0-C7 の Legacy fallback 内訳)
2. デストラクタ出力の更新
- [FREE_PATH_STATS_LEGACY_BY_CLASS] 行を追加し、C0-C7 の内訳を出力
3. カウンタの散布
- free_tiny_fast() の Legacy fallback 経路で legacy_by_class[class_idx] をインクリメント
- class_idx の範囲チェック(0-7)を実施
## 測定結果(Mixed 16-1024B)
**測定安定性**: 完全に安定(3 回とも同一の値、決定的測定)
Legacy per-class 内訳:
- C0: 0 (0.0%)
- C1: 0 (0.0%)
- C2: 8,746 (3.3% of legacy)
- C3: 17,279 (6.5% of legacy)
- C4: 34,727 (13.0% of legacy)
- C5: 68,871 (25.8% of legacy)
- C6: 137,319 (51.4% of legacy) ← 最大シェア
- C7: 0 (0.0%)
合計: 266,942 (49.2% of total free calls)
## 分析結果
**最大シェアクラス**: C6 (513-1024B) が Legacy の 51.4% を占める
**理由**:
- Mixed 16-1024B では C6 サイズのアロケーションが多い
- C7 ULTRA は C7 専用で C6 は未対応
- v3/v4 も C6 をカバーしていない
- Route 設定で C6 は Legacy に直接落ちている
## 次のアクション
Phase FREE-LEGACY-OPT-4-2 で C6 クラスに ULTRA-Free lane を実装:
- Legacy fallback を 51% 削減(C6 分)
- Legacy: 49.2% → 24-27% に改善(半減)
- Mixed 16-1024B: 44.8M → 47-48M ops/s 程度(+5-8% 改善)
## 変更ファイル
- core/box/free_path_stats_box.h: FreePathStats 構造体に legacy_by_class[8] 追加
- core/box/free_path_stats_box.c: デストラクタに per-class 出力追加
- core/front/malloc_tiny_fast.h: Legacy fallback 経路に per-class カウンタ追加
- docs/analysis/FREE_LEGACY_PATH_ANALYSIS.md: Phase 4-1 分析結果を記録
Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-11 18:04:14 +09:00
e2ca52d59d
Phase v6-6: Inline hot path optimization for SmallObject Core v6
...
Optimize v6 alloc/free by eliminating redundant route checks and adding
inline hot path functions:
- smallobject_core_v6_box.h: Add inline hot path functions:
- small_alloc_c6_hot_v6() / small_alloc_c5_hot_v6(): Direct TLS pop
- small_free_c6_hot_v6() / small_free_c5_hot_v6(): Direct TLS push
- No route check needed (caller already validated via switch case)
- smallobject_core_v6.c: Add cold path functions:
- small_alloc_cold_v6(): Handle TLS refill from page
- small_free_cold_v6(): Handle page freelist push (TLS full/cross-thread)
- malloc_tiny_fast.h: Update front gate to use inline hot path:
- Alloc: hot path first, cold path fallback on TLS miss
- Free: hot path first, cold path fallback on TLS full
Performance results:
- C5-heavy: v6 ON 42.2M ≈ baseline (parity restored)
- C6-heavy: v6 ON 34.5M ≈ baseline (parity restored)
- Mixed 16-1024B: ~26.5M (v3-only: ~28.1M, gap is routing overhead)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-11 15:59:29 +09:00
c60199182e
Phase v6-1/2/3/4: SmallObject Core v6 - C6-only implementation + refactor
...
Phase v6-1: C6-only route stub (v1/pool fallback)
Phase v6-2: Segment v6 + ColdIface v6 + Core v6 HotPath implementation
- 2MiB segment / 64KiB page allocation
- O(1) ptr→page_meta lookup with segment masking
- C6-heavy A/B: SEGV-free but -44% performance (15.3M ops/s)
Phase v6-3: Thin-layer optimization (TLS ownership check + batch header + refill batching)
- TLS ownership fast-path skip page_meta for 90%+ of frees
- Batch header writes during refill (32 allocs = 1 header write)
- TLS batch refill (1/32 refill frequency)
- C6-heavy A/B: v6-2 15.3M → v6-3 27.1M ops/s (±0% vs baseline) ✅
Phase v6-4: Mixed hang fix (segment metadata lookup correction)
- Root cause: metadata lookup was reading mmap region instead of TLS slot
- Fix: use TLS slot descriptor with in_use validation
- Mixed health: 5M iterations SEGV-free, 35.8M ops/s ✅
Phase v6-refactor: Code quality improvements (macro unification + inline + docs)
- Add SMALL_V6_* prefix macros (header, pointer conversion, page index)
- Extract inline validation functions (small_page_v6_valid, small_ptr_in_segment_v6)
- Doxygen-style comments for all public functions
- Result: 0 compiler warnings, maintained +1.2% performance
Files:
- core/box/smallobject_core_v6_box.h (new, type & API definitions)
- core/box/smallobject_cold_iface_v6.h (new, cold iface API)
- core/box/smallsegment_v6_box.h (new, segment type definitions)
- core/smallobject_core_v6.c (new, C6 alloc/free implementation)
- core/smallobject_cold_iface_v6.c (new, refill/retire logic)
- core/smallsegment_v6.c (new, segment allocator)
- docs/analysis/SMALLOBJECT_CORE_V6_DESIGN.md (new, design document)
- core/box/tiny_route_env_box.h (modified, v6 route added)
- core/front/malloc_tiny_fast.h (modified, v6 case in route switch)
- Makefile (modified, v6 objects added)
- CURRENT_TASK.md (modified, v6 status added)
Status:
- C6-heavy: v6 OFF 27.1M → v6-3 ON 27.1M ops/s (±0%) ✅
- Mixed: v6 ON 35.8M ops/s (C6-only, other classes via v1) ✅
- Build: 0 warnings, fully documented ✅
🤖 Generated with Claude Code
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-11 15:29:59 +09:00
e0fb7d550a
Phase v5-2: SmallObject v5 C6-only 本実装 (WIP - header fix)
...
本実装修正:
- tiny_region_id_write_header() を追加: USER pointer を正しく返す
- TLS slot からの segment 探索 (page_meta_of)
- Page-level allocation で segment 再利用
- 2MiB alignment 保証 (4MiB 確保 + alignment)
- free パスの route 修正 (v4 から v5 への fallthrough 削除)
動作確認:
- SEGV 消失: alloc/free 基本動作 OK
- 性能: ~18-20M ops/s (baseline 43-47M の約 40-45%)
- 回帰原因: TLS slot 線形探索 O(n)、find_page O(n)
残タスク:
- O(1) segment lookup 最適化 (hash または array 直接参照)
- find_page 除去 (segment lookup 成功時)
- partial_count/list 管理の最適化
ENV デフォルト OFF なので本線影響なし。
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-11 04:14:51 +09:00
9c24bebf08
Phase v5-1: SmallObject v5 C6-only route stub 接続
...
- tiny_route_env_box.h: TINY_ROUTE_SMALL_HEAP_V5 enum 追加、route snapshot で C6→v5 分岐
- malloc_tiny_fast.h: alloc/free switch に v5 case 追加(v1/pool fallback)
- smallobject_hotbox_v5.c: stub 実装(alloc は NULL 返却、free は no-op)
- smallobject_hotbox_v5_box.h: 関数 signature に ctx パラメータ追加
- Makefile: core/smallobject_hotbox_v5.o をリンクリストに追加
- ENV_PROFILE_PRESETS.md: v5-1 プリセット追記
- CURRENT_TASK.md: Phase v5-1 完了記録
**特性**:
- ENV: HAKMEM_SMALL_HEAP_V5_ENABLED=1 / HAKMEM_SMALL_HEAP_V5_CLASSES=0x40 で opt-in
- テスト結果: C6-heavy (v5 OFF 15.5M → v5 ON 16.4M ops/s, 正常), Mixed 47.2M ops/s, SEGV/assert なし
- 挙動は v1/pool fallback と同じ(実装は v5-2)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-11 03:25:37 +09:00
2a13478dc7
Optimize C6 heavy and C7 ultra performance analysis with refined design refinements
...
- Update environment profile presets and visibility analysis
- Enhance small object and tiny segment v4 box implementations
- Refine C7 ultra and C6 heavy allocation strategies
- Add comprehensive performance metrics and design documentation
🤖 Generated with Claude Code
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-10 22:57:26 +09:00
f2ce7256cd
Add v4 C7/C6 fast classify and small-segment v4 scaffolding
2025-12-10 19:14:38 +09:00
3261025995
Phase v4-4: pilot C6 v4 route with opt-in gate
2025-12-10 18:18:05 +09:00
cbd33511eb
Phase v4-3.1: reuse C7 v4 pages and record prep calls
2025-12-10 17:58:42 +09:00
acc64f2438
Phase ML1: Pool v1 memset 89.73% overhead 軽量化 (+15.34% improvement)
...
## Summary
- ChatGPT により bench_profile.h の setenv segfault を修正(RTLD_NEXT 経由に切り替え)
- core/box/pool_zero_mode_box.h 新設:ENV キャッシュ経由で ZERO_MODE を統一管理
- core/hakmem_pool.c で zero mode に応じた memset 制御(FULL/header/off)
- A/B テスト結果:ZERO_MODE=header で +15.34% improvement(1M iterations, C6-heavy)
## Files Modified
- core/box/pool_api.inc.h: pool_zero_mode_box.h include
- core/bench_profile.h: glibc setenv → malloc+putenv(segfault 回避)
- core/hakmem_pool.c: zero mode 参照・制御ロジック
- core/box/pool_zero_mode_box.h (新設): enum/getter
- CURRENT_TASK.md: Phase ML1 結果記載
## Test Results
| Iterations | ZERO_MODE=full | ZERO_MODE=header | Improvement |
|-----------|----------------|-----------------|------------|
| 10K | 3.06 M ops/s | 3.17 M ops/s | +3.65% |
| 1M | 23.71 M ops/s | 27.34 M ops/s | **+15.34%** |
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-10 09:08:18 +09:00
a905e0ffdd
Guard madvise ENOMEM and stabilize pool/tiny front v3
2025-12-09 21:50:15 +09:00
8f18963ad5
Phase 36-37: TinyHotHeap v2 HotBox redesign and C7 current_page policy fixes
...
- Redefine TinyHotHeap v2 as per-thread Hot Box with clear boundaries
- Add comprehensive OS statistics tracking for SS allocations
- Implement route-based free handling for TinyHeap v2
- Add C6/C7 debugging and statistics improvements
- Update documentation with implementation guidelines and analysis
- Add new box headers for stats, routing, and front-end management
2025-12-08 21:30:21 +09:00
a6991ec9e4
Add TinyHeap class mask and extend routing
2025-12-07 22:49:28 +09:00
fda6cd2e67
Boxify superslab registry, add bench profile, and document C7 hotpath experiments
2025-12-07 03:12:27 +09:00
c1c45106da
Two-Speed HOT PATH: Guard hak_super_lookup calls with HAKMEM_BUILD_RELEASE
...
Phase E2 introduced registry lookup to the hot path, causing 84-88% regression
(70M → 9M ops/sec). This commit restores performance by guarding expensive
hak_super_lookup calls (50-100 cycles each) with conditional compilation.
Key changes:
- tls_sll_box.h push: Full validation in Debug, ss_fast_lookup (O(1)) in Release
- tls_sll_box.h pop: Registry validation in Debug, trust list structure in Release
- tiny_free_fast_v2.inc.h: Header/meta cross-check Debug-only
- malloc_tiny_fast.h: SuperSlab registration check Debug-only
Performance improvement:
- Release build: 2.9M → 87-88M ops/sec (30x improvement)
- Restored to historical UNIFIED-HEADER peak (70-80M range)
Release builds trust:
- Header magic (0xA0) as sufficient allocation origin validation
- TLS SLL linked list structure integrity
- Header-based class_idx classification
Debug builds maintain full validation with expensive registry lookups.
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-04 18:53:04 +09:00
0c0d9c8c0b
Unify Unified Cache API to BASE-only pointer type with Phantom typing
...
Core Changes:
- Modified: core/front/tiny_unified_cache.h
* API signatures changed to use hak_base_ptr_t (Phantom type)
* unified_cache_pop() returns hak_base_ptr_t (was void*)
* unified_cache_push() accepts hak_base_ptr_t base (was void*)
* unified_cache_pop_or_refill() returns hak_base_ptr_t (was void*)
* Added #include "../box/ptr_type_box.h" for Phantom types
- Modified: core/front/tiny_unified_cache.c
* unified_cache_refill() return type changed to hak_base_ptr_t
* Uses HAK_BASE_FROM_RAW() for wrapping return values
* Uses HAK_BASE_TO_RAW() for unwrapping parameters
* Maintains internal void* storage in slots array
- Modified: core/box/tiny_front_cold_box.h
* Uses hak_base_ptr_t from unified_cache_refill()
* Uses hak_base_is_null() for NULL checks
* Maintains tiny_user_offset() for BASE→USER conversion
* Cold path refill integration updated to Phantom types
- Modified: core/front/malloc_tiny_fast.h
* Free path wraps BASE pointer with HAK_BASE_FROM_RAW()
* When pushing to Unified Cache via unified_cache_push()
Design Rationale:
- Unified Cache API now exclusively handles BASE pointers (no USER mixing)
- Phantom types enforce type distinction at compile time (debug mode)
- Zero runtime overhead in Release mode (macros expand to identity)
- Hot paths (tiny_hot_alloc_fast, tiny_hot_free_fast) remain unchanged
- Layout consistency maintained via tiny_user_offset() Box
Validation:
- All 25 Phantom type usage sites verified (25/25 correct)
- HAK_BASE_FROM_RAW(): 5/5 correct wrappings
- HAK_BASE_TO_RAW(): 1/1 correct unwrapping
- hak_base_is_null(): 4/4 correct NULL checks
- Compilation: RELEASE=0 and RELEASE=1 both successful
- Smoke tests: 3/3 passed (simple_alloc, loop 10M, pool_tls)
Type Safety Benefits:
- Prevents USER/BASE pointer confusion at API boundaries
- Compile-time checking in debug builds via Phantom struct
- Zero cost abstraction in release builds
- Clear intent: Unified Cache exclusively stores BASE pointers
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-04 12:20:21 +09:00
c2716f5c01
Implement Phase 2: Headerless Allocator Support (Partial)
...
- Feature: Added HAKMEM_TINY_HEADERLESS toggle (A/B testing)
- Feature: Implemented Headerless layout logic (Offset=0)
- Refactor: Centralized layout definitions in tiny_layout_box.h
- Refactor: Abstracted pointer arithmetic in free path via ptr_conversion_box.h
- Verification: sh8bench passes in Headerless mode (No TLS_SLL_HDR_RESET)
- Known Issue: Regression in Phase 1 mode due to blind pointer conversion logic
2025-12-03 12:11:27 +09:00
195c74756c
Fix mid free routing and relax mid W_MAX
2025-12-01 22:06:10 +09:00
04186341c1
Phase 4-Step2: Add Hot/Cold Path Box (+7.3% performance)
...
Implemented Hot/Cold Path separation using Box pattern for Tiny allocations:
Performance Improvement (without PGO):
- Baseline (Phase 26-A): 53.3 M ops/s
- Hot/Cold Box (Phase 4-Step2): 57.2 M ops/s
- Gain: +7.3% (+3.9 M ops/s)
Implementation:
1. core/box/tiny_front_hot_box.h - Ultra-fast hot path (1 branch)
- Removed range check (caller guarantees valid class_idx)
- Inline cache hit path with branch prediction hints
- Debug metrics with zero overhead in Release builds
2. core/box/tiny_front_cold_box.h - Slow cold path (noinline, cold)
- Refill logic (batch allocation from SuperSlab)
- Drain logic (batch free to SuperSlab)
- Error reporting and diagnostics
3. core/front/malloc_tiny_fast.h - Updated to use Hot/Cold Boxes
- Hot path: tiny_hot_alloc_fast() (1 branch: cache empty check)
- Cold path: tiny_cold_refill_and_alloc() (noinline, cold attribute)
- Clear separation improves i-cache locality
Branch Analysis:
- Baseline: 4-5 branches in hot path (range check + cache check + refill logic mixed)
- Hot/Cold Box: 1 branch in hot path (cache empty check only)
- Reduction: 3-4 branches eliminated from hot path
Design Principles (Box Pattern):
✅ Single Responsibility: Hot path = cache hit only, Cold path = refill/errors
✅ Clear Contract: Hot returns NULL on miss, Cold handles miss
✅ Observable: Debug metrics (TINY_HOT_METRICS_*) gated by NDEBUG
✅ Safe: Branch prediction hints (TINY_HOT_LIKELY/UNLIKELY)
✅ Testable: Isolated hot/cold paths, easy A/B testing
PGO Status:
- Temporarily disabled (build issues with __gcov_merge_time_profile)
- Will re-enable PGO in future commit after resolving gcc/lto issues
- Current benchmarks are without PGO (fair A/B comparison)
Other Changes:
- .gitignore: Added *.d files (dependency files, auto-generated)
- Makefile: PGO targets temporarily disabled (show informational message)
- build_pgo.sh: Temporarily disabled (show "PGO paused" message)
Next: Phase 4-Step3 (Front Config Box, target +5-8%)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-29 11:58:37 +09:00
64ed3d8d8c
Add ss_fast_lookup() for O(1) SuperSlab lookup via mask
...
Replaces expensive hak_super_lookup() (registry hash lookup, 50-100 cycles)
with fast mask-based lookup (~5-10 cycles) in free hot paths.
Algorithm:
1. Mask pointer with SUPERSLAB_SIZE_MIN (1MB) - works for both 1MB and 2MB SS
2. Validate magic (SUPERSLAB_MAGIC)
3. Range check using ss->lg_size
Applied to:
- tiny_free_fast.inc.h: tiny_free_fast() SuperSlab path
- tiny_free_fast_v2.inc.h: LARSON_FIX cross-thread check
- front/malloc_tiny_fast.h: free_tiny_fast() LARSON_FIX path
Note: Performance impact minimal with LARSON_FIX=OFF (default) since
SuperSlab lookup is skipped entirely in that case. Optimization benefits
LARSON_FIX=ON path for safe multi-threaded operation.
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-27 12:47:10 +09:00
d8e3971dc2
Fix cross-thread ownership check: Use bits 8-15 for owner_tid_low
...
Problem:
- TLS_SLL_PUSH_DUP crash in Larson multi-threaded benchmark
- Cross-thread frees incorrectly routed to same-thread TLS path
- Root cause: pthread_t on glibc is 256-byte aligned (TCB base)
so lower 8 bits are ALWAYS 0x00 for ALL threads
Fix:
- Change owner_tid_low from (tid & 0xFF) to ((tid >> 8) & 0xFF)
- Bits 8-15 actually vary between threads, enabling correct detection
- Applied consistently across all ownership check locations:
- superslab_inline.h: ss_owner_try_acquire/release/is_mine
- slab_handle.h: slab_try_acquire
- tiny_free_fast.inc.h: tiny_free_is_same_thread_ss
- tiny_free_fast_v2.inc.h: cross-thread detection
- tiny_superslab_free.inc.h: same-thread check
- ss_allocation_box.c: slab initialization
- hakmem_tiny_superslab.c: ownership handling
Also added:
- Address watcher debug infrastructure (tiny_region_id.h)
- Cross-thread detection in malloc_tiny_fast.h Front Gate
Test results:
- Larson 1T/2T/4T: PASS (no TLS_SLL_PUSH_DUP crash)
- random_mixed: PASS
- Performance: ~20M ops/s (regression from 48M, needs optimization)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-27 11:52:11 +09:00
5c9fe34b40
Enable performance optimizations by default (+557% improvement)
...
## Performance Impact
**Before** (optimizations OFF):
- Random Mixed 256B: 9.4M ops/s
- System malloc ratio: 10.6% (9.5x slower)
**After** (optimizations ON):
- Random Mixed 256B: 61.8M ops/s (+557%)
- System malloc ratio: 70.0% (1.43x slower) ✅
- 3-run average: 60.1M - 62.8M ops/s (±2.2% variance)
## Changes
Enabled 3 critical optimizations by default:
### 1. HAKMEM_SS_EMPTY_REUSE (hakmem_shared_pool.c:810)
```c
// BEFORE: default OFF
empty_reuse_enabled = (e && *e && *e != '0') ? 1 : 0;
// AFTER: default ON
empty_reuse_enabled = (e && *e && *e == '0') ? 0 : 1;
```
**Impact**: Reuse empty slabs before mmap, reduces syscall overhead
### 2. HAKMEM_TINY_UNIFIED_CACHE (tiny_unified_cache.h:69)
```c
// BEFORE: default OFF
g_enable = (e && *e && *e != '0') ? 1 : 0;
// AFTER: default ON
g_enable = (e && *e && *e == '0') ? 0 : 1;
```
**Impact**: Unified TLS cache improves hit rate
### 3. HAKMEM_FRONT_GATE_UNIFIED (malloc_tiny_fast.h:42)
```c
// BEFORE: default OFF
g_enable = (e && *e && *e != '0') ? 1 : 0;
// AFTER: default ON
g_enable = (e && *e && *e == '0') ? 0 : 1;
```
**Impact**: Unified front gate reduces dispatch overhead
## ENV Override
Users can still disable optimizations if needed:
```bash
export HAKMEM_SS_EMPTY_REUSE=0 # Disable empty slab reuse
export HAKMEM_TINY_UNIFIED_CACHE=0 # Disable unified cache
export HAKMEM_FRONT_GATE_UNIFIED=0 # Disable unified front gate
```
## Comparison to Competitors
```
mimalloc: 113.34M ops/s (1.83x faster than HAKMEM)
System malloc: 88.20M ops/s (1.43x faster than HAKMEM)
HAKMEM: 61.80M ops/s ✅ Competitive performance
```
## Files Modified
- core/hakmem_shared_pool.c - EMPTY_REUSE default ON
- core/front/tiny_unified_cache.h - UNIFIED_CACHE default ON
- core/front/malloc_tiny_fast.h - FRONT_GATE_UNIFIED default ON
🚀 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-22 01:29:05 +09:00
5b36c1c908
Phase 26: Front Gate Unification - Tiny allocator fast path (+12.9%)
...
Implementation:
- New single-layer malloc/free path for Tiny (≤1024B) allocations
- Bypasses 3-layer overhead: malloc → hak_alloc_at (236 lines) → wrapper → tiny_alloc_fast
- Leverages Phase 23 Unified Cache (tcache-style, 2-3 cache misses)
- Safe fallback to normal path on Unified Cache miss
Performance (Random Mixed 256B, 100K iterations):
- Baseline (Phase 26 OFF): 11.33M ops/s
- Phase 26 ON: 12.79M ops/s (+12.9%)
- Prediction (ChatGPT): +10-15% → Actual: +12.9% (perfect match!)
Bug fixes:
- Initialization bug: Added hak_init() call before fast path
- Page boundary SEGV: Added guard for offset_in_page == 0
Also includes Phase 23 debug log fixes:
- Guard C2_CARVE logs with #if !HAKMEM_BUILD_RELEASE
- Guard prewarm logs with #if !HAKMEM_BUILD_RELEASE
- Set Hot_2048 as default capacity (C2/C3=2048, others=64)
Files:
- core/front/malloc_tiny_fast.h: Phase 26 implementation (145 lines)
- core/box/hak_wrappers.inc.h: Fast path integration (+28 lines)
- core/front/tiny_unified_cache.h: Hot_2048 default
- core/tiny_refill_opt.h: C2_CARVE log guard
- core/box/ss_hot_prewarm_box.c: Prewarm log guard
- CURRENT_TASK.md: Phase 26 completion documentation
ENV variables:
- HAKMEM_FRONT_GATE_UNIFIED=1 (enable Phase 26, default: OFF)
- HAKMEM_TINY_UNIFIED_CACHE=1 (Phase 23, required)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-17 05:29:08 +09:00