release: silence runtime logs and stabilize benches

- Fix HAKMEM_LOG gating to use  (numeric) so release builds compile out logs.
- Switch remaining prints to HAKMEM_LOG or guard with :
  - core/box/hak_core_init.inc.h (EVO sample warning, shutdown banner)
  - core/hakmem_config.c (config/feature prints)
  - core/hakmem.c (BigCache eviction prints)
  - core/hakmem_tiny_superslab.c (OOM, head init/expand, C7 init diagnostics)
  - core/hakmem_elo.c (init/evolution)
  - core/hakmem_batch.c (init/flush/stats)
  - core/hakmem_ace.c (33KB route diagnostics)
  - core/hakmem_ace_controller.c (ACE logs macro → no-op in release)
  - core/hakmem_site_rules.c (init banner)
  - core/box/hak_free_api.inc.h (unknown method error → release-gated)
- Rebuilt benches and verified quiet output for release:
  - bench_fixed_size_hakmem/system
  - bench_random_mixed_hakmem/system
  - bench_mid_large_mt_hakmem/system
  - bench_comprehensive_hakmem/system

Note: Kept debug logs available in debug builds and when explicitly toggled via env.
This commit is contained in:
Moe Charm (CI)
2025-11-11 01:47:06 +09:00
parent a97005f50e
commit 8feeb63c2b
25 changed files with 215 additions and 144 deletions

View File

@ -16,6 +16,7 @@
#include <unistd.h>
#include <sys/resource.h> // getrlimit for OOM diagnostics
#include <sys/mman.h>
#include "hakmem_internal.h" // HAKMEM_LOG for release-silent logging
static int g_ss_force_lg = -1;
static _Atomic int g_ss_populate_once = 0;
@ -166,6 +167,7 @@ static void log_superslab_oom_once(size_t ss_size, size_t alloc_size, int err) {
snprintf(rl_max_buf, sizeof(rl_max_buf), "%llu", (unsigned long long)rl.rlim_max);
}
#if !HAKMEM_BUILD_RELEASE
fprintf(stderr,
"[SS OOM] mmap failed: err=%d ss_size=%zu alloc_size=%zu "
"alloc=%llu freed=%llu bytes=%llu "
@ -180,6 +182,7 @@ static void log_superslab_oom_once(size_t ss_size, size_t alloc_size, int err) {
rl_max_buf,
vm_size_kb,
vm_rss_kb);
#endif
g_hakmem_lock_depth--; // Now safe to restore (all libc calls complete)
}
@ -229,11 +232,13 @@ static void* ss_os_acquire(uint8_t size_class, size_t ss_size, uintptr_t ss_mask
-1, 0);
if (raw != MAP_FAILED) {
uint64_t count = atomic_fetch_add(&g_ss_mmap_count, 1) + 1;
#if !HAKMEM_BUILD_RELEASE
if (log_count < 10) {
fprintf(stderr, "[SUPERSLAB_MMAP] #%lu: class=%d size=%zu (total SuperSlab mmaps so far)\n",
(unsigned long)count, size_class, ss_size);
log_count++;
}
#endif
}
if (raw == MAP_FAILED) {
log_superslab_oom_once(ss_size, alloc_size, errno);
@ -562,8 +567,10 @@ SuperSlabHead* init_superslab_head(int class_idx) {
extern __thread int g_hakmem_lock_depth;
g_hakmem_lock_depth++;
#if !HAKMEM_BUILD_RELEASE
fprintf(stderr, "[HAKMEM] Initialized SuperSlabHead for class %d: %zu initial chunks\n",
class_idx, atomic_load_explicit(&head->total_chunks, memory_order_relaxed));
#endif
g_hakmem_lock_depth--;
return head;
@ -745,13 +752,14 @@ void superslab_init_slab(SuperSlab* ss, int slab_idx, size_t block_size, uint32_
static _Atomic int g_cap_log_printed = 0;
if (atomic_load(&g_cap_log_printed) == 0 &&
atomic_exchange(&g_cap_log_printed, 1) == 0) {
#if !HAKMEM_BUILD_RELEASE
fprintf(stderr, "[SUPERSLAB_INIT] class 7 slab 0: usable_size=%zu stride=%zu capacity=%d\n",
usable_size, stride, capacity);
fprintf(stderr, "[SUPERSLAB_INIT] Expected: 63488 / 1024 = 62 blocks\n");
if (capacity != 62) {
fprintf(stderr, "[SUPERSLAB_INIT] WARNING: capacity=%d (expected 62!)\n", capacity);
}
fflush(stderr);
#endif
}
}