Phase 24-26: Hot path atomic telemetry prune (+2.00% cumulative)
Summary: - Phase 24 (alloc stats): +0.93% GO - Phase 25 (free stats): +1.07% GO - Phase 26 (diagnostics): -0.33% NEUTRAL (code cleanliness) - Total: 11 atomics compiled-out, +2.00% improvement Phase 24: OBSERVE tax prune (tiny_class_stats_box.h) - Added HAKMEM_TINY_CLASS_STATS_COMPILED (default: 0) - Wrapped 5 stats functions: uc_miss, warm_hit, shared_lock, tls_carve_* - Result: +0.93% (baseline 56.675M vs compiled-in 56.151M ops/s) Phase 25: Tiny free stats prune (tiny_superslab_free.inc.h) - Added HAKMEM_TINY_FREE_STATS_COMPILED (default: 0) - Wrapped g_free_ss_enter atomic in free hot path - Result: +1.07% (baseline 57.017M vs compiled-in 56.415M ops/s) Phase 26: Hot path diagnostic atomics prune - Added 5 compile gates for low-frequency error counters: - HAKMEM_TINY_C7_FREE_COUNT_COMPILED - HAKMEM_TINY_HDR_MISMATCH_LOG_COMPILED - HAKMEM_TINY_HDR_META_MISMATCH_COMPILED - HAKMEM_TINY_METRIC_BAD_CLASS_COMPILED - HAKMEM_TINY_HDR_META_FAST_COMPILED - Result: -0.33% NEUTRAL (within noise, kept for cleanliness) Alignment with mimalloc principles: - "No atomics on hot path" - telemetry moved to compile-time opt-in - Fixed per-op tax elimination - Production builds: maximum performance (atomics compiled-out) - Research builds: full diagnostics (COMPILED=1) Generated with Claude Code https://claude.com/claude-code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
// - hak_tiny_free_superslab(): Main SuperSlab free entry point
|
||||
|
||||
#include <stdatomic.h>
|
||||
#include "hakmem_build_flags.h" // Phase 25: Compile-time feature switches
|
||||
#include "box/ptr_type_box.h" // Phase 10
|
||||
#include "box/free_remote_box.h"
|
||||
#include "box/free_local_box.h"
|
||||
@ -15,8 +16,13 @@
|
||||
// Phase 6.22-B: SuperSlab fast free path
|
||||
static inline void hak_tiny_free_superslab(void* ptr, SuperSlab* ss) {
|
||||
// Route trace: count SuperSlab free entries (diagnostics only)
|
||||
// Phase 25: Compile-out free stats atomic (default OFF)
|
||||
#if HAKMEM_TINY_FREE_STATS_COMPILED
|
||||
extern _Atomic uint64_t g_free_ss_enter;
|
||||
atomic_fetch_add_explicit(&g_free_ss_enter, 1, memory_order_relaxed);
|
||||
#else
|
||||
(void)0; // No-op when compiled out
|
||||
#endif
|
||||
ROUTE_MARK(16); // free_enter
|
||||
HAK_DBG_INC(g_superslab_free_count); // Phase 7.6: Track SuperSlab frees
|
||||
|
||||
@ -40,7 +46,9 @@ static inline void hak_tiny_free_superslab(void* ptr, SuperSlab* ss) {
|
||||
uint8_t cls = meta->class_idx;
|
||||
|
||||
// Debug: Log first C7 alloc/free for path verification
|
||||
// Phase 26A: Compile-out c7_free_count atomic (default OFF)
|
||||
if (cls == 7) {
|
||||
#if HAKMEM_C7_FREE_COUNT_COMPILED
|
||||
static _Atomic int c7_free_count = 0;
|
||||
int count = atomic_fetch_add_explicit(&c7_free_count, 1, memory_order_relaxed);
|
||||
if (count == 0) {
|
||||
@ -48,6 +56,10 @@ static inline void hak_tiny_free_superslab(void* ptr, SuperSlab* ss) {
|
||||
fprintf(stderr, "[C7_FIRST_FREE] ptr=%p base=%p slab_idx=%d\n", ptr, base, slab_idx);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
// No-op when compiled out (Phase 26A)
|
||||
(void)0;
|
||||
#endif
|
||||
}
|
||||
if (__builtin_expect(tiny_remote_watch_is(ptr), 0)) {
|
||||
tiny_remote_watch_note("free_enter", ss, slab_idx, ptr, 0xA240u, tiny_self_u32(), 0);
|
||||
@ -137,8 +149,13 @@ static inline void hak_tiny_free_superslab(void* ptr, SuperSlab* ss) {
|
||||
uint8_t hdr = *(uint8_t*)base;
|
||||
uint8_t expect = (uint8_t)(HEADER_MAGIC | (cls & HEADER_CLASS_MASK));
|
||||
if (__builtin_expect(hdr != expect, 0)) {
|
||||
// Phase 26B: Compile-out g_hdr_mismatch_log atomic (default OFF)
|
||||
#if HAKMEM_HDR_MISMATCH_LOG_COMPILED
|
||||
static _Atomic uint32_t g_hdr_mismatch_log = 0;
|
||||
uint32_t n = atomic_fetch_add_explicit(&g_hdr_mismatch_log, 1, memory_order_relaxed);
|
||||
#else
|
||||
uint32_t n = 0; // No-op when compiled out
|
||||
#endif
|
||||
if (n < 8) {
|
||||
fprintf(stderr,
|
||||
"[TLS_HDR_MISMATCH] cls=%u slab_idx=%d hdr=0x%02x expect=0x%02x ptr=%p\n",
|
||||
@ -172,8 +189,13 @@ static inline void hak_tiny_free_superslab(void* ptr, SuperSlab* ss) {
|
||||
uint8_t hdr_cls = tiny_region_id_read_header(ptr);
|
||||
uint8_t meta_cls = meta->class_idx;
|
||||
if (__builtin_expect(hdr_cls != meta_cls, 0)) {
|
||||
// Phase 26C: Compile-out g_hdr_meta_mismatch atomic (default OFF)
|
||||
#if HAKMEM_HDR_META_MISMATCH_COMPILED
|
||||
static _Atomic uint32_t g_hdr_meta_mismatch = 0;
|
||||
uint32_t n = atomic_fetch_add_explicit(&g_hdr_meta_mismatch, 1, memory_order_relaxed);
|
||||
#else
|
||||
uint32_t n = 0; // No-op when compiled out
|
||||
#endif
|
||||
if (n < 16) {
|
||||
fprintf(stderr, "[SLAB_HDR_META_MISMATCH] slab_push cls_meta=%u hdr_cls=%u ptr=%p slab_idx=%d ss=%p freelist=%p used=%u\n",
|
||||
(unsigned)meta_cls, (unsigned)hdr_cls, ptr, slab_idx, (void*)ss, meta->freelist, (unsigned)meta->used);
|
||||
|
||||
Reference in New Issue
Block a user