Phase 15 完了: CURRENT_TASK更新 - ベンチマーク結果記録
Phase 15 Box Separation / Wrapper Domain Check 完了を記録: - 99.29% BenchMeta 正常解放 (domain check 成功) - 0.71% page-aligned leak (acceptable tradeoff) - Performance: 14.9-16.6M ops/s (stable, crash-free) - vs System malloc: 18.1% (5.5倍差) Next: Phase 16 - Tiny守備範囲最適化 (512/1024B → Mid へ移す A/B)
This commit is contained in:
124
CURRENT_TASK.md
124
CURRENT_TASK.md
@ -1,9 +1,11 @@
|
|||||||
# CURRENT TASK – Phase 14 (TinyUltraHot / C2/C3 Ultra-Fast Path)
|
# CURRENT TASK – Phase 15 (Box Separation / Wrapper Domain Check)
|
||||||
|
|
||||||
**Date**: 2025-11-15
|
**Date**: 2025-11-16
|
||||||
**Status**: ✅ TinyUltraHot 実装完了 (+21-36% on C2/C3 workloads), Phase 13 TinyHeapV2 = 安全な stub
|
**Status**: ✅ Phase 15 完了 - Box 境界違反を修正、99.29% BenchMeta 正常解放、crash-free 安定動作
|
||||||
**Owner**: Claude Code → 実装完了
|
**Owner**: Claude Code → 実装完了
|
||||||
|
|
||||||
|
**Next**: Phase 16 - Tiny 守備範囲の最適化 (512/1024B を Mid に移す A/B テスト)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 1. 全体の今どこ
|
## 1. 全体の今どこ
|
||||||
@ -174,9 +176,121 @@ typedef struct {
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 3. 最近のバグ修正・仕様調整(もう触らなくてよい箱)
|
## 3. Phase 15: Box Separation / Wrapper Domain Check (2025-11-16) ✅
|
||||||
|
|
||||||
### 3.1 Tiny / Mid サイズ境界ギャップ修正(完了)
|
### 3.1 問題発見 - Box 境界違反
|
||||||
|
|
||||||
|
**ChatGPT 先生の分析**:
|
||||||
|
- free() wrapper が**無条件で全ポインタを hak_free_at() に流していた**
|
||||||
|
- BenchMeta の slots[] (外部アロケーション) も CoreAlloc (hakmem) に侵入 ← **箱侵犯!**
|
||||||
|
- LD_PRELOAD が `__libc_free()` も傍受するため、allocation 側の修正だけでは不十分
|
||||||
|
|
||||||
|
**症状**:
|
||||||
|
- Page-aligned pointer (0x...000) が ExternalGuard まで到達
|
||||||
|
- SuperSlab registry lookup 失敗 → crash or leak
|
||||||
|
- 0.84% memory leak (BenchMeta slots[] が解放されていない)
|
||||||
|
|
||||||
|
### 3.2 実装: Wrapper Domain Check
|
||||||
|
|
||||||
|
**戦略** (User 提案 + ChatGPT レビュー):
|
||||||
|
1. **Allocation 側**: BENCH_META_CALLOC/FREE で分離 (`bench_random_mixed.c`)
|
||||||
|
2. **Wrapper 側**: Domain check で hakmem vs external を識別 ← **本質的修正**
|
||||||
|
|
||||||
|
**実装詳細** (`core/box/hak_wrappers.inc.h:227-256`):
|
||||||
|
```c
|
||||||
|
// Phase 15: Domain check - 1-byte header 検査で hakmem vs external を分離
|
||||||
|
uintptr_t offset_in_page = (uintptr_t)ptr & 0xFFF;
|
||||||
|
if (offset_in_page > 0) {
|
||||||
|
// Not page-aligned → ptr-1 を安全に読める
|
||||||
|
uint8_t header = *((uint8_t*)ptr - 1);
|
||||||
|
if ((header & 0xF0) == 0xA0 || (header & 0xF0) == 0xB0) {
|
||||||
|
// HEADER_MAGIC found → hakmem Tiny allocation
|
||||||
|
hak_free_at(ptr, ...); // ✅ CoreAlloc へ
|
||||||
|
} else {
|
||||||
|
// No magic → external/BenchMeta
|
||||||
|
__libc_free(ptr); // ✅ __libc_free へ
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Page-aligned → full classification (safe fallback)
|
||||||
|
hak_free_at(ptr, ...);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3.3 Results
|
||||||
|
|
||||||
|
**Stability** (500K iterations):
|
||||||
|
- ✅ **No crashes** - crash-free stable operation
|
||||||
|
- ✅ **99.29% BenchMeta correctly freed** via `__libc_free()`
|
||||||
|
- ⚠️ **0.71% leak** - page-aligned fallthrough (acceptable tradeoff)
|
||||||
|
|
||||||
|
**Performance** (Random Mixed, 500K iterations):
|
||||||
|
| Size | Before Fix | After Fix | Change |
|
||||||
|
|------|-----------|-----------|--------|
|
||||||
|
| 128B | - | 16.64M ops/s | - |
|
||||||
|
| 256B | 15.9M ops/s | 16.17M ops/s | **+1.7%** |
|
||||||
|
| 512B | - | 14.94M ops/s | - |
|
||||||
|
| 1024B | - | 15.11M ops/s | - |
|
||||||
|
|
||||||
|
**vs System malloc** (256B): 16.17M vs 89.58M ops/s = **18.1%** (5.5倍遅い)
|
||||||
|
|
||||||
|
### 3.4 0.71% Leak 詳細
|
||||||
|
|
||||||
|
**10K iterations 分析**:
|
||||||
|
- Total: 10,000 slots[] allocations
|
||||||
|
- ExternalGuard calls: 71
|
||||||
|
- **Leak rate: 0.71%**
|
||||||
|
|
||||||
|
**原因**:
|
||||||
|
- 71個の slots[] がページ境界に配置 (random, system allocator 依存)
|
||||||
|
- Page-aligned では ptr-1 を読むと SEGV リスク → full classification へ
|
||||||
|
- ExternalGuard まで到達 → leak (crash 回避のための安全な tradeoff)
|
||||||
|
|
||||||
|
**99.29% の成功**:
|
||||||
|
- ヘッダチェック成功 → external と認識
|
||||||
|
- `__libc_free()` へ正しくルーティング ✅
|
||||||
|
|
||||||
|
### 3.5 Files Modified
|
||||||
|
|
||||||
|
1. **core/box/hak_wrappers.inc.h** (lines 227-256)
|
||||||
|
- Domain check logic with 1-byte header inspection
|
||||||
|
- Split routing: hakmem → hak_free_at(), external → __libc_free()
|
||||||
|
|
||||||
|
2. **core/box/external_guard_box.h** (lines 121-145)
|
||||||
|
- Conservative unknown pointer handling (leak instead of crash)
|
||||||
|
- Enhanced debug logging
|
||||||
|
|
||||||
|
3. **core/hakmem_super_registry.h** (line 28)
|
||||||
|
- SUPER_MAX_PROBE: 8 → 32 (hash collision tolerance)
|
||||||
|
|
||||||
|
4. **bench_random_mixed.c** (lines 15-25, 46, 99)
|
||||||
|
- BENCH_META_CALLOC/FREE macros (allocation side separation)
|
||||||
|
|
||||||
|
### 3.6 Lessons Learned
|
||||||
|
|
||||||
|
**LD_PRELOAD 傍受範囲**:
|
||||||
|
- `__libc_free()` も傍受される (内部からの呼び出しも wrapper 経由)
|
||||||
|
- → Wrapper 自体に defense-in-depth が必要
|
||||||
|
|
||||||
|
**Box 分離の Defense in Depth**:
|
||||||
|
1. Allocation 側: BENCH_META_CALLOC で分離
|
||||||
|
2. Wrapper 側: Domain check で二重防御
|
||||||
|
3. Last resort: ExternalGuard で conservative leak
|
||||||
|
|
||||||
|
**Page 境界 edge case**:
|
||||||
|
- ptr-1 を読むと SEGV リスク (0.71%)
|
||||||
|
- Tradeoff: leak (acceptable) vs crash (fatal)
|
||||||
|
- 安全性を優先 ✅
|
||||||
|
|
||||||
|
### 3.7 Documentation
|
||||||
|
|
||||||
|
- **PHASE15_WRAPPER_DOMAIN_CHECK_FIX.md** - 完全な実装解説 + User contribution 記録
|
||||||
|
- **PHASE15_REGISTRY_LOOKUP_INVESTIGATION.md** - SuperSlab registry 調査過程
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. 最近のバグ修正・仕様調整(もう触らなくてよい箱)
|
||||||
|
|
||||||
|
### 4.1 Tiny / Mid サイズ境界ギャップ修正(完了)
|
||||||
|
|
||||||
- 以前:
|
- 以前:
|
||||||
- `TINY_MAX_SIZE = 1024` / `MID_MIN_SIZE = 8192` で 1KB–8KB が誰の担当でもなく mmap 直行。
|
- `TINY_MAX_SIZE = 1024` / `MID_MIN_SIZE = 8192` で 1KB–8KB が誰の担当でもなく mmap 直行。
|
||||||
|
|||||||
BIN
perf.data.off
Normal file
BIN
perf.data.off
Normal file
Binary file not shown.
BIN
perf.data.off.old
Normal file
BIN
perf.data.off.old
Normal file
Binary file not shown.
BIN
perf.data.on
Normal file
BIN
perf.data.on
Normal file
Binary file not shown.
BIN
perf.data.on.old
Normal file
BIN
perf.data.on.old
Normal file
Binary file not shown.
Reference in New Issue
Block a user