Phase 5-Step2: Mid Free Route Box (+28.9x free perf, 1.53x faster than system)

Fix critical 19x free() slowdown in Mid MT allocator (1KB-8KB range).

Root Cause:
- Mid MT registers chunks in MidGlobalRegistry
- Free path searches Pool's mid_desc registry (different registry!)
- Result: 100% lookup failure → 4x cascading lookups → libc fallback

Solution (Box Pattern):
- Created core/box/mid_free_route_box.h
- Try Mid MT registry BEFORE classify_ptr() in free()
- Direct route to mid_mt_free() if found
- Fall through to existing path if not found

Performance Results (bench_mid_mt_gap, 1KB-8KB allocs):
- Before: 1.49 M ops/s (19x slower than system malloc)
- After:  41.0 M ops/s (+28.9x improvement)
- vs System malloc: 1.53x faster (41.0 vs 26.8 M ops/s)

Files:
- core/box/mid_free_route_box.h (NEW) - Mid Free Route Box
- core/box/hak_wrappers.inc.h - Add mid_free_route_try() call
- core/hakmem_mid_mt.h - Fix mid_get_min_size() (1024 not 2048)
- bench_mid_mt_gap.c (NEW) - Targeted 1KB-8KB benchmark
- Makefile - Add bench_mid_mt_gap targets

Box Pattern:  Single responsibility, clear contract, testable, minimal change

🤖 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-11-29 14:18:20 +09:00
parent 3cc7b675df
commit 3daf75e57f
5 changed files with 268 additions and 4 deletions

View File

@ -616,6 +616,19 @@ bench_random_mixed_hakmem: bench_random_mixed_hakmem.o $(TINY_BENCH_OBJS)
bench_random_mixed_system: bench_random_mixed_system.o
$(CC) -o $@ $^ $(LDFLAGS)
# Mid MT gap benchmark (1KB-8KB allocations) - Phase 5-Step2 verification
bench_mid_mt_gap_hakmem.o: bench_mid_mt_gap.c hakmem.h
$(CC) $(CFLAGS) -DUSE_HAKMEM -c -o $@ $<
bench_mid_mt_gap_system.o: bench_mid_mt_gap.c
$(CC) $(CFLAGS) -c -o $@ $<
bench_mid_mt_gap_hakmem: bench_mid_mt_gap_hakmem.o $(TINY_BENCH_OBJS)
$(CC) -o $@ $^ $(LDFLAGS)
bench_mid_mt_gap_system: bench_mid_mt_gap_system.o
$(CC) -o $@ $^ $(LDFLAGS)
# Fixed-size microbench (direct link variants)
bench_fixed_size_hakmem.o: benchmarks/src/fixed/bench_fixed_size.c hakmem.h
$(CC) $(CFLAGS) -DUSE_HAKMEM -c -o $@ $<