Files
hakmem/core/front/tiny_unified_cache.d
Moe Charm (CI) 5685c2f4c9 Implement Warm Pool Secondary Prefill Optimization (Phase B-2c Complete)
Problem: Warm pool had 0% hit rate (only 1 hit per 3976 misses) despite being
implemented, causing all cache misses to go through expensive superslab_refill
registry scans.

Root Cause Analysis:
- Warm pool was initialized once and pushed a single slab after each refill
- When that slab was exhausted, it was discarded (not pushed back)
- Next refill would push another single slab, which was immediately exhausted
- Pool would oscillate between 0 and 1 items, yielding 0% hit rate

Solution: Secondary Prefill on Cache Miss
When warm pool becomes empty, we now do multiple superslab_refills and prefill
the pool with 3 additional HOT superlslabs before attempting to carve. This
builds a working set of slabs that can sustain allocation pressure.

Implementation Details:
- Modified unified_cache_refill() cold path to detect empty pool
- Added prefill loop: when pool count == 0, load 3 extra superlslabs
- Store extra slabs in warm pool, keep 1 in TLS for immediate carving
- Track prefill events in g_warm_pool_stats[].prefilled counter

Results (1M Random Mixed 256B allocations):
- Before: C7 hits=1, misses=3976, hit_rate=0.0%
- After:  C7 hits=3929, misses=3143, hit_rate=55.6%
- Throughput: 4.055M ops/s (maintained vs 4.07M baseline)
- Stability: Consistent 55.6% hit rate at 5M allocations (4.102M ops/s)

Performance Impact:
- No regression: throughput remained stable at ~4.1M ops/s
- Registry scan avoided in 55.6% of cache misses (significant savings)
- Warm pool now functioning as intended with strong locality

Configuration:
- TINY_WARM_POOL_MAX_PER_CLASS increased from 4 to 16 to support prefill
- Prefill budget hardcoded to 3 (tunable via env var if needed later)
- All statistics always compiled, ENV-gated printing via HAKMEM_WARM_POOL_STATS=1

Next Steps:
- Monitor for further optimization opportunities (prefill budget tuning)
- Consider adaptive prefill budget based on class-specific hit rates
- Validate at larger allocation counts (10M+ pending registry size fix)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 23:31:54 +09:00

89 lines
3.7 KiB
Makefile

core/front/tiny_unified_cache.o: core/front/tiny_unified_cache.c \
core/front/tiny_unified_cache.h core/front/../hakmem_build_flags.h \
core/front/../hakmem_tiny_config.h core/front/../box/ptr_type_box.h \
core/front/../box/tiny_front_config_box.h \
core/front/../box/../hakmem_build_flags.h core/front/tiny_warm_pool.h \
core/front/../superslab/superslab_types.h \
core/hakmem_tiny_superslab_constants.h core/front/../tiny_tls.h \
core/front/../hakmem_tiny_superslab.h \
core/front/../superslab/superslab_types.h \
core/front/../superslab/superslab_inline.h \
core/front/../superslab/superslab_types.h \
core/front/../superslab/../tiny_box_geometry.h \
core/front/../superslab/../hakmem_tiny_superslab_constants.h \
core/front/../superslab/../hakmem_tiny_config.h \
core/front/../tiny_debug_ring.h core/front/../hakmem_build_flags.h \
core/front/../tiny_remote.h \
core/front/../hakmem_tiny_superslab_constants.h \
core/front/../tiny_box_geometry.h core/front/../box/tiny_next_ptr_box.h \
core/hakmem_tiny_config.h core/tiny_nextptr.h core/hakmem_build_flags.h \
core/tiny_region_id.h core/tiny_box_geometry.h core/ptr_track.h \
core/hakmem_super_registry.h core/hakmem_tiny_superslab.h \
core/box/ss_addr_map_box.h core/box/../hakmem_build_flags.h \
core/superslab/superslab_inline.h core/hakmem_tiny.h core/hakmem_trace.h \
core/hakmem_tiny_mini_mag.h core/box/hak_lane_classify.inc.h \
core/box/ptr_type_box.h core/tiny_debug_api.h core/box/tiny_layout_box.h \
core/box/../hakmem_tiny_config.h core/box/tiny_header_box.h \
core/box/tiny_layout_box.h core/box/../tiny_region_id.h \
core/front/../hakmem_tiny_superslab.h \
core/front/../superslab/superslab_inline.h \
core/front/../box/pagefault_telemetry_box.h \
core/front/../box/ss_tier_box.h \
core/front/../box/../superslab/superslab_types.h \
core/front/../box/ss_slab_meta_box.h \
core/front/../box/slab_freelist_atomic.h \
core/front/../hakmem_env_cache.h
core/front/tiny_unified_cache.h:
core/front/../hakmem_build_flags.h:
core/front/../hakmem_tiny_config.h:
core/front/../box/ptr_type_box.h:
core/front/../box/tiny_front_config_box.h:
core/front/../box/../hakmem_build_flags.h:
core/front/tiny_warm_pool.h:
core/front/../superslab/superslab_types.h:
core/hakmem_tiny_superslab_constants.h:
core/front/../tiny_tls.h:
core/front/../hakmem_tiny_superslab.h:
core/front/../superslab/superslab_types.h:
core/front/../superslab/superslab_inline.h:
core/front/../superslab/superslab_types.h:
core/front/../superslab/../tiny_box_geometry.h:
core/front/../superslab/../hakmem_tiny_superslab_constants.h:
core/front/../superslab/../hakmem_tiny_config.h:
core/front/../tiny_debug_ring.h:
core/front/../hakmem_build_flags.h:
core/front/../tiny_remote.h:
core/front/../hakmem_tiny_superslab_constants.h:
core/front/../tiny_box_geometry.h:
core/front/../box/tiny_next_ptr_box.h:
core/hakmem_tiny_config.h:
core/tiny_nextptr.h:
core/hakmem_build_flags.h:
core/tiny_region_id.h:
core/tiny_box_geometry.h:
core/ptr_track.h:
core/hakmem_super_registry.h:
core/hakmem_tiny_superslab.h:
core/box/ss_addr_map_box.h:
core/box/../hakmem_build_flags.h:
core/superslab/superslab_inline.h:
core/hakmem_tiny.h:
core/hakmem_trace.h:
core/hakmem_tiny_mini_mag.h:
core/box/hak_lane_classify.inc.h:
core/box/ptr_type_box.h:
core/tiny_debug_api.h:
core/box/tiny_layout_box.h:
core/box/../hakmem_tiny_config.h:
core/box/tiny_header_box.h:
core/box/tiny_layout_box.h:
core/box/../tiny_region_id.h:
core/front/../hakmem_tiny_superslab.h:
core/front/../superslab/superslab_inline.h:
core/front/../box/pagefault_telemetry_box.h:
core/front/../box/ss_tier_box.h:
core/front/../box/../superslab/superslab_types.h:
core/front/../box/ss_slab_meta_box.h:
core/front/../box/slab_freelist_atomic.h:
core/front/../hakmem_env_cache.h: