Files
hakmem/CURRENT_TASK.md

221 lines
12 KiB
Markdown
Raw Normal View History

# CURRENT TASK (Phase 12: Shared SuperSlab Pool Debug Phase)
Phase12 の設計に沿った shared SuperSlab pool 実装および Box API 境界リファクタリングは導入済み。
現在は **shared backend 有効状態での SEGV 解消と安定化** を行うデバッグフェーズに入っている。
Fix: CRITICAL multi-threaded freelist/remote queue race condition Root Cause: =========== Freelist and remote queue contained the SAME blocks, causing use-after-free: 1. Thread A (owner): pops block X from freelist → allocates to user 2. User writes data ("ab") to block X 3. Thread B (remote): free(block X) → adds to remote queue 4. Thread A (later): drains remote queue → *(void**)block_X = chain_head → OVERWRITES USER DATA! 💥 The freelist pop path did NOT drain the remote queue first, so blocks could be simultaneously in both freelist and remote queue. Fix: ==== Add remote queue drain BEFORE freelist pop in refill path: core/hakmem_tiny_refill_p0.inc.h: - Call _ss_remote_drain_to_freelist_unsafe() BEFORE trc_pop_from_freelist() - Add #include "superslab/superslab_inline.h" - This ensures freelist and remote queue are mutually exclusive Test Results: ============= BEFORE: larson_hakmem (4 threads): ❌ SEGV in seconds (freelist corruption) AFTER: larson_hakmem (4 threads): ✅ 931,629 ops/s (1073 sec stable run) bench_random_mixed: ✅ 1,020,163 ops/s (no crashes) Evidence: - Fail-Fast logs showed next pointer corruption: 0x...6261 (ASCII "ab") - Single-threaded benchmarks worked (865K ops/s) - Multi-threaded Larson crashed immediately - Fix eliminates all crashes in both benchmarks Files: - core/hakmem_tiny_refill_p0.inc.h: Add remote drain before freelist pop - CURRENT_TASK.md: Document fix details 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 01:35:45 +09:00
本タスクでは以下をゴールとする:
Phase 7-1 PoC: Region-ID Direct Lookup (+39%~+436% improvement!) Implemented ultra-fast header-based free path that eliminates SuperSlab lookup bottleneck (100+ cycles → 5-10 cycles). ## Key Changes 1. **Smart Headers** (core/tiny_region_id.h): - 1-byte header before each allocation stores class_idx - Memory layout: [Header: 1B] [User data: N-1B] - Overhead: <2% average (0% for Slab[0] using wasted padding) 2. **Ultra-Fast Allocation** (core/tiny_alloc_fast.inc.h): - Write header at base: *base = class_idx - Return user pointer: base + 1 3. **Ultra-Fast Free** (core/tiny_free_fast_v2.inc.h): - Read class_idx from header (ptr-1): 2-3 cycles - Push base (ptr-1) to TLS freelist: 3-5 cycles - Total: 5-10 cycles (vs 500+ cycles current!) 4. **Free Path Integration** (core/box/hak_free_api.inc.h): - Removed SuperSlab lookup from fast path - Direct header validation (no lookup needed!) 5. **Size Class Adjustment** (core/hakmem_tiny.h): - Max tiny size: 1023B (was 1024B) - 1024B requests → Mid allocator fallback ## Performance Results | Size | Baseline | Phase 7 | Improvement | |------|----------|---------|-------------| | 128B | 1.22M | 6.54M | **+436%** 🚀 | | 512B | 1.22M | 1.70M | **+39%** | | 1023B | 1.22M | 1.92M | **+57%** | ## Build & Test Enable Phase 7: make HEADER_CLASSIDX=1 bench_random_mixed_hakmem Run benchmark: HAKMEM_TINY_USE_SUPERSLAB=1 ./bench_random_mixed_hakmem 10000 128 1234567 ## Known Issues - 1024B requests fallback to Mid allocator (by design) - Target 40-60M ops/s not yet reached (current: 1.7-6.5M) - Further optimization needed (TLS capacity tuning, refill optimization) ## Credits Design: ChatGPT Pro Ultrathink, Claude Code Implementation: Claude Code with Task Agent Ultrathink support 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 03:18:17 +09:00
- shared Superslab pool backend (`hakmem_shared_pool.[ch]` + `hak_tiny_alloc_superslab_backend_shared`) を
Box API (`hak_tiny_alloc_superslab_box`) 経由で安全に運用できる状態にする。
- `bench_random_mixed_hakmem` 実行時に SEGV が発生しないことを確認し、
shared backend を実用レベルの「最小安定実装」として確定させる。
---
## 2. 現状サマリ(実装済み)
1. Box/API 境界
- tiny フロントエンドから Superslab への入口:
- `hak_tiny_alloc_superslab_box(int class_idx)` に一本化。
- TLS SLL:
- slow path を含む呼び出しは `tls_sll_box.h` (`tls_sll_pop(int, void**)` 等) の Box API 経由に統一。
2. shared Superslab pool 実装
- `hakmem_shared_pool.[ch]`:
- `SharedSuperSlabPool g_shared_pool`
`shared_pool_init`, `shared_pool_acquire_slab`, `shared_pool_release_slab` を実装。
- SuperSlab を global に管理し、slab 単位で `class_idx` を割当/解放する shared pool 構造を提供。
- `hakmem_tiny_superslab.c`:
- `hak_tiny_alloc_superslab_backend_shared(int class_idx)`:
- `shared_pool_acquire_slab` により `(ss, slab_idx)` を取得。
- `superslab_init_slab` で未初期化 slab を初期化。
- ジオメトリは `SUPERSLAB_SLAB0_DATA_OFFSET` + `slab_idx * SUPERSLAB_SLAB_USABLE_SIZE` + `used * stride` を使用。
- 単純 bump でブロックを返却。
- `hak_tiny_alloc_superslab_backend_legacy(int class_idx)`:
- 旧 per-class `g_superslab_heads` ベースの実装を static backend に封じ込め。
- `hak_tiny_alloc_superslab_box(int class_idx)`:
- shared backend → 失敗時に legacy backend へフォールバックする実装に更新。
- `make bench_random_mixed_hakmem`:
- ビルドは成功し、shared backend を含む構造的な不整合は解消済み。
3. 現状の問題2025-11-14 更新)
- `bench_random_mixed_hakmem` は SLLTLS 単方向リスト)有効時に早期 SEGV。
- SLL を無効化(`HAKMEM_TINY_TLS_SLL=0`すると、shared ON/OFF いずれも安定完走Throughput 表示)。
- よって、現時点のクラッシュ主因は「共有SS」ではなく「SLL フロント経路の不整合BASE/USER/next 取り扱い)」である可能性が高い。
以降は、この SEGV を潰し「shared Superslab pool 最小安定版」を完成させるためのデバッグタスクとする。
## 3. デバッグフェーズの具体タスク
### 3-1. shared backend ON/OFF 制御と原因切り分け
1. shared backend スイッチ導入・確認
- `hak_tiny_alloc_superslab_box(int class_idx)` に環境変数または定数フラグを導入し:
- `HAKMEM_TINY_SS_SHARED=0` → legacy backend のみ(回帰確認用)
- `HAKMEM_TINY_SS_SHARED=1` → 現行 shared backendデバッグ対象
- 手順:
- legacy 固定で `bench_random_mixed_hakmem` 実行 → SEGV が消えることを確認し、問題が shared 経路に限定されることを保証。
### 3-2. shared slab メタデータの一貫性検証
2. `shared_pool_acquire_slab``hak_tiny_alloc_superslab_backend_shared` の整合確認
- 確認事項:
- `class_idx` 割当時に:
- `meta->class_idx` が正しく `class_idx` にセットされているか。
- `superslab_init_slab` 呼び出し後、`capacity > 0`, `used == 0`, `freelist == NULL` になっているか。
- `meta->used++` / `total_active_blocks++` の更新が free パスの期待と一致しているか。
- 必要なら:
- debug build で `assert(meta->class_idx == class_idx)` 等を追加して早期検出。
3. free/refill 経路との整合性
- 対象ファイル:
- `tiny_superslab_free.inc.h`
- `hakmem_tiny_free.inc`
- `hakmem_tiny_bg_spill.c`
- 確認事項:
- pointer→SuperSlab→TinySlabMeta 解決ロジックが:
- `meta->class_idx` ベースで正しい class を判定しているか。
- shared/legacy の違いに依存せず動作するか。
- 空 slab 判定時に:
- `shared_pool_release_slab` を呼ぶ条件と `meta->used == 0` の扱いが矛盾していないか。
- 必要な修正:
- shared slab 専用の「空になった slab の返却」パスを導入し、UNASSIGNED への戻しを一元化。
### 3-3. Superslab registry / LRU / shared pool の連携確認
4. Registry & LRU 連携
- `hakmem_super_registry.c` の:
- `hak_super_register`, `hak_super_unregister`
- `hak_ss_lru_pop/push`
- 確認:
- shared pool で確保した SuperSlab も registry に登録されていること。
- LRU 経由再利用時に `class_idx`/slab 割付が破綻していないこと。
- 必要に応じて:
- shared pool 管理下の SuperSlab を区別するフラグや、再利用前のメタリセットを追加。
### 3-4. SEGV の直接解析
5. gdb によるスタックトレース取得(実施)
- コマンド例:
- `cd hakmem`
- `gdb --args ./bench_random_mixed_hakmem`
- `run`
- `bt`
- 結果(抜粋):
- `hak_tiny_alloc_fast_wrapper()` 内で SEGV。SLL 無効化で再現しないため、SLL 経路の BASE/USER/next の整合に絞る。
### 3-5. 安定版 shared Superslab pool の確定
6. 修正後確認
- `HAKMEM_TINY_SS_SHARED=1`shared 有効)で:
- `bench_random_mixed_hakmem` が SEGV 無しで完走すること。
- 簡易的な統計・ログで:
- shared Superslab が複数 class で共有されていること。
- メタデータ破綻や異常な解放が発生していないこと。
- これをもって:
- 「Phase12 Shared Superslab Pool 最小安定版」が完了。
### 2-3. TLS / SLL / Refill の整合性確保
**スコープ: `core/hakmem_tiny_refill.inc.h`, `core/hakmem_tiny_tls_ops.h`, `core/hakmem_tiny.c`(局所)**
6. **sll_refill_small_from_ss の Phase12 対応**
- 入力: `class_idx`, `max_take`
- 動作:
- shared pool から該当 `class_idx` の slab を取得 or bind。
- slab の freelist/bump から `max_take` 個を TLS SLL に積む。
- ここでは:
- **g_sll_cap_override を参照しない**(将来廃止しやすい形に)。
- cap 計算は `sll_cap_for_class(class_idx, mag_cap)` に集約。
7. **tiny_fast_refill_and_take / TLS SLL 経路の一貫性**
- `tiny_fast_refill_and_take` が:
- まず TLS SLL / FastCache を見る。
- 足りなければ `sll_refill_small_from_ss` を必ず経由するよう整理(旧経路の枝刈り)。
- ただし:
- 既存インラインとの整合性を崩さないよう、**分岐削除は段階的に**行う。
### 2-4. g_sll_cap_override の段階的無効化(安全版)
8. **参照経路のサニタイズ(非破壊)**
- `hakmem_tiny_intel.inc`, `hakmem_tiny_background.inc`, `hakmem_tiny_init.inc` などで:
- g_sll_cap_override を書き換える経路を `#if 0` or コメントアウトで停止。
- 配列定義自体はそのまま残し、リンク切れを防ぐ。
- `sll_cap_for_class()` は Phase12 ポリシーに従う実装に置き換える。
- これにより:
- 実際の SLL cap は sll_cap_for_class 経由に統一されるが、
- ABI/シンボル互換性は保持される。
9. **ビルド & アセンブリ確認**
- `make bench_random_mixed_hakmem`
- `gdb -q ./bench_random_mixed_hakmem -ex "disassemble sll_refill_small_from_ss" -ex "quit"`
- 確認項目:
- g_sll_cap_override 更新経路は実際には使われていない。
- sll_refill_small_from_ss が shared SuperSlab pool を用いる単一ロジックになっている。
### 2-5. Shared Pool 実装の検証とバグ切り分け
10. **機能検証**
- `bench_random_mixed_hakmem` を実行:
- SIGSEGV / abort の有無
- ログと `HAKMEM_TINY_SUPERSLAB_TRACE` で shared pool の挙動を確認。
11. **パフォーマンス確認**
- 目標: 設計書の期待値に対し、オーダーとして妥当な速度になっているか:
- 9M → 7090M ops/s のレンジを狙う(まずは退行していないことを確認)。
12. **問題発生時の切り分け**
- クラッシュ/不正挙動があれば:
- まず shared pool 周辺slab class_idx, freelist 管理, owner/bind/unbindに絞って原因特定。
- Tiny front-end (bump, SLL, HotMag 等) を疑うのはその後。
Phase 7-1 PoC: Region-ID Direct Lookup (+39%~+436% improvement!) Implemented ultra-fast header-based free path that eliminates SuperSlab lookup bottleneck (100+ cycles → 5-10 cycles). ## Key Changes 1. **Smart Headers** (core/tiny_region_id.h): - 1-byte header before each allocation stores class_idx - Memory layout: [Header: 1B] [User data: N-1B] - Overhead: <2% average (0% for Slab[0] using wasted padding) 2. **Ultra-Fast Allocation** (core/tiny_alloc_fast.inc.h): - Write header at base: *base = class_idx - Return user pointer: base + 1 3. **Ultra-Fast Free** (core/tiny_free_fast_v2.inc.h): - Read class_idx from header (ptr-1): 2-3 cycles - Push base (ptr-1) to TLS freelist: 3-5 cycles - Total: 5-10 cycles (vs 500+ cycles current!) 4. **Free Path Integration** (core/box/hak_free_api.inc.h): - Removed SuperSlab lookup from fast path - Direct header validation (no lookup needed!) 5. **Size Class Adjustment** (core/hakmem_tiny.h): - Max tiny size: 1023B (was 1024B) - 1024B requests → Mid allocator fallback ## Performance Results | Size | Baseline | Phase 7 | Improvement | |------|----------|---------|-------------| | 128B | 1.22M | 6.54M | **+436%** 🚀 | | 512B | 1.22M | 1.70M | **+39%** | | 1023B | 1.22M | 1.92M | **+57%** | ## Build & Test Enable Phase 7: make HEADER_CLASSIDX=1 bench_random_mixed_hakmem Run benchmark: HAKMEM_TINY_USE_SUPERSLAB=1 ./bench_random_mixed_hakmem 10000 128 1234567 ## Known Issues - 1024B requests fallback to Mid allocator (by design) - Target 40-60M ops/s not yet reached (current: 1.7-6.5M) - Further optimization needed (TLS capacity tuning, refill optimization) ## Credits Design: ChatGPT Pro Ultrathink, Claude Code Implementation: Claude Code with Task Agent Ultrathink support 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 03:18:17 +09:00
---
Fix: CRITICAL multi-threaded freelist/remote queue race condition Root Cause: =========== Freelist and remote queue contained the SAME blocks, causing use-after-free: 1. Thread A (owner): pops block X from freelist → allocates to user 2. User writes data ("ab") to block X 3. Thread B (remote): free(block X) → adds to remote queue 4. Thread A (later): drains remote queue → *(void**)block_X = chain_head → OVERWRITES USER DATA! 💥 The freelist pop path did NOT drain the remote queue first, so blocks could be simultaneously in both freelist and remote queue. Fix: ==== Add remote queue drain BEFORE freelist pop in refill path: core/hakmem_tiny_refill_p0.inc.h: - Call _ss_remote_drain_to_freelist_unsafe() BEFORE trc_pop_from_freelist() - Add #include "superslab/superslab_inline.h" - This ensures freelist and remote queue are mutually exclusive Test Results: ============= BEFORE: larson_hakmem (4 threads): ❌ SEGV in seconds (freelist corruption) AFTER: larson_hakmem (4 threads): ✅ 931,629 ops/s (1073 sec stable run) bench_random_mixed: ✅ 1,020,163 ops/s (no crashes) Evidence: - Fail-Fast logs showed next pointer corruption: 0x...6261 (ASCII "ab") - Single-threaded benchmarks worked (865K ops/s) - Multi-threaded Larson crashed immediately - Fix eliminates all crashes in both benchmarks Files: - core/hakmem_tiny_refill_p0.inc.h: Add remote drain before freelist pop - CURRENT_TASK.md: Document fix details 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 01:35:45 +09:00
## 3. 実装ルール(再確認)
feat: Pool TLS Phase 1 - Lock-free TLS freelist (173x improvement, 2.3x vs System) ## Performance Results Pool TLS Phase 1: 33.2M ops/s System malloc: 14.2M ops/s Improvement: 2.3x faster! 🏆 Before (Pool mutex): 192K ops/s (-95% vs System) After (Pool TLS): 33.2M ops/s (+133% vs System) Total improvement: 173x ## Implementation **Architecture**: Clean 3-Box design - Box 1 (TLS Freelist): Ultra-fast hot path (5-6 cycles) - Box 2 (Refill Engine): Fixed refill counts, batch carving - Box 3 (ACE Learning): Not implemented (future Phase 3) **Files Added** (248 LOC total): - core/pool_tls.h (27 lines) - TLS freelist API - core/pool_tls.c (104 lines) - Hot path implementation - core/pool_refill.h (12 lines) - Refill API - core/pool_refill.c (105 lines) - Batch carving + backend **Files Modified**: - core/box/hak_alloc_api.inc.h - Pool TLS fast path integration - core/box/hak_free_api.inc.h - Pool TLS free path integration - Makefile - Build rules + POOL_TLS_PHASE1 flag **Scripts Added**: - build_hakmem.sh - One-command build (Phase 7 + Pool TLS) - run_benchmarks.sh - Comprehensive benchmark runner **Documentation Added**: - POOL_TLS_LEARNING_DESIGN.md - Complete 3-Box architecture + contracts - POOL_IMPLEMENTATION_CHECKLIST.md - Phase 1-3 guide - POOL_HOT_PATH_BOTTLENECK.md - Mutex bottleneck analysis - POOL_FULL_FIX_EVALUATION.md - Design evaluation - CURRENT_TASK.md - Updated with Phase 1 results ## Technical Highlights 1. **1-byte Headers**: Magic byte 0xb0 | class_idx for O(1) free 2. **Zero Contention**: Pure TLS, no locks, no atomics 3. **Fixed Refill Counts**: 64→16 blocks (no learning in Phase 1) 4. **Direct mmap Backend**: Bypasses old Pool mutex bottleneck ## Contracts Enforced (A-D) - Contract A: Queue overflow policy (DROP, never block) - N/A Phase 1 - Contract B: Policy scope limitation (next refill only) - N/A Phase 1 - Contract C: Memory ownership (fixed ring buffer) - N/A Phase 1 - Contract D: API boundaries (no cross-box includes) ✅ ## Overall HAKMEM Status | Size Class | Status | |------------|--------| | Tiny (8-1024B) | 🏆 WINS (92-149% of System) | | Mid-Large (8-32KB) | 🏆 DOMINANT (233% of System) | | Large (>1MB) | Neutral (mmap) | HAKMEM now BEATS System malloc in ALL major categories! 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 23:53:25 +09:00
- hakmem_tiny.c は write_to_file で全書き換えしない。
- 変更は:
- `#if 0` / コメントアウト
- 局所的な関数実装差し替え
- 新しい shared pool 関数の追加
- 既存呼び出し先の付け替え
に限定し、逐次ビルド確認する。
Phase 7-1 PoC: Region-ID Direct Lookup (+39%~+436% improvement!) Implemented ultra-fast header-based free path that eliminates SuperSlab lookup bottleneck (100+ cycles → 5-10 cycles). ## Key Changes 1. **Smart Headers** (core/tiny_region_id.h): - 1-byte header before each allocation stores class_idx - Memory layout: [Header: 1B] [User data: N-1B] - Overhead: <2% average (0% for Slab[0] using wasted padding) 2. **Ultra-Fast Allocation** (core/tiny_alloc_fast.inc.h): - Write header at base: *base = class_idx - Return user pointer: base + 1 3. **Ultra-Fast Free** (core/tiny_free_fast_v2.inc.h): - Read class_idx from header (ptr-1): 2-3 cycles - Push base (ptr-1) to TLS freelist: 3-5 cycles - Total: 5-10 cycles (vs 500+ cycles current!) 4. **Free Path Integration** (core/box/hak_free_api.inc.h): - Removed SuperSlab lookup from fast path - Direct header validation (no lookup needed!) 5. **Size Class Adjustment** (core/hakmem_tiny.h): - Max tiny size: 1023B (was 1024B) - 1024B requests → Mid allocator fallback ## Performance Results | Size | Baseline | Phase 7 | Improvement | |------|----------|---------|-------------| | 128B | 1.22M | 6.54M | **+436%** 🚀 | | 512B | 1.22M | 1.70M | **+39%** | | 1023B | 1.22M | 1.92M | **+57%** | ## Build & Test Enable Phase 7: make HEADER_CLASSIDX=1 bench_random_mixed_hakmem Run benchmark: HAKMEM_TINY_USE_SUPERSLAB=1 ./bench_random_mixed_hakmem 10000 128 1234567 ## Known Issues - 1024B requests fallback to Mid allocator (by design) - Target 40-60M ops/s not yet reached (current: 1.7-6.5M) - Further optimization needed (TLS capacity tuning, refill optimization) ## Credits Design: ChatGPT Pro Ultrathink, Claude Code Implementation: Claude Code with Task Agent Ultrathink support 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 03:18:17 +09:00
---
## 4. 直近の変更2025-11-14 追記)
- 定数/APIの復元・宣言不足解消`SUPERSLAB_LG_*`, 所有権API, active dec, fail-fast スタブ 等)。
- Box 2 drain 境界を `_ss_remote_drain_to_freelist_unsafe()` に一本化。
- `tiny_fast_pop()` が USER を返していた不具合を修正BASE返却へ
- SLL トグルの実効化:
- free v2ヘッダ系`g_tls_sll_enable==0` 時は即スローパスへ。
- alloc fast でも SLL 無効時は TLS SLL pop を完全スキップ。
- `tls_sll_box` の capacity > 1<<20 無制限扱いへ過剰警告を抑制)。
feat: Pool TLS Phase 1 - Lock-free TLS freelist (173x improvement, 2.3x vs System) ## Performance Results Pool TLS Phase 1: 33.2M ops/s System malloc: 14.2M ops/s Improvement: 2.3x faster! 🏆 Before (Pool mutex): 192K ops/s (-95% vs System) After (Pool TLS): 33.2M ops/s (+133% vs System) Total improvement: 173x ## Implementation **Architecture**: Clean 3-Box design - Box 1 (TLS Freelist): Ultra-fast hot path (5-6 cycles) - Box 2 (Refill Engine): Fixed refill counts, batch carving - Box 3 (ACE Learning): Not implemented (future Phase 3) **Files Added** (248 LOC total): - core/pool_tls.h (27 lines) - TLS freelist API - core/pool_tls.c (104 lines) - Hot path implementation - core/pool_refill.h (12 lines) - Refill API - core/pool_refill.c (105 lines) - Batch carving + backend **Files Modified**: - core/box/hak_alloc_api.inc.h - Pool TLS fast path integration - core/box/hak_free_api.inc.h - Pool TLS free path integration - Makefile - Build rules + POOL_TLS_PHASE1 flag **Scripts Added**: - build_hakmem.sh - One-command build (Phase 7 + Pool TLS) - run_benchmarks.sh - Comprehensive benchmark runner **Documentation Added**: - POOL_TLS_LEARNING_DESIGN.md - Complete 3-Box architecture + contracts - POOL_IMPLEMENTATION_CHECKLIST.md - Phase 1-3 guide - POOL_HOT_PATH_BOTTLENECK.md - Mutex bottleneck analysis - POOL_FULL_FIX_EVALUATION.md - Design evaluation - CURRENT_TASK.md - Updated with Phase 1 results ## Technical Highlights 1. **1-byte Headers**: Magic byte 0xb0 | class_idx for O(1) free 2. **Zero Contention**: Pure TLS, no locks, no atomics 3. **Fixed Refill Counts**: 64→16 blocks (no learning in Phase 1) 4. **Direct mmap Backend**: Bypasses old Pool mutex bottleneck ## Contracts Enforced (A-D) - Contract A: Queue overflow policy (DROP, never block) - N/A Phase 1 - Contract B: Policy scope limitation (next refill only) - N/A Phase 1 - Contract C: Memory ownership (fixed ring buffer) - N/A Phase 1 - Contract D: API boundaries (no cross-box includes) ✅ ## Overall HAKMEM Status | Size Class | Status | |------------|--------| | Tiny (8-1024B) | 🏆 WINS (92-149% of System) | | Mid-Large (8-32KB) | 🏆 DOMINANT (233% of System) | | Large (>1MB) | Neutral (mmap) | HAKMEM now BEATS System malloc in ALL major categories! 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 23:53:25 +09:00
暫定ガイドshared の検証を先に進めるため)
- `HAKMEM_TINY_TLS_SLL=0` で shared ON/OFF の安定動作を確認し、shared 経路の SEGV 有無を切り分ける。
次の一手SLL ルートの最小修正)
1) SLL push/pop すべての呼び出しを Box API 経由BASEのみに強制。直書き・next手計算を禁止。
2) `tls_sll_box` にデバッグ限定の軽量ガードを追加slab範囲stride整合して最初の破綻ードを特定。
3) 必要なら一時的に `HAKMEM_TINY_SLL_C03_ONLY=1`C0C3 のみ SLL 使用)で範囲を狭め、原因箇所を早期確定。
### 現在のトリアージ結果2025-11-14 後半)
- 共有SS: SLL を C0..C4 に限定(`HAKMEM_TINY_SLL_MASK=0x1F`)で ON は安定完走。OFFlegacyは SEGV別途
- SLL: C5256Bを含めると SEGV 再現。`HAKMEM_TINY_HOTPATH_CLASS5=0` にすると安定化。
- 対策(小変更):
- クラス4以上の alloc fast POP は `tls_sll_pop()`Box APIで安全化。
- SLL PUSH は `HAKMEM_TINY_SLL_SAFEHEADER=1` でヘッダ不一致時に上書きせず拒否blind write回避
- class5 ホットパスは POP/PUSH をガード付き(`tls_list_pop/push`)に変更。
- それでも `g_tiny_hotpath_class5=1` だと再現 → ホットパス経路のどこかに BASE/USER/next 整合不備が残存。
- 当面の安定デフォルト: `g_tiny_hotpath_class5=0`Env で A/B 可: `HAKMEM_TINY_HOTPATH_CLASS5=1`)。
### 次の実装(根治方針/小粒)
1) 共有SSの観測を先に確定`HAKMEM_TINY_SLL_MASK=0x1F` でON/OFFのA/B、軽いFailFast/リング有効)
2) C5根治: C5のみON`HAKMEM_TINY_SLL_MASK=0x20``HAKMEM_TINY_SLL_SAFEHEADER=1``HAKMEM_TINY_HOTPATH_CLASS5=0`)で短尺実行→最初の破綻箇所をログ採取
3) 該当箇所BASE/USER/next、ヘッダ整合に点で外科修正~2030行
4) 段階的にマスク拡張C6→C7し再検証。