Two critical bugs fixed:
1. Policy snapshot infinite loop (smallobject_policy_v7.c):
- Condition `g_policy_v7_version == 0` caused reinit on every call
- Fixed via CAS to set global version to 1 after first init
2. Malloc recursion (smallobject_segment_mid_v3.c):
- Internal malloc() routed back through hakmem → MID v3.5 → segment
creation → malloc → infinite recursion / stack overflow
- Fixed by using mmap() directly for internal allocations:
- Segment struct, pages array, page metadata block
Performance results (bench_random_mixed 257-512B):
- Baseline (LEGACY): 34.0M ops/s
- MID_V35 ON (C6): 35.8M ops/s
- Improvement: +5.1% ✓
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Change: Learner now defaults to ON (when v7 is enabled)
- Old behavior: Learner only enabled if explicitly requested
- New behavior: Learner always ON (can disable with ENV=0)
- Learner is optional dependency of v7 (not intrusive)
Configuration:
- HAKMEM_SMALL_HEAP_V7_ENABLED=1: enables v7 + Learner
- HAKMEM_SMALL_LEARNER_V7_ENABLED=0: disable Learner only (keeps v7)
Benefits:
- Automatic workload detection without user configuration
- C5 allocation ratio monitored by default
- Route optimization happens transparently
Performance: v7+Learner C5/C6 workload = 39M ops/s (maintained)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Refactoring: Separate Learner API and types from Policy Box
- New: core/box/smallobject_learner_v7_box.h
- SmallLearnerStatsV7 type definition
- Learner recording API (record_refill, record_retire)
- Learner evaluation and stats snapshot
- Learner configuration constants
- Updated: core/box/smallobject_policy_v7_box.h
- Removed Learner API (moved to Learner Box)
- Removed SmallLearnerStatsV7 type (moved to Learner Box)
- Added include of smallobject_learner_v7_box.h
- Kept small_policy_v7_update_from_learner() (L3 integration)
- Updated: core/smallobject_policy_v7.c
- Added include of smallobject_learner_v7_box.h
Benefits:
- Clearer module boundaries (Policy vs Learner)
- Easier testing and debugging (stats isolation)
- Reduced coupling between components
Performance: No regression (v7+Learner: 41M ops/s on C5/C6)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add SmallLearnerStatsV7 type + API to policy box
- Hook ColdIface refill/retire to collect stats (capacity-based)
- Implement C5 route switching: if C5 ratio < 30%, switch to MID_V3
- Version-based TLS cache invalidation for policy updates
- Evaluation interval: every 100 refills
Tested with c6heavy scenario: C5 ratio=12% triggers V7 → MID_V3 switch
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>