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:
@ -40,6 +40,20 @@ static void hak_init_impl(void) {
|
||||
// dlsym() initializes function pointers to real libc (bypasses LD_PRELOAD)
|
||||
hkm_syscall_init();
|
||||
|
||||
// CRITICAL FIX (BUG #10): Pre-detect jemalloc ONCE during init, not on hot path!
|
||||
// This prevents infinite recursion: malloc → hak_jemalloc_loaded → dlopen → malloc → ...
|
||||
// We protect dlopen's internal malloc calls with g_hakmem_lock_depth
|
||||
extern int g_jemalloc_loaded; // Declared in hakmem.c
|
||||
if (g_jemalloc_loaded < 0) {
|
||||
void* h = dlopen("libjemalloc.so.2", RTLD_NOLOAD | RTLD_NOW);
|
||||
if (!h) h = dlopen("libjemalloc.so.1", RTLD_NOLOAD | RTLD_NOW);
|
||||
g_jemalloc_loaded = (h != NULL) ? 1 : 0;
|
||||
if (h) dlclose(h);
|
||||
if (g_jemalloc_loaded) {
|
||||
HAKMEM_LOG("Detected jemalloc: will avoid interposing\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Optional: one-shot SIGSEGV backtrace for early crash diagnosis
|
||||
do {
|
||||
const char* dbg = getenv("HAKMEM_DEBUG_SEGV");
|
||||
|
||||
Reference in New Issue
Block a user