Guard madvise ENOMEM and stabilize pool/tiny front v3

This commit is contained in:
Moe Charm (CI)
2025-12-09 21:50:15 +09:00
parent e274d5f6a9
commit a905e0ffdd
45 changed files with 3154 additions and 242 deletions

View File

@ -91,6 +91,9 @@ typedef struct {
// ===== Cold Path: Batch (1 variable) =====
int batch_bg; // HAKMEM_BATCH_BG (default: 0)
// ===== Cold Path: Superslab Madvise (1 variable) =====
int ss_madvise_strict; // HAKMEM_SS_MADVISE_STRICT (default: 1)
} HakEnvCache;
// Global cache instance (initialized once at startup)
@ -289,10 +292,17 @@ static inline void hakmem_env_cache_init(void) {
g_hak_env_cache.batch_bg = (e && atoi(e) != 0) ? 1 : 0; // default: 0 (OFF)
}
// ===== Cold Path: Superslab Madvise =====
{
const char* e = getenv("HAKMEM_SS_MADVISE_STRICT");
// Default: 1 (STRICT), set HAKMEM_SS_MADVISE_STRICT=0 to relax
g_hak_env_cache.ss_madvise_strict = (e && *e && *e == '0') ? 0 : 1;
}
#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", 49);
fprintf(stderr, "[ENV_CACHE_INIT] Parsed %d ENV variables at startup\n", 50);
fprintf(stderr, "[ENV_CACHE_INIT] Hot path syscalls eliminated: ~2000/sec → 0/sec\n");
fflush(stderr);
}
@ -361,4 +371,7 @@ static inline void hakmem_env_cache_init(void) {
// Cold path: Batch
#define HAK_ENV_BATCH_BG() (g_hak_env_cache.batch_bg)
// Cold path: Superslab Madvise
#define HAK_ENV_SS_MADVISE_STRICT() (g_hak_env_cache.ss_madvise_strict)
#endif // HAKMEM_ENV_CACHE_H