ENV Cleanup Step 18: Gate HAKMEM_TINY_SLL_DIAG

Gate the SLL diagnostics debug variable behind #if !HAKMEM_BUILD_RELEASE:
- HAKMEM_TINY_SLL_DIAG: Controls singly-linked list integrity diagnostics
- 5 call sites gated (2 already gated, 5 needed gating):

Files modified:
- core/box/tls_sll_box.h:117 (tls_sll_dump_tls_window)
- core/box/tls_sll_box.h:191 (tls_sll_diag_next)
- core/hakmem_tiny.c:629 (tiny_tls_sll_diag_atexit destructor)
- core/hakmem_tiny_superslab.c:142 (remote drain diag)
- core/tiny_superslab_free.inc.h:132 (header mismatch detector)

Already gated:
- core/box/free_local_box.c:38 (already gated at line 33)
- core/box/free_local_box.c:87 (already gated at line 82)

Performance: 30.9M ops/s (baseline maintained)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm (CI)
2025-11-28 04:39:20 +09:00
parent 7d0782d5b6
commit 813ebd5221
4 changed files with 18 additions and 0 deletions

View File

@ -111,6 +111,7 @@ static inline void* tls_sll_normalize_base(int class_idx, void* node)
// Narrow dump around TLS SLL array when corruption is detected (env-gated)
static inline void tls_sll_dump_tls_window(int class_idx, const char* stage)
{
#if !HAKMEM_BUILD_RELEASE
static _Atomic uint32_t g_tls_sll_diag_shots = 0;
static int s_diag_enable = -1;
if (__builtin_expect(s_diag_enable == -1, 0)) {
@ -154,6 +155,9 @@ static inline void tls_sll_dump_tls_window(int class_idx, const char* stage)
fprintf(stderr, " canary_before=%#llx canary_after=%#llx\n",
(unsigned long long)g_tls_canary_before_sll,
(unsigned long long)g_tls_canary_after_sll);
#else
(void)class_idx; (void)stage;
#endif
}
static inline void tls_sll_record_writer(int class_idx, const char* who)
@ -186,6 +190,7 @@ static inline void tls_sll_log_hdr_mismatch(int class_idx, void* base, uint8_t g
static inline void tls_sll_diag_next(int class_idx, void* base, void* next, const char* stage)
{
#if !HAKMEM_BUILD_RELEASE
static int s_diag_enable = -1;
if (__builtin_expect(s_diag_enable == -1, 0)) {
const char* e = getenv("HAKMEM_TINY_SLL_DIAG");
@ -227,6 +232,9 @@ static inline void tls_sll_diag_next(int class_idx, void* base, void* next, cons
slab_idx,
(void*)ss);
}
#else
(void)class_idx; (void)base; (void)next; (void)stage;
#endif
}
// ========== Push ==========

View File

@ -626,6 +626,7 @@ extern _Atomic uint64_t g_tls_sll_invalid_head[TINY_NUM_CLASSES];
extern _Atomic uint64_t g_tls_sll_invalid_push[TINY_NUM_CLASSES];
static void tiny_tls_sll_diag_atexit(void) __attribute__((destructor));
static void tiny_tls_sll_diag_atexit(void) {
#if !HAKMEM_BUILD_RELEASE
const char* env = getenv("HAKMEM_TINY_SLL_DIAG");
if (!(env && *env && *env != '0')) return;
fprintf(stderr, "\n[TLS_SLL_DIAG] invalid head/push counts per class\n");
@ -637,6 +638,7 @@ static void tiny_tls_sll_diag_atexit(void) {
cls, (unsigned long long)ih, (unsigned long long)ip);
}
}
#endif
}

View File

@ -138,10 +138,16 @@ void _ss_remote_drain_to_freelist_unsafe(SuperSlab* ss, int slab_idx, TinySlabMe
uintptr_t cur = head;
while (cur != 0) {
uintptr_t next = *(uintptr_t*)cur; // remote-next stored at offset 0
#if !HAKMEM_BUILD_RELEASE
if (__builtin_expect(g_remote_drain_diag_en == -1, 0)) {
const char* e = getenv("HAKMEM_TINY_SLL_DIAG");
g_remote_drain_diag_en = (e && *e && *e != '0') ? 1 : 0;
}
#else
if (__builtin_expect(g_remote_drain_diag_en == -1, 0)) {
g_remote_drain_diag_en = 0;
}
#endif
if (__builtin_expect(g_remote_drain_diag_en, 0)) {
uintptr_t addr = (uintptr_t)next;
if (addr != 0 && (addr < 4096 || addr > 0x00007fffffffffffULL)) {

View File

@ -126,6 +126,7 @@ static inline void hak_tiny_free_superslab(void* ptr, SuperSlab* ss) {
}
// Header vs meta class mismatch detectorenv: HAKMEM_TINY_SLL_DIAG、初回数件のみ
#if !HAKMEM_BUILD_RELEASE
do {
static int g_hdr_diag_en = -1;
if (__builtin_expect(g_hdr_diag_en == -1, 0)) {
@ -146,6 +147,7 @@ static inline void hak_tiny_free_superslab(void* ptr, SuperSlab* ss) {
}
}
} while (0);
#endif
// Phase 6.23: Same-thread check (Phase 12: owner_tid_low)
uint32_t my_tid = tiny_self_u32();