Priority-2: ENV Cache - SFC (Super Front Cache) getenv() 置換
変更内容: - hakmem_env_cache.h: 4つの新ENV変数を追加 (SFC_DEBUG, SFC_ENABLE, SFC_CAPACITY, SFC_REFILL_COUNT) - hakmem_tiny_sfc.c: 4箇所の getenv() を置換 (init時のdebug/enable/capacity/refill設定) ※Per-class動的変数(2箇所)は初期化時のみのため後回し 効果: SFC層からも syscall を排除 (ENV変数数: 37→41) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -49,12 +49,16 @@ typedef struct {
|
|||||||
// ===== Warm Path: Lazy Init (1 variable) =====
|
// ===== Warm Path: Lazy Init (1 variable) =====
|
||||||
int ss_map_trace; // HAKMEM_SS_MAP_TRACE (default: 0)
|
int ss_map_trace; // HAKMEM_SS_MAP_TRACE (default: 0)
|
||||||
|
|
||||||
// ===== Warm Path: FastCache (5 variables) =====
|
// ===== Warm Path: FastCache (9 variables) =====
|
||||||
int tiny_fast_debug; // HAKMEM_TINY_FAST_DEBUG (default: 0)
|
int tiny_fast_debug; // HAKMEM_TINY_FAST_DEBUG (default: 0)
|
||||||
int tiny_fast_debug_max; // HAKMEM_TINY_FAST_DEBUG_MAX (default: 0)
|
int tiny_fast_debug_max; // HAKMEM_TINY_FAST_DEBUG_MAX (default: 0)
|
||||||
int tiny_front_direct; // HAKMEM_TINY_FRONT_DIRECT (default: 0)
|
int tiny_front_direct; // HAKMEM_TINY_FRONT_DIRECT (default: 0)
|
||||||
int tiny_fast_stats; // HAKMEM_TINY_FAST_STATS (default: 0)
|
int tiny_fast_stats; // HAKMEM_TINY_FAST_STATS (default: 0)
|
||||||
int tiny_unified_cache; // HAKMEM_TINY_UNIFIED_CACHE (default: 1)
|
int tiny_unified_cache; // HAKMEM_TINY_UNIFIED_CACHE (default: 1)
|
||||||
|
int sfc_debug; // HAKMEM_SFC_DEBUG (default: 0)
|
||||||
|
int sfc_enable; // HAKMEM_SFC_ENABLE (default: 1)
|
||||||
|
int sfc_capacity; // HAKMEM_SFC_CAPACITY (default: 128)
|
||||||
|
int sfc_refill_count; // HAKMEM_SFC_REFILL_COUNT (default: 16)
|
||||||
|
|
||||||
// ===== Cold Path: Headers/Debug (12 variables) =====
|
// ===== Cold Path: Headers/Debug (12 variables) =====
|
||||||
int tiny_restore_header; // HAKMEM_TINY_RESTORE_HEADER (default: 0)
|
int tiny_restore_header; // HAKMEM_TINY_RESTORE_HEADER (default: 0)
|
||||||
@ -171,6 +175,18 @@ static inline void hakmem_env_cache_init(void) {
|
|||||||
e = getenv("HAKMEM_TINY_UNIFIED_CACHE");
|
e = getenv("HAKMEM_TINY_UNIFIED_CACHE");
|
||||||
// Default: 1 (enabled), set HAKMEM_TINY_UNIFIED_CACHE=0 to disable
|
// Default: 1 (enabled), set HAKMEM_TINY_UNIFIED_CACHE=0 to disable
|
||||||
g_hak_env_cache.tiny_unified_cache = (e && *e && *e == '0') ? 0 : 1;
|
g_hak_env_cache.tiny_unified_cache = (e && *e && *e == '0') ? 0 : 1;
|
||||||
|
|
||||||
|
e = getenv("HAKMEM_SFC_DEBUG");
|
||||||
|
g_hak_env_cache.sfc_debug = (e && *e && *e != '0') ? 1 : 0;
|
||||||
|
|
||||||
|
e = getenv("HAKMEM_SFC_ENABLE");
|
||||||
|
g_hak_env_cache.sfc_enable = (e && *e && *e != '0') ? 1 : 0;
|
||||||
|
|
||||||
|
e = getenv("HAKMEM_SFC_CAPACITY");
|
||||||
|
g_hak_env_cache.sfc_capacity = (e && *e) ? atoi(e) : 128;
|
||||||
|
|
||||||
|
e = getenv("HAKMEM_SFC_REFILL_COUNT");
|
||||||
|
g_hak_env_cache.sfc_refill_count = (e && *e) ? atoi(e) : 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== Cold Path: Headers/Debug =====
|
// ===== Cold Path: Headers/Debug =====
|
||||||
@ -217,7 +233,7 @@ static inline void hakmem_env_cache_init(void) {
|
|||||||
#if !HAKMEM_BUILD_RELEASE
|
#if !HAKMEM_BUILD_RELEASE
|
||||||
// Debug: Print cache summary (stderr only)
|
// Debug: Print cache summary (stderr only)
|
||||||
if (!g_hak_env_cache.quiet) {
|
if (!g_hak_env_cache.quiet) {
|
||||||
fprintf(stderr, "[ENV_CACHE_INIT] Parsed %d ENV variables at startup\n", 37);
|
fprintf(stderr, "[ENV_CACHE_INIT] Parsed %d ENV variables at startup\n", 41);
|
||||||
fprintf(stderr, "[ENV_CACHE_INIT] Hot path syscalls eliminated: ~2000/sec → 0/sec\n");
|
fprintf(stderr, "[ENV_CACHE_INIT] Hot path syscalls eliminated: ~2000/sec → 0/sec\n");
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
}
|
}
|
||||||
@ -251,6 +267,10 @@ static inline void hakmem_env_cache_init(void) {
|
|||||||
#define HAK_ENV_TINY_FRONT_DIRECT() (g_hak_env_cache.tiny_front_direct)
|
#define HAK_ENV_TINY_FRONT_DIRECT() (g_hak_env_cache.tiny_front_direct)
|
||||||
#define HAK_ENV_TINY_FAST_STATS() (g_hak_env_cache.tiny_fast_stats)
|
#define HAK_ENV_TINY_FAST_STATS() (g_hak_env_cache.tiny_fast_stats)
|
||||||
#define HAK_ENV_TINY_UNIFIED_CACHE() (g_hak_env_cache.tiny_unified_cache)
|
#define HAK_ENV_TINY_UNIFIED_CACHE() (g_hak_env_cache.tiny_unified_cache)
|
||||||
|
#define HAK_ENV_SFC_DEBUG() (g_hak_env_cache.sfc_debug)
|
||||||
|
#define HAK_ENV_SFC_ENABLE() (g_hak_env_cache.sfc_enable)
|
||||||
|
#define HAK_ENV_SFC_CAPACITY() (g_hak_env_cache.sfc_capacity)
|
||||||
|
#define HAK_ENV_SFC_REFILL_COUNT() (g_hak_env_cache.sfc_refill_count)
|
||||||
|
|
||||||
// Cold path accessors
|
// Cold path accessors
|
||||||
#define HAK_ENV_TINY_RESTORE_HEADER() (g_hak_env_cache.tiny_restore_header)
|
#define HAK_ENV_TINY_RESTORE_HEADER() (g_hak_env_cache.tiny_restore_header)
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
#include "hakmem_stats_master.h" // Phase 4d: Master stats control
|
#include "hakmem_stats_master.h" // Phase 4d: Master stats control
|
||||||
#include "tiny_tls.h"
|
#include "tiny_tls.h"
|
||||||
#include "box/tls_sll_box.h" // static inline tls_sll_pop/push API (Box TLS-SLL)
|
#include "box/tls_sll_box.h" // static inline tls_sll_pop/push API (Box TLS-SLL)
|
||||||
|
#include "hakmem_env_cache.h" // Priority-2: ENV cache (eliminate syscalls)
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -49,38 +50,25 @@ static int g_sfc_refill_override[TINY_NUM_CLASSES] = {0};
|
|||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
void sfc_init(void) {
|
void sfc_init(void) {
|
||||||
// Cache debug flag once (hot paths reuse g_sfc_debug)
|
// Priority-2: Use cached ENV (eliminate init syscall overhead)
|
||||||
const char* env_debug = getenv("HAKMEM_SFC_DEBUG");
|
g_sfc_debug = HAK_ENV_SFC_DEBUG();
|
||||||
g_sfc_debug = (env_debug && *env_debug && *env_debug != '0') ? 1 : 0;
|
g_sfc_enabled = HAK_ENV_SFC_ENABLE();
|
||||||
|
|
||||||
// Parse ENV: HAKMEM_SFC_ENABLE
|
|
||||||
const char* env_enable = getenv("HAKMEM_SFC_ENABLE");
|
|
||||||
if (env_enable && *env_enable && *env_enable != '0') {
|
|
||||||
g_sfc_enabled = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!g_sfc_enabled) {
|
if (!g_sfc_enabled) {
|
||||||
// SFC disabled, skip initialization
|
// SFC disabled, skip initialization
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse ENV: HAKMEM_SFC_CAPACITY (default capacity for all classes)
|
// Priority-2: Use cached ENV (eliminate config syscall overhead)
|
||||||
const char* env_cap = getenv("HAKMEM_SFC_CAPACITY");
|
int cap = HAK_ENV_SFC_CAPACITY();
|
||||||
if (env_cap && *env_cap) {
|
|
||||||
int cap = atoi(env_cap);
|
|
||||||
if (cap >= SFC_MIN_CAPACITY && cap <= SFC_MAX_CAPACITY) {
|
if (cap >= SFC_MIN_CAPACITY && cap <= SFC_MAX_CAPACITY) {
|
||||||
g_sfc_default_capacity = cap;
|
g_sfc_default_capacity = cap;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Parse ENV: HAKMEM_SFC_REFILL_COUNT (default refill for all classes)
|
int refill = HAK_ENV_SFC_REFILL_COUNT();
|
||||||
const char* env_refill = getenv("HAKMEM_SFC_REFILL_COUNT");
|
|
||||||
if (env_refill && *env_refill) {
|
|
||||||
int refill = atoi(env_refill);
|
|
||||||
if (refill >= 8 && refill <= 256) {
|
if (refill >= 8 && refill <= 256) {
|
||||||
g_sfc_default_refill = refill;
|
g_sfc_default_refill = refill;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Parse ENV: HAKMEM_SFC_CAPACITY_CLASS{0..7} (per-class capacity override)
|
// Parse ENV: HAKMEM_SFC_CAPACITY_CLASS{0..7} (per-class capacity override)
|
||||||
for (int cls = 0; cls < TINY_NUM_CLASSES; cls++) {
|
for (int cls = 0; cls < TINY_NUM_CLASSES; cls++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user