P-Tier + Tiny Route Policy: Aggressive Superslab Management + Safe Routing
## Phase 1: Utilization-Aware Superslab Tiering (案B実装済) - Add ss_tier_box.h: Classify SuperSlabs into HOT/DRAINING/FREE based on utilization - HOT (>25%): Accept new allocations - DRAINING (≤25%): Drain only, no new allocs - FREE (0%): Ready for eager munmap - Enhanced shared_pool_release_slab(): - Check tier transition after each slab release - If tier→FREE: Force remaining slots to EMPTY and call superslab_free() immediately - Bypasses LRU cache to prevent registry bloat from accumulating DRAINING SuperSlabs - Test results (bench_random_mixed_hakmem): - 1M iterations: ✅ ~1.03M ops/s (previously passed) - 10M iterations: ✅ ~1.15M ops/s (previously: registry full error) - 50M iterations: ✅ ~1.08M ops/s (stress test) ## Phase 2: Tiny Front Routing Policy (新規Box) - Add tiny_route_box.h/c: Single 8-byte table for class→routing decisions - ROUTE_TINY_ONLY: Tiny front exclusive (no fallback) - ROUTE_TINY_FIRST: Try Tiny, fallback to Pool if fails - ROUTE_POOL_ONLY: Skip Tiny entirely - Profiles via HAKMEM_TINY_PROFILE ENV: - "hot": C0-C3=TINY_ONLY, C4-C6=TINY_FIRST, C7=POOL_ONLY - "conservative" (default): All TINY_FIRST - "off": All POOL_ONLY (disable Tiny) - "full": All TINY_ONLY (microbench mode) - A/B test results (ws=256, 100k ops random_mixed): - Default (conservative): ~2.90M ops/s - hot: ~2.65M ops/s (more conservative) - off: ~2.86M ops/s - full: ~2.98M ops/s (slightly best) ## Design Rationale ### Registry Pressure Fix (案B) - Problem: DRAINING tier SS occupied registry indefinitely - Solution: When total_active_blocks→0, immediately free to clear registry slot - Result: No more "registry full" errors under stress ### Routing Policy Box (新) - Problem: Tiny front optimization scattered across ENV/branches - Solution: Centralize routing in single table, select profiles via ENV - Benefit: Safe A/B testing without touching hot path code - Future: Integrate with RSS budget/learning layers for dynamic profile switching ## Next Steps (性能最適化) - Profile Tiny front internals (TLS SLL, FastCache, Superslab backend latency) - Identify bottleneck between current ~2.9M ops/s and mimalloc ~100M ops/s - Consider: - Reduce shared pool lock contention - Optimize unified cache hit rate - Streamline Superslab carving logic 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -280,6 +280,41 @@ New (debug isolation)
|
||||
- 小クラス用の小型TLSマガジン(128要素, classes 0..3)を有効化。既定0(A/B用)。
|
||||
- alloc: HotMag→SLL→Magazine の順でヒットを狙う。free: SLL優先、溢れ時にHotMag→Magazine。
|
||||
|
||||
### Superslab Tiering / Registry 制御
|
||||
|
||||
- HAKMEM_SS_TIER_DOWN_THRESHOLD
|
||||
- 型: float (0.0–1.0)
|
||||
- 既定値: `0.25`
|
||||
- 役割: SuperSlab 利用率(`total_active_blocks / capacity`)がこの値以下になったとき、Tier を `HOT→DRAINING` に落とすための下限。
|
||||
- 影響: DRAINING Tier の SuperSlab は新規 alloc の対象から外れ、drain/解放の対象になる(Box: `ss_tier_box.h`)。
|
||||
|
||||
- HAKMEM_SS_TIER_UP_THRESHOLD
|
||||
- 型: float (0.0–1.0)
|
||||
- 既定値: `0.50`
|
||||
- 役割: DRAINING Tier の SuperSlab の利用率がこの値以上になったときに `DRAINING→HOT` に戻すための上限(ヒステリシス)。
|
||||
- 影響: 利用率が一時的にブレても HOT/DRAINING を行き来しにくくし、Tier の振動を防ぐ。
|
||||
|
||||
### Tiny Front Routing(Tiny vs Pool の切替)
|
||||
|
||||
- HAKMEM_TINY_PROFILE
|
||||
- 型: string
|
||||
- 既定値: `"conservative"`
|
||||
- 役割: Tiny Front(TLS SLL / FastCache)と Pool/backend のルーティング方針をクラス別に切り替えるプロファイル。
|
||||
- プロファイル:
|
||||
- `"conservative"`(既定):
|
||||
- C0〜C7 すべて `TINY_FIRST`(まず Tiny front、失敗時は Pool/backend にフォールバック)
|
||||
- `"hot"`:
|
||||
- C0〜C3: `TINY_ONLY`(小クラスを Tiny 専用で積極活用)
|
||||
- C4〜C6: `TINY_FIRST`
|
||||
- C7: `POOL_ONLY`(1KB headerless は Pool に任せる)
|
||||
- `"off"`:
|
||||
- C0〜C7 すべて `POOL_ONLY`(Tiny front を完全に無効化)
|
||||
- `"full"`:
|
||||
- C0〜C7 すべて `TINY_ONLY`(microbench 用、Gate としては常に Tiny 経由)
|
||||
- 実装:
|
||||
- Box: `core/box/tiny_route_box.h` / `tiny_route_box.c`
|
||||
- Gate: `tiny_alloc_gate_fast()` がクラスごとに `TinyRoutePolicy` を参照して Tiny vs Pool を振り分ける。
|
||||
|
||||
## USDT/tracepoints(perfのユーザ空間静的トレース)
|
||||
- ビルド時に `CFLAGS+=-DHAKMEM_USDT=1` を付与すると、主要分岐にUSDT(DTrace互換)プローブが埋め込まれます。
|
||||
- 依存: `<sys/sdt.h>`(Debian/Ubuntu: `sudo apt-get install systemtap-sdt-dev`)。
|
||||
|
||||
@ -297,7 +297,50 @@ From `/mnt/workdisk/public_share/hakmem/core/hakmem_tiny_stats.h`:
|
||||
|
||||
---
|
||||
|
||||
### 9. Memory Efficiency & RSS Control
|
||||
### 9. Tiny Front Routing
|
||||
|
||||
#### HAKMEM_TINY_PROFILE
|
||||
- **Default**: `"conservative"`
|
||||
- **Type**: string
|
||||
- **Purpose**: Control Tiny Front (TLS SLL / FastCache) vs Pool/backend routing per Tiny class via a simple profile.
|
||||
- **Profiles**:
|
||||
- `"conservative"`:
|
||||
- All classes (C0–C7) use `TINY_FIRST`: try Tiny Front first, then fallback to Pool/backend on miss.
|
||||
- `"hot"`:
|
||||
- C0–C3: `TINY_ONLY` (small classes use Tiny exclusively via front gate)
|
||||
- C4–C6: `TINY_FIRST`
|
||||
- C7: `POOL_ONLY` (1KB headerless class uses Pool/backend)
|
||||
- `"off"`:
|
||||
- All classes `POOL_ONLY` (Tiny Front is fully disabled, Pool-only allocator behaviour).
|
||||
- `"full"`:
|
||||
- All classes `TINY_ONLY` (microbench-style, front gate always routes via Tiny).
|
||||
- **Implementation**:
|
||||
- Box: `core/box/tiny_route_box.h` / `tiny_route_box.c` (per-class `g_tiny_route[8]` table).
|
||||
- Gate: `tiny_alloc_gate_fast()` reads `TinyRoutePolicy` and decides Tiny vs Pool on each allocation.
|
||||
|
||||
---
|
||||
|
||||
### 10. Superslab Tiering & Registry Control
|
||||
|
||||
#### HAKMEM_SS_TIER_DOWN_THRESHOLD
|
||||
- **Default**: `0.25`
|
||||
- **Range**: 0.0–1.0
|
||||
- **Purpose**: SuperSlab 利用率がこの値以下になったときに、Tier を `HOT → DRAINING` に遷移させる下限。
|
||||
- **Impact**:
|
||||
- DRAINING Tier の SuperSlab は新規割り当ての対象外となり、drain/解放候補として扱われる。
|
||||
- 利用率が低い SuperSlab への新規割り当てを避け、活発な SuperSlab に負荷を集中させる。
|
||||
|
||||
#### HAKMEM_SS_TIER_UP_THRESHOLD
|
||||
- **Default**: `0.50`
|
||||
- **Range**: 0.0–1.0
|
||||
- **Purpose**: DRAINING Tier の SuperSlab 利用率がこの値以上になったときに `DRAINING → HOT` に戻す上限(ヒステリシス)。
|
||||
- **Impact**:
|
||||
- Down/Up 閾値にギャップを持たせることで、Tier が HOT と DRAINING の間で頻繁に振動するのを防ぐ。
|
||||
- Sustained な利用増加が観測された SuperSlab のみ HOT に復帰させる。
|
||||
|
||||
---
|
||||
|
||||
### 11. Memory Efficiency & RSS Control
|
||||
|
||||
#### HAKMEM_TINY_RSS_BUDGET_KB
|
||||
- **Default**: Unlimited
|
||||
@ -333,7 +376,7 @@ From `/mnt/workdisk/public_share/hakmem/core/hakmem_tiny_stats.h`:
|
||||
|
||||
---
|
||||
|
||||
### 10. Policy & Learning Parameters
|
||||
### 11. Policy & Learning Parameters
|
||||
|
||||
#### HAKMEM_LEARN
|
||||
- **Default**: 0 (OFF, unless HAKMEM_MODE=learning/research)
|
||||
|
||||
Reference in New Issue
Block a user