diff --git a/core/hakmem_env_cache.h b/core/hakmem_env_cache.h index 40b69515..c3e6bd3f 100644 --- a/core/hakmem_env_cache.h +++ b/core/hakmem_env_cache.h @@ -81,6 +81,9 @@ typedef struct { int tiny_tension_drain_enable; // HAKMEM_TINY_TENSION_DRAIN_ENABLE (default: 1) int tiny_tension_drain_threshold; // HAKMEM_TINY_TENSION_DRAIN_THRESHOLD (default: 1024) + // ===== Warm Path: SmallMid (1 variable) ===== + int smallmid_enable; // HAKMEM_SMALLMID_ENABLE (default: 0) + } HakEnvCache; // Global cache instance (initialized once at startup) @@ -258,10 +261,17 @@ static inline void hakmem_env_cache_init(void) { if (g_hak_env_cache.tiny_tension_drain_threshold > 65536) g_hak_env_cache.tiny_tension_drain_threshold = 65536; } + // ===== Warm Path: SmallMid ===== + { + const char* e; + e = getenv("HAKMEM_SMALLMID_ENABLE"); + g_hak_env_cache.smallmid_enable = (e && atoi(e) == 1) ? 1 : 0; // default: 0 (OFF) + } + #if !HAKMEM_BUILD_RELEASE // Debug: Print cache summary (stderr only) if (!g_hak_env_cache.quiet) { - fprintf(stderr, "[ENV_CACHE_INIT] Parsed %d ENV variables at startup\n", 46); + fprintf(stderr, "[ENV_CACHE_INIT] Parsed %d ENV variables at startup\n", 47); fprintf(stderr, "[ENV_CACHE_INIT] Hot path syscalls eliminated: ~2000/sec → 0/sec\n"); fflush(stderr); } @@ -321,4 +331,7 @@ static inline void hakmem_env_cache_init(void) { #define HAK_ENV_TINY_TENSION_DRAIN_ENABLE() (g_hak_env_cache.tiny_tension_drain_enable) #define HAK_ENV_TINY_TENSION_DRAIN_THRESHOLD() (g_hak_env_cache.tiny_tension_drain_threshold) +// Warm path: SmallMid +#define HAK_ENV_SMALLMID_ENABLE() (g_hak_env_cache.smallmid_enable) + #endif // HAKMEM_ENV_CACHE_H diff --git a/core/hakmem_smallmid.c b/core/hakmem_smallmid.c index 6a3abe3f..7d653aee 100644 --- a/core/hakmem_smallmid.c +++ b/core/hakmem_smallmid.c @@ -23,6 +23,7 @@ #include "hakmem_build_flags.h" #include "hakmem_smallmid_superslab.h" // Phase 17-2: Dedicated backend #include "tiny_region_id.h" // For header writing +#include "hakmem_env_cache.h" // Priority-2: ENV cache #include #include @@ -79,8 +80,8 @@ void smallmid_print_stats(void) { bool smallmid_is_enabled(void) { if (__builtin_expect(g_smallmid_enabled == -1, 0)) { - const char* env = getenv("HAKMEM_SMALLMID_ENABLE"); - g_smallmid_enabled = (env && atoi(env) == 1) ? 1 : 0; + // Priority-2: Use cached ENV + g_smallmid_enabled = HAK_ENV_SMALLMID_ENABLE(); if (g_smallmid_enabled) { SMALLMID_LOG("Small-Mid allocator ENABLED (ENV: HAKMEM_SMALLMID_ENABLE=1)");