Phase 3d-B: TLS Cache Merge - Unified g_tls_sll[] structure (+12-18% expected)
Merge separate g_tls_sll_head[] and g_tls_sll_count[] arrays into unified TinyTLSSLL struct to improve L1D cache locality. Expected performance gain: +12-18% from reducing cache line splits (2 loads → 1 load per operation). Changes: - core/hakmem_tiny.h: Add TinyTLSSLL type (16B aligned, head+count+pad) - core/hakmem_tiny.c: Replace separate arrays with g_tls_sll[8] - core/box/tls_sll_box.h: Update Box API (13 sites) for unified access - Updated 32+ files: All g_tls_sll_head[i] → g_tls_sll[i].head - Updated 32+ files: All g_tls_sll_count[i] → g_tls_sll[i].count - core/hakmem_tiny_integrity.h: Unified canary guards - core/box/integrity_box.c: Simplified canary validation - Makefile: Added core/box/tiny_sizeclass_hist_box.o to link Build: ✅ PASS (10K ops sanity test) Warnings: Only pre-existing LTO type mismatches (unrelated) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -1165,25 +1165,15 @@ static __attribute__((cold, noinline, unused)) void* tiny_slow_alloc_fast(int cl
|
||||
// Hot-path cheap sampling counter to avoid rand() in allocation path
|
||||
// Phase 9.4: TLS single-linked freelist (mimalloc-inspired) for hottest classes (≤128B/≤256B)
|
||||
int g_tls_sll_enable = 1; // HAKMEM_TINY_TLS_SLL=0 to disable
|
||||
int g_tiny_hotpath_class5 = 0; // HAKMEM_TINY_HOTPATH_CLASS5=1 to enable class 5 hotpath
|
||||
// Phase 6-1.7: Export TLS variables for box refactor (Box 5/6 need access from hakmem.c)
|
||||
// CRITICAL FIX: Explicit initializers prevent SEGV from uninitialized TLS in worker threads
|
||||
// PRIORITY 3: TLS Canaries - Add canaries around TLS arrays to detect buffer overruns
|
||||
#define TLS_CANARY_MAGIC 0xDEADBEEFDEADBEEFULL
|
||||
__thread uint64_t g_tls_canary_before_sll_head = TLS_CANARY_MAGIC;
|
||||
#ifdef HAKMEM_TINY_PHASE6_BOX_REFACTOR
|
||||
__thread void* g_tls_sll_head[TINY_NUM_CLASSES] __attribute__((aligned(64))) = {0};
|
||||
#else
|
||||
static __thread void* g_tls_sll_head[TINY_NUM_CLASSES] __attribute__((aligned(64))) = {0};
|
||||
#endif
|
||||
__thread uint64_t g_tls_canary_after_sll_head = TLS_CANARY_MAGIC;
|
||||
|
||||
__thread uint64_t g_tls_canary_before_sll_count = TLS_CANARY_MAGIC;
|
||||
#ifdef HAKMEM_TINY_PHASE6_BOX_REFACTOR
|
||||
__thread uint32_t g_tls_sll_count[TINY_NUM_CLASSES] __attribute__((aligned(64))) = {0};
|
||||
#else
|
||||
static __thread uint32_t g_tls_sll_count[TINY_NUM_CLASSES] __attribute__((aligned(64))) = {0};
|
||||
#endif
|
||||
__thread uint64_t g_tls_canary_after_sll_count = TLS_CANARY_MAGIC;
|
||||
// Phase 3d-B: Unified TLS SLL (head+count in same cache line for +12-18% cache hit rate)
|
||||
__thread uint64_t g_tls_canary_before_sll = TLS_CANARY_MAGIC;
|
||||
__thread TinyTLSSLL g_tls_sll[TINY_NUM_CLASSES] __attribute__((aligned(64))) = {0};
|
||||
__thread uint64_t g_tls_canary_after_sll = TLS_CANARY_MAGIC;
|
||||
static int g_tiny_ultra = 0; // HAKMEM_TINY_ULTRA=1 for SLL-only ultra mode
|
||||
static int g_ultra_validate = 0; // HAKMEM_TINY_ULTRA_VALIDATE=1 to enable per-pop validation
|
||||
// Ultra debug counters
|
||||
|
||||
Reference in New Issue
Block a user