From cfa5e4e91cc7b1edfbb1e9d4854d0b0f7cb51537 Mon Sep 17 00:00:00 2001 From: "Moe Charm (CI)" Date: Fri, 28 Nov 2025 01:06:15 +0900 Subject: [PATCH] ENV Cleanup Step 7: Gate debug ENV vars in core/box/free_local_box.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes: - Gated HAKMEM_TINY_SLL_DIAG (2 call sites) behind #if !HAKMEM_BUILD_RELEASE - Gated HAKMEM_TINY_FREELIST_MASK behind #if !HAKMEM_BUILD_RELEASE - Gated HAKMEM_SS_FREE_DEBUG behind #if !HAKMEM_BUILD_RELEASE - Entire diagnostic blocks wrapped (not just getenv) to avoid compilation errors - ENV variables gated: HAKMEM_TINY_SLL_DIAG, HAKMEM_TINY_FREELIST_MASK, HAKMEM_SS_FREE_DEBUG Performance: 30.4M ops/s Larson (baseline 30.4M, perfect match) Build: Clean, pre-existing warnings only FIX: Previous version had scoping issue with static variables inside do{}while blocks 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- core/box/free_local_box.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/box/free_local_box.c b/core/box/free_local_box.c index 23f65f2b..cb915c2c 100644 --- a/core/box/free_local_box.c +++ b/core/box/free_local_box.c @@ -30,6 +30,7 @@ void tiny_free_local_box(SuperSlab* ss, int slab_idx, TinySlabMeta* meta, void* void* base = (void*)((uint8_t*)ptr - 1); // Targeted header integrity check (env: HAKMEM_TINY_SLL_DIAG, C7 focus) +#if !HAKMEM_BUILD_RELEASE do { static int g_free_diag_en = -1; static _Atomic uint32_t g_free_diag_shot = 0; @@ -56,6 +57,7 @@ void tiny_free_local_box(SuperSlab* ss, int slab_idx, TinySlabMeta* meta, void* } } } while (0); +#endif if (__builtin_expect(tiny_refill_failfast_level() >= 2, 0)) { int actual_idx = slab_index_for(ss, base); @@ -77,6 +79,7 @@ void tiny_free_local_box(SuperSlab* ss, int slab_idx, TinySlabMeta* meta, void* void* prev = meta->freelist; // Detect suspicious prev before writing next (env-gated) +#if !HAKMEM_BUILD_RELEASE do { static int g_prev_diag_en = -1; static _Atomic uint32_t g_prev_diag_shot = 0; @@ -100,6 +103,7 @@ void tiny_free_local_box(SuperSlab* ss, int slab_idx, TinySlabMeta* meta, void* } } } while (0); +#endif // FREELIST CORRUPTION DEBUG: Validate pointer before writing if (__builtin_expect(tiny_refill_failfast_level() >= 2, 0)) { @@ -157,6 +161,7 @@ void tiny_free_local_box(SuperSlab* ss, int slab_idx, TinySlabMeta* meta, void* atomic_thread_fence(memory_order_release); // Optional freelist mask update on first push +#if !HAKMEM_BUILD_RELEASE do { static int g_mask_en = -1; if (__builtin_expect(g_mask_en == -1, 0)) { @@ -168,6 +173,7 @@ void tiny_free_local_box(SuperSlab* ss, int slab_idx, TinySlabMeta* meta, void* atomic_fetch_or_explicit(&ss->freelist_mask, bit, memory_order_release); } } while (0); +#endif // Track local free (debug helpers may be no-op) tiny_remote_track_on_local_free(ss, slab_idx, ptr, "local_free", my_tid); @@ -180,11 +186,15 @@ void tiny_free_local_box(SuperSlab* ss, int slab_idx, TinySlabMeta* meta, void* ss_mark_slab_empty(ss, slab_idx); // DEBUG LOGGING - Track when used reaches 0 +#if !HAKMEM_BUILD_RELEASE static int dbg = -1; if (__builtin_expect(dbg == -1, 0)) { const char* e = getenv("HAKMEM_SS_FREE_DEBUG"); dbg = (e && *e && *e != '0') ? 1 : 0; } +#else + const int dbg = 0; +#endif if (dbg == 1) { fprintf(stderr, "[FREE_LOCAL_BOX] EMPTY detected: cls=%u ss=%p slab=%d empty_mask=0x%x empty_count=%u\n", cls, (void*)ss, slab_idx, ss->empty_mask, ss->empty_count);