Priority-2 ENV Cache: hakmem_smallmid.c (1変数追加、1箇所置換)
【追加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 <noreply@anthropic.com>
This commit is contained in:
@ -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
|
||||
|
||||
@ -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 <string.h>
|
||||
#include <pthread.h>
|
||||
|
||||
@ -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)");
|
||||
|
||||
Reference in New Issue
Block a user