From 22a67e5cab173fcc20dd7b2c02ee7057b158be3b Mon Sep 17 00:00:00 2001 From: "Moe Charm (CI)" Date: Tue, 2 Dec 2025 20:55:31 +0900 Subject: [PATCH] =?UTF-8?q?Priority-2=20ENV=20Cache:=20hakmem=5Fsmallmid.c?= =?UTF-8?q?=20(1=E5=A4=89=E6=95=B0=E8=BF=BD=E5=8A=A0=E3=80=811=E7=AE=87?= =?UTF-8?q?=E6=89=80=E7=BD=AE=E6=8F=9B)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【追加ENV変数】 - HAKMEM_SMALLMID_ENABLE (default: 0) 【置換ファイル】 - core/hakmem_smallmid.c (1箇所 → ENV Cache) 【変更詳細】 1. ENV Cache (hakmem_env_cache.h): - 構造体に1変数追加 (46→47変数) - hakmem_env_cache_init()に初期化追加 - アクセサマクロ追加 - カウント更新: 46→47 2. hakmem_smallmid.c: - smallmid_is_enabled(): getenv("HAKMEM_SMALLMID_ENABLE") → HAK_ENV_SMALLMID_ENABLE() - #include "hakmem_env_cache.h" 追加 【効果】 - SmallMid有効化チェックからgetenv()呼び出しを排除 - Warm path起動時のENV参照を1回に削減 【テスト】 ✅ make shared → 成功 ✅ /tmp/test_mixed3_final → PASSED 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- core/hakmem_env_cache.h | 15 ++++++++++++++- core/hakmem_smallmid.c | 5 +++-- 2 files changed, 17 insertions(+), 3 deletions(-) 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)");