Add Page Box layer for C7 class optimization

- Implement tiny_page_box.c/h: per-thread page cache between UC and Shared Pool
- Integrate Page Box into Unified Cache refill path
- Remove legacy SuperSlab implementation (merged into smallmid)
- Add HAKMEM_TINY_PAGE_BOX_CLASSES env var for selective class enabling
- Update bench_random_mixed.c with Page Box statistics

Current status: Implementation safe, no regressions.
Page Box ON/OFF shows minimal difference - pool strategy needs tuning.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm (CI)
2025-12-05 15:31:44 +09:00
parent 2b2b607957
commit 093f362231
16 changed files with 651 additions and 1347 deletions

View File

@ -40,6 +40,11 @@ extern _Atomic uint64_t g_unified_cache_hits_global;
extern _Atomic uint64_t g_unified_cache_misses_global;
extern _Atomic uint64_t g_unified_cache_refill_cycles_global;
// Per-class counters観測用 Box、ENV でのみ有効)
extern _Atomic uint64_t g_unified_cache_hits_by_class[TINY_NUM_CLASSES];
extern _Atomic uint64_t g_unified_cache_misses_by_class[TINY_NUM_CLASSES];
extern _Atomic uint64_t g_unified_cache_refill_cycles_by_class[TINY_NUM_CLASSES];
// Print statistics function
void unified_cache_print_measurements(void);
@ -102,10 +107,15 @@ static inline size_t unified_capacity(int class_idx) {
snprintf(env_name, sizeof(env_name), "HAKMEM_TINY_UNIFIED_C%d", class_idx);
const char* e = getenv(env_name);
// Default: Hot_2048 strategy (C2/C3=2048, others=64)
// Default: Hot_2048 strategy
// - C2/C3 (128B/256B): 2048 slots超ホット Tiny
// - C5/C6/C7 (>=129B): 128 slotsMixed 用に拡張)
// - その他: 64 slotsコールド
size_t default_cap = 64; // Cold classes
if (class_idx == 2 || class_idx == 3) {
default_cap = 2048; // Hot classes (128B, 256B)
default_cap = 2048; // Hot Tiny classes (128B, 256B)
} else if (class_idx >= 5 && class_idx <= 7) {
default_cap = 128; // Mixed workload classes (C5-C7: 129B-1024B)
}
g_cap[class_idx] = (e && *e) ? (size_t)atoi(e) : default_cap;
@ -265,9 +275,13 @@ static inline hak_base_ptr_t unified_cache_pop_or_refill(int class_idx) {
#if !HAKMEM_BUILD_RELEASE
g_unified_cache_hit[class_idx]++;
#endif
// Performance measurement: count cache hits
// Performance measurement: count cache hitsENV 有効時のみ)
if (__builtin_expect(unified_cache_measure_check(), 0)) {
atomic_fetch_add_explicit(&g_unified_cache_hits_global, 1, memory_order_relaxed);
atomic_fetch_add_explicit(&g_unified_cache_hits_global,
1, memory_order_relaxed);
// Per-class ヒットC5C7 の利用率も可視化)
atomic_fetch_add_explicit(&g_unified_cache_hits_by_class[class_idx],
1, memory_order_relaxed);
}
return HAK_BASE_FROM_RAW(base); // Hit! (2-3 cache misses total)
}