Add SuperSlab Prefault Box with 4MB MAP_POPULATE bug fix

New Feature: ss_prefault_box.h
- Box for controlling SuperSlab page prefaulting policy
- ENV: HAKMEM_SS_PREFAULT (0=OFF, 1=POPULATE, 2=TOUCH)
- Default: OFF (safe mode until further optimization)

Bug Fix: 4MB MAP_POPULATE regression
- Problem: Fallback path allocated 4MB (2x size for alignment) with MAP_POPULATE
  causing 52x slower mmap (0.585ms → 30.6ms) and 35% throughput regression
- Solution: Remove MAP_POPULATE from 4MB allocation, apply madvise(MADV_WILLNEED)
  only to the aligned 2MB region after trimming prefix/suffix

Changes:
- core/box/ss_prefault_box.h: New prefault policy box (header-only)
- core/box/ss_allocation_box.c: Integrate prefault box, call ss_prefault_region()
- core/superslab_cache.c: Fix fallback path - no MAP_POPULATE on 4MB,
  always munmap prefix/suffix, use MADV_WILLNEED for 2MB only
- docs/specs/ENV_VARS*.md: Document HAKMEM_SS_PREFAULT

Performance:
- bench_random_mixed: 4.32M ops/s (regression fixed, slight improvement)
- bench_tiny_hot: 157M ops/s with prefault=1 (no crash)

Box Theory:
- OS layer (ss_os_acquire): "how to mmap"
- Prefault Box: "when to page-in"
- Allocation Box: "when to call prefault"

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm (CI)
2025-12-04 20:11:24 +09:00
parent a32d0fafd4
commit cba6f785a1
5 changed files with 153 additions and 12 deletions

View File

@ -176,6 +176,14 @@ SuperSlab cache / prechargePhase 6.24+
- HAKMEM_TINY_SS_POPULATE_ONCE=1
- 次回 `mmap` で取得する SuperSlab を 1 回だけ `MAP_POPULATE` で fault-inA/B 用のワンショットプリタッチ)。
SuperSlab prefaultPF 削減のための前倒し)
- HAKMEM_SS_PREFAULT=0/1/2/3
- 0: OFF安全デフォルト。`g_ss_populate_once` によるワンショット `MAP_POPULATE` のみ)
- 1: POPULATE — 新規 SuperSlab の `mmap` で常に `MAP_POPULATE` を付与し、page fault を kernel 側で事前解消perf 計測用)。
- 2: TOUCH — `MAP_POPULATE` に加えて `ss_prefault_region()` で SuperSlab 全域を 1 回 4KB stride で touchPF をほぼゼロにしたい実験用)。
- 3: ASYNC — 予約値(現状は TOUCH と同等の扱いだが、将来的に BG thread prefault 用に拡張予定)。
- Box: `core/box/ss_prefault_box.h`(ポリシー決定)+ `core/box/ss_allocation_box.c`mmap 直後の実行)。
Harvest / Guardmmap前の収穫ゲート
- HAKMEM_TINY_SS_CAP=N
- Tiny 各クラスにおける SuperSlab 上限0=無制限)。