feat: Phase 7 + Phase 2 - Massive performance & stability improvements
Performance Achievements: - Tiny allocations: +180-280% (21M → 59-70M ops/s random mixed) - Single-thread: +24% (2.71M → 3.36M ops/s Larson) - 4T stability: 0% → 95% (19/20 success rate) - Overall: 91.3% of System malloc average (target was 40-55%) ✓ Phase 7 (Tasks 1-3): Core Optimizations - Task 1: Header validation removal (Region-ID direct lookup) - Task 2: Aggressive inline (TLS cache access optimization) - Task 3: Pre-warm TLS cache (eliminate cold-start penalty) Result: +180-280% improvement, 85-146% of System malloc Critical Bug Fixes: - Fix 64B allocation crash (size-to-class +1 for header) - Fix 4T wrapper recursion bugs (BUG #7, #8, #10, #11) - Remove malloc fallback (30% → 50% stability) Phase 2a: SuperSlab Dynamic Expansion (CRITICAL) - Implement mimalloc-style chunk linking - Unlimited slab expansion (no more OOM at 32 slabs) - Fix chunk initialization bug (bitmap=0x00000001 after expansion) Files: core/hakmem_tiny_superslab.c/h, core/superslab/superslab_types.h Result: 50% → 95% stability (19/20 4T success) Phase 2b: TLS Cache Adaptive Sizing - Dynamic capacity: 16-2048 slots based on usage - High-water mark tracking + exponential growth/shrink - Expected: +3-10% performance, -30-50% memory Files: core/tiny_adaptive_sizing.c/h (new) Phase 2c: BigCache Dynamic Hash Table - Migrate from fixed 256×8 array to dynamic hash table - Auto-resize: 256 → 512 → 1024 → 65,536 buckets - Improved hash function (FNV-1a) + collision chaining Files: core/hakmem_bigcache.c/h Expected: +10-20% cache hit rate Design Flaws Analysis: - Identified 6 components with fixed-capacity bottlenecks - SuperSlab (CRITICAL), TLS Cache (HIGH), BigCache/L2.5 (MEDIUM) - Report: DESIGN_FLAWS_ANALYSIS.md (11 chapters) Documentation: - 13 comprehensive reports (PHASE*.md, DESIGN_FLAWS*.md) - Implementation guides, test results, production readiness - Bug fix reports, root cause analysis Build System: - Makefile: phase7 targets, PREWARM_TLS flag - Auto dependency generation (-MMD -MP) for .inc files Known Issues: - 4T stability: 19/20 (95%) - investigating 1 failure for 100% - L2.5 Pool dynamic sharding: design only (needs 2-3 days integration) 🤖 Generated with Claude Code (https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -244,11 +244,15 @@ void hkm_ace_set_drain_threshold(int class_idx, uint32_t threshold);
|
||||
static inline int hak_tiny_size_to_class(size_t size) {
|
||||
if (size == 0 || size > TINY_MAX_SIZE) return -1;
|
||||
#if HAKMEM_TINY_HEADER_CLASSIDX
|
||||
// Phase 7: 1024B requires header (1B) + user data (1024B) = 1025B
|
||||
// Class 7 blocks are only 1024B, so 1024B requests must use Mid allocator
|
||||
if (size >= 1024) return -1;
|
||||
#endif
|
||||
// Phase 7 CRITICAL FIX (2025-11-08): Add 1-byte header overhead BEFORE class lookup
|
||||
// Bug: 64B request was mapped to class 3 (64B blocks), leaving only 63B usable → BUS ERROR
|
||||
// Fix: 64B request → alloc_size=65 → class 4 (128B blocks) → 127B usable ✓
|
||||
size_t alloc_size = size + 1; // Add header overhead
|
||||
if (alloc_size > TINY_MAX_SIZE) return -1; // 1024B request becomes 1025B, reject to Mid
|
||||
return g_size_to_class_lut_1k[alloc_size]; // Look up with header-adjusted size
|
||||
#else
|
||||
return g_size_to_class_lut_1k[size]; // 1..1024: single load
|
||||
#endif
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user