Phase POOL-MID-DN-BATCH: Complete deferred inuse_dec implementation

Summary:
- Goal: Eliminate mid_desc_lookup from pool_free_v1 hot path
- Result: +2.8% improvement (7.94M → 8.16M ops/s median)
- Strategy: TLS map batching + thread exit cleanup

Implementation:
1. ENV gate (HAKMEM_POOL_MID_INUSE_DEFERRED=1 to enable)
2. TLS page map (32 entries, batches page→dec_count)
3. Deferred API (hot: O(1) map update, cold: batched lookup)
4. Stats counters (hits, drains, empty transitions)
5. Thread cleanup (pthread_key ensures drain on thread exit)

Performance:
- Baseline (deferred OFF): 7.94M ops/s (median of 3 runs)
- Deferred ON: 8.16M ops/s (median of 3 runs)
- Improvement: +2.8% (within target +2-4% range)

Statistics (deferred ON):
- Deferred hits: 82K
- Drain calls: 2.5K
- Avg pages/drain: 32.6 (32x lookup reduction)
- Empty transitions: 3.5K

Key Achievement:
- Hot path: ZERO lookups (only TLS map update)
- Cold path: Batched lookups at map full / thread exit
- Correctness: Same pending_dn logic as original, just batched

Files:
- core/box/pool_mid_inuse_deferred_env_box.h (NEW)
- core/box/pool_mid_inuse_tls_pagemap_box.h (NEW)
- core/box/pool_mid_inuse_deferred_box.h (NEW)
- core/box/pool_mid_inuse_deferred_stats_box.h (NEW)
- core/box/pool_free_v1_box.h (MODIFIED)
- CURRENT_TASK.md (UPDATED)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Moe Charm (CI)
2025-12-12 23:00:59 +09:00
parent 16b415f5a2
commit b400762f29

View File

@ -1,6 +1,36 @@
# 本線タスク(現在) # 本線タスク(現在)
## 現在地: Phase MID-V35-HOTPATH-OPT-1 完了 → 次フェーズ選定待ち ## 現在地: Phase POOL-MID-DN-BATCH 完了 → 次フェーズ選定待ち
---
### Status: Phase POOL-MID-DN-BATCH 完了 ✅ (2025-12-12)
**Summary**:
- **Goal**: Eliminate `mid_desc_lookup` from pool_free_v1 hot path by deferring inuse_dec
- **Mixed (bench_mid_large_mt_hakmem)**: **+2.8%** improvement ✅ (7.94M → 8.16M ops/s, median)
- **Strategy**: TLS map batching (~32 pages/drain) + thread exit cleanup
- **Decision**: Default OFF (ENV gate),可用于生产环境测试
**Key Achievements**:
- Hot path: Zero lookups (O(1) TLS map update only)
- Cold path: Batched lookup + atomic subtract (32x reduction in lookup frequency)
- Thread-safe: pthread_key cleanup ensures pending ops drained on thread exit
- Stats: 82K deferred hits, 2.5K drain calls, 3.5K empty transitions
**Deliverables**:
- `core/box/pool_mid_inuse_deferred_env_box.h` (ENV gate: HAKMEM_POOL_MID_INUSE_DEFERRED)
- `core/box/pool_mid_inuse_tls_pagemap_box.h` (32-entry TLS map)
- `core/box/pool_mid_inuse_deferred_box.h` (deferred API + drain logic)
- `core/box/pool_mid_inuse_deferred_stats_box.h` (counters + dump)
- `core/box/pool_free_v1_box.h` (integration: fast + slow paths)
- Benchmark: +2.8% median, within target range (+2-4%)
**ENV Control**:
```bash
HAKMEM_POOL_MID_INUSE_DEFERRED=0 # Default (immediate dec)
HAKMEM_POOL_MID_INUSE_DEFERRED=1 # Enable deferred batching
```
--- ---