Files
hakmem/docs/analysis/PHASE43_HEADER_WRITE_TAX_REDUCTION_INSTRUCTIONS.md

71 lines
2.7 KiB
Markdown
Raw Normal View History

Phase 54-60: Memory-Lean mode, Balanced mode stabilization, M1 (50%) achievement ## Summary Completed Phase 54-60 optimization work: **Phase 54-56: Memory-Lean mode (LEAN+OFF prewarm suppression)** - Implemented ss_mem_lean_env_box.h with ENV gates - Balanced mode (LEAN+OFF) promoted as production default - Result: +1.2% throughput, better stability, zero syscall overhead - Added to bench_profile.h: MIXED_TINYV3_C7_BALANCED preset **Phase 57: 60-min soak finalization** - Balanced mode: 60-min soak, RSS drift 0%, CV 5.38% - Speed-first mode: 60-min soak, RSS drift 0%, CV 1.58% - Syscall budget: 1.25e-7/op (800× under target) - Status: PRODUCTION-READY **Phase 59: 50% recovery baseline rebase** - hakmem FAST (Balanced): 59.184M ops/s, CV 1.31% - mimalloc: 120.466M ops/s, CV 3.50% - Ratio: 49.13% (M1 ACHIEVED within statistical noise) - Superior stability: 2.68× better CV than mimalloc **Phase 60: Alloc pass-down SSOT (NO-GO)** - Implemented alloc_passdown_ssot_env_box.h - Modified malloc_tiny_fast.h for SSOT pattern - Result: -0.46% (NO-GO) - Key lesson: SSOT not applicable where early-exit already optimized ## Key Metrics - Performance: 49.13% of mimalloc (M1 effectively achieved) - Stability: CV 1.31% (superior to mimalloc 3.50%) - Syscall budget: 1.25e-7/op (excellent) - RSS: 33MB stable, 0% drift over 60 minutes ## Files Added/Modified New boxes: - core/box/ss_mem_lean_env_box.h - core/box/ss_release_policy_box.{h,c} - core/box/alloc_passdown_ssot_env_box.h Scripts: - scripts/soak_mixed_single_process.sh - scripts/analyze_epoch_tail_csv.py - scripts/soak_mixed_rss.sh - scripts/calculate_percentiles.py - scripts/analyze_soak.py Documentation: Phase 40-60 analysis documents ## Design Decisions 1. Profile separation (core/bench_profile.h): - MIXED_TINYV3_C7_SAFE: Speed-first (no LEAN) - MIXED_TINYV3_C7_BALANCED: Balanced mode (LEAN+OFF) 2. Box Theory compliance: - All ENV gates reversible (HAKMEM_SS_MEM_LEAN, HAKMEM_ALLOC_PASSDOWN_SSOT) - Single conversion points maintained - No physical deletions (compile-out only) 3. Lessons learned: - SSOT effective only where redundancy exists (Phase 60 showed limits) - Branch prediction extremely effective (~0 cycles for well-predicted branches) - Early-exit pattern valuable even when seemingly redundant 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-17 06:24:01 +09:00
# Phase 43 — Header write tax reductionalloc hot: preserve-class skip
## 目的
FAST build`make perf_fast`)で、`tiny_region_id_write_header`alloc hotの **実作業**を減らして +1% 以上を狙う。
Phase 42 の結論: gate はもう Top 50 圏外。次は「実作業header store」が芯。
## 背景(観測)
- `tiny_region_id_write_header` が runtime profiling で大きいalloc の固定作業)。
- Tiny の nextptr 仕様では **C1C6 は header を保持**next_off=1、C0/C7 は header を上書きnext_off=0
- `core/tiny_nextptr.h`SSOT
- `core/box/tiny_header_box.h``tiny_class_preserves_header()`
つまり **C1C6 については “free 中に header が壊れない”**前提が成立するので、alloc で毎回 header を書く必要が本来ない。
## 方針Box Theory
- Standard/OBSERVE は触らない(安全・互換を維持)。
- FAST`HAKMEM_BENCH_MINIMAL=1`の中だけで、alloc 側の header write を減らす。
- link-out / 物理削除は禁止layout tax の前例がある)。
## Step 0: Invariant 確認(必須)
1) nextptr 仕様確認
- C0: next_off=0header 上書き)
- C1C6: next_off=1header 保持)
- C7: next_off=0デフォルト
2) 「header 保持クラス」の block が最初に header を持つこと
- linear carve / refill 経路で、C1C6 には header が書かれていることを確認する。
- 例: `core/tiny_refill_opt.h` の carve/popfreenode で `tiny_header_write_if_preserved()` が走ること
## Step 1: 変更FAST 限定)
ターゲット:
- `core/tiny_region_id.h``tiny_region_id_write_header(...)` の hot 経路
変更方針:
- `tiny_class_preserves_header(class_idx)==true` のクラスC1C6について、
- FAST では **alloc 時の header store をスキップ**
- `user = header_ptr + 1` を返すだけheader は “既に正しい”前提)
- `tiny_class_preserves_header(class_idx)==false`C0/C7だけは **従来どおり header を書く**
重要:
- 既存の Phase 21 “HOTFULL” の hot/cold split を壊さないFAST でも HOTFULL の直線性を維持)。
## Step 2: A/BFAST 10-run
baseline:
- `make perf_fast`FAST v3
treatment:
- `make perf_fast`FAST v4 / Phase 43
判定risk 高めなので閾値を上げる):
- GO: +1.0% 以上
- NEUTRAL: ±1.0%
- NO-GO: -1.0% 以下(即 revert
## Step 3: 健康診断(最小)
- `make perf_observe` を 1回crash/ASSERT がないこと)
## ログ
- `docs/analysis/PHASE43_HEADER_WRITE_TAX_REDUCTION_RESULTS.md` を作成し、10-run mean/median と判定を書く。
- `docs/analysis/PERFORMANCE_TARGETS_SCORECARD.md` の FAST build 履歴を更新。