ENV cleanup: Remove BG/HotMag vars & guard fprintf (Larson 52.3M ops/s)
Phase 1 完了:環境変数整理 + fprintf デバッグガード ENV変数削除(BG/HotMag系): - core/hakmem_tiny_init.inc: HotMag ENV 削除 (~131 lines) - core/hakmem_tiny_bg_spill.c: BG spill ENV 削除 - core/tiny_refill.h: BG remote 固定値化 - core/hakmem_tiny_slow.inc: BG refs 削除 fprintf Debug Guards (#if !HAKMEM_BUILD_RELEASE): - core/hakmem_shared_pool.c: Lock stats (~18 fprintf) - core/page_arena.c: Init/Shutdown/Stats (~27 fprintf) - core/hakmem.c: SIGSEGV init message ドキュメント整理: - 328 markdown files 削除(旧レポート・重複docs) 性能確認: - Larson: 52.35M ops/s (前回52.8M、安定動作✅) - ENV整理による機能影響なし - Debug出力は一部残存(次phase で対応) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -183,131 +183,6 @@ void hak_tiny_init(void) {
|
||||
g_sll_multiplier = v;
|
||||
}
|
||||
|
||||
// HotMag enable / tuning(既定OFF, envでON可)
|
||||
{
|
||||
char* hm = getenv("HAKMEM_TINY_HOTMAG");
|
||||
if (hm) g_hotmag_enable = (atoi(hm) != 0) ? 1 : 0;
|
||||
char* hmcap = getenv("HAKMEM_TINY_HOTMAG_CAP");
|
||||
if (hmcap) {
|
||||
int v = atoi(hmcap);
|
||||
if (v < 16) v = 16;
|
||||
else if (v > 1024) v = 1024;
|
||||
g_hotmag_cap_default = v;
|
||||
}
|
||||
char* hmrefill = getenv("HAKMEM_TINY_HOTMAG_REFILL");
|
||||
if (hmrefill) {
|
||||
int v = atoi(hmrefill);
|
||||
if (v < 0) v = 0;
|
||||
if (v > g_hotmag_cap_default) v = g_hotmag_cap_default;
|
||||
g_hotmag_refill_default = v;
|
||||
}
|
||||
if (g_hotmag_refill_default > g_hotmag_cap_default) {
|
||||
g_hotmag_refill_default = g_hotmag_cap_default;
|
||||
}
|
||||
if (g_hotmag_refill_default < 0) g_hotmag_refill_default = 0;
|
||||
|
||||
for (int k = 0; k < TINY_NUM_CLASSES; k++) {
|
||||
uint16_t cap = hotmag_effective_cap(k);
|
||||
g_hotmag_cap_current[k] = cap;
|
||||
g_hotmag_cap_locked[k] = 0;
|
||||
uint16_t refill = (uint16_t)g_hotmag_refill_default;
|
||||
if (refill > cap) refill = cap;
|
||||
g_hotmag_refill_current[k] = refill;
|
||||
g_hotmag_refill_locked[k] = 0;
|
||||
g_hotmag_class_en[k] = (k <= 3) ? 1 : 0;
|
||||
}
|
||||
|
||||
// Heuristic defaults for the three hottest classes when not overridden
|
||||
if (!g_hotmag_cap_locked[0]) {
|
||||
uint16_t cap = g_hotmag_cap_current[0];
|
||||
uint16_t cap_target = (g_hotmag_cap_default > 48) ? 48 : (uint16_t)g_hotmag_cap_default;
|
||||
if (cap_target < 16) cap_target = 16;
|
||||
if (cap_target < cap) g_hotmag_cap_current[0] = cap_target;
|
||||
}
|
||||
if (!g_hotmag_cap_locked[1]) {
|
||||
uint16_t cap = g_hotmag_cap_current[1];
|
||||
uint16_t cap_target = (g_hotmag_cap_default > 80) ? 80 : (uint16_t)g_hotmag_cap_default;
|
||||
if (cap_target < 32) cap_target = 32;
|
||||
if (cap_target < cap) g_hotmag_cap_current[1] = cap_target;
|
||||
}
|
||||
if (!g_hotmag_cap_locked[2]) {
|
||||
uint16_t cap = g_hotmag_cap_current[2];
|
||||
uint16_t cap_target = (g_hotmag_cap_default > 112) ? 112 : (uint16_t)g_hotmag_cap_default;
|
||||
if (cap_target < 48) cap_target = 48;
|
||||
if (cap_target < cap) g_hotmag_cap_current[2] = cap_target;
|
||||
}
|
||||
|
||||
if (!g_hotmag_refill_locked[0]) {
|
||||
g_hotmag_refill_current[0] = 0;
|
||||
}
|
||||
if (!g_hotmag_refill_locked[1]) {
|
||||
uint16_t cap = g_hotmag_cap_current[1];
|
||||
uint16_t ref = (g_hotmag_refill_default > 0) ? (uint16_t)g_hotmag_refill_default : 0;
|
||||
if (ref > 0) {
|
||||
uint16_t limit = (cap > 20) ? 20 : cap;
|
||||
if (ref > limit) ref = limit;
|
||||
if (ref > cap) ref = cap;
|
||||
}
|
||||
g_hotmag_refill_current[1] = ref;
|
||||
}
|
||||
if (!g_hotmag_refill_locked[2]) {
|
||||
uint16_t cap = g_hotmag_cap_current[2];
|
||||
uint16_t ref = (g_hotmag_refill_default > 0) ? (uint16_t)g_hotmag_refill_default : 0;
|
||||
if (ref > 0) {
|
||||
uint16_t limit = (cap > 40) ? 40 : cap;
|
||||
if (ref > limit) ref = limit;
|
||||
if (ref > cap) ref = cap;
|
||||
}
|
||||
g_hotmag_refill_current[2] = ref;
|
||||
}
|
||||
|
||||
// Default: disable class 2 (32B) HotMag entirely unless explicitly enabled by env
|
||||
if (!getenv("HAKMEM_TINY_HOTMAG_C2")) {
|
||||
g_hotmag_class_en[2] = 0;
|
||||
}
|
||||
|
||||
for (int k = 0; k < TINY_NUM_CLASSES; k++) {
|
||||
char key_cap[64];
|
||||
snprintf(key_cap, sizeof(key_cap), "HAKMEM_TINY_HOTMAG_CAP_C%d", k);
|
||||
char* cap_env = getenv(key_cap);
|
||||
if (cap_env) {
|
||||
int v = atoi(cap_env);
|
||||
if (v < 16) v = 16;
|
||||
else if (v > 1024) v = 1024;
|
||||
g_hotmag_cap_current[k] = (uint16_t)v;
|
||||
g_hotmag_cap_locked[k] = 1;
|
||||
if (!g_hotmag_refill_locked[k] && g_hotmag_refill_current[k] > g_hotmag_cap_current[k]) {
|
||||
g_hotmag_refill_current[k] = g_hotmag_cap_current[k];
|
||||
}
|
||||
}
|
||||
char key_ref[64];
|
||||
snprintf(key_ref, sizeof(key_ref), "HAKMEM_TINY_HOTMAG_REFILL_C%d", k);
|
||||
char* ref_env = getenv(key_ref);
|
||||
if (ref_env) {
|
||||
int v = atoi(ref_env);
|
||||
if (v < 0) v = 0;
|
||||
if (v > g_hotmag_cap_current[k]) v = g_hotmag_cap_current[k];
|
||||
g_hotmag_refill_current[k] = (uint16_t)v;
|
||||
g_hotmag_refill_locked[k] = 1;
|
||||
}
|
||||
char key_en[64];
|
||||
snprintf(key_en, sizeof(key_en), "HAKMEM_TINY_HOTMAG_C%d", k);
|
||||
char* en_env = getenv(key_en);
|
||||
if (en_env) {
|
||||
g_hotmag_class_en[k] = (uint8_t)((atoi(en_env) != 0) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
for (int k = 0; k < TINY_NUM_CLASSES; k++) {
|
||||
if (g_hotmag_enable && hkm_is_hot_class(k)) {
|
||||
g_tls_hot_mag[k].cap = g_hotmag_cap_current[k];
|
||||
} else {
|
||||
g_tls_hot_mag[k].cap = 0; // lazy init
|
||||
}
|
||||
g_tls_hot_mag[k].top = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Ultra-Simple front enable(既定OFF, A/B用)
|
||||
{
|
||||
char* us = getenv("HAKMEM_TINY_ULTRA_SIMPLE");
|
||||
@ -315,47 +190,12 @@ void hak_tiny_init(void) {
|
||||
// zero-initialized by default
|
||||
}
|
||||
|
||||
// Background Refill Bin(既定OFF, A/B用)
|
||||
{
|
||||
char* bb = getenv("HAKMEM_TINY_BG_BIN");
|
||||
if (bb) g_bg_bin_enable = (atoi(bb) != 0) ? 1 : 0;
|
||||
char* bt = getenv("HAKMEM_TINY_BG_TARGET");
|
||||
if (bt) { int v = atoi(bt); if (v > 0 && v <= 4096) g_bg_bin_target = v; }
|
||||
for (int k = 0; k < TINY_NUM_CLASSES; k++) {
|
||||
atomic_store_explicit(&g_bg_bin_head[k], (uintptr_t)0, memory_order_relaxed);
|
||||
}
|
||||
if (g_bg_bin_enable && !g_bg_bin_started) {
|
||||
if (pthread_create(&g_bg_bin_thread, NULL, tiny_bg_refill_main, NULL) == 0) {
|
||||
g_bg_bin_started = 1;
|
||||
} else {
|
||||
g_bg_bin_enable = 0; // disable on failure
|
||||
}
|
||||
}
|
||||
}
|
||||
// Background Spill/Drain (integrated into bg thread)
|
||||
// EXTRACTED: bg_spill init moved to hakmem_tiny_bg_spill.c (Phase 2C-2)
|
||||
{
|
||||
bg_spill_init(); // Initialize bg_spill module from environment
|
||||
|
||||
// Remote target queue init (Phase 2C-1)
|
||||
char* br = getenv("HAKMEM_TINY_BG_REMOTE");
|
||||
if (br) g_bg_remote_enable = (atoi(br) != 0) ? 1 : 0;
|
||||
char* rb = getenv("HAKMEM_TINY_BG_REMOTE_BATCH");
|
||||
if (rb) { int v = atoi(rb); if (v > 0 && v <= 4096) g_bg_remote_batch = v; }
|
||||
for (int k = 0; k < TINY_NUM_CLASSES; k++) {
|
||||
atomic_store_explicit(&g_remote_target_head[k], (uintptr_t)0, memory_order_relaxed);
|
||||
atomic_store_explicit(&g_remote_target_len[k], 0u, memory_order_relaxed);
|
||||
}
|
||||
|
||||
// bg thread already started above if bg_bin_enable=1; if only spill is enabled, start thread
|
||||
if (g_bg_spill_enable && !g_bg_bin_started) {
|
||||
if (pthread_create(&g_bg_bin_thread, NULL, tiny_bg_refill_main, NULL) == 0) {
|
||||
g_bg_bin_started = 1;
|
||||
g_bg_bin_enable = 1; // reuse loop
|
||||
} else {
|
||||
g_bg_spill_enable = 0;
|
||||
}
|
||||
}
|
||||
// Background Bin/Spill/Remote: runtime ENV toggles removed (fixed OFF)
|
||||
// Initialize heads to keep structures consistent.
|
||||
for (int k = 0; k < TINY_NUM_CLASSES; k++) {
|
||||
atomic_store_explicit(&g_bg_bin_head[k], (uintptr_t)0, memory_order_relaxed);
|
||||
atomic_store_explicit(&g_remote_target_head[k], (uintptr_t)0, memory_order_relaxed);
|
||||
atomic_store_explicit(&g_remote_target_len[k], 0u, memory_order_relaxed);
|
||||
}
|
||||
// Optional prefetch enable
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user