From 25a81713b45e4c6b1984839296a9bbe2cf0a2fcb Mon Sep 17 00:00:00 2001 From: "Moe Charm (CI)" Date: Fri, 7 Nov 2025 03:03:07 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20Move=20g=5Fhakmem=5Flock=5Fdepth++=20to?= =?UTF-8?q?=20function=20start=20(27%=20=E2=86=92=2070%=20success)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Problem**: After previous fixes, 4T Larson success rate dropped 27% (4/15) **Root Cause**: In `log_superslab_oom_once()`, `g_hakmem_lock_depth++` was placed AFTER `getrlimit()` call. However, the function was already called from within malloc wrapper context where `g_hakmem_lock_depth = 1`. When `getrlimit()` or other LIBC functions call `malloc()` internally, they enter the wrapper with lock_depth=1, but the increment to 2 hasn't happened yet, so getenv() in wrapper can trigger recursion. **Fix**: Move `g_hakmem_lock_depth++` to the VERY FIRST line after early return check. This ensures ALL subsequent LIBC calls (getrlimit, fopen, fclose, fprintf) bypass HAKMEM wrapper. **Result**: 4T Larson success rate improved 27% → 70% (14/20 runs) ✅ +43% improvement, but 30% crash rate remains (continuing investigation) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- core/hakmem_tiny_superslab.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/hakmem_tiny_superslab.c b/core/hakmem_tiny_superslab.c index 21b01eb7..0f8ef63c 100644 --- a/core/hakmem_tiny_superslab.c +++ b/core/hakmem_tiny_superslab.c @@ -117,6 +117,12 @@ static void log_superslab_oom_once(size_t ss_size, size_t alloc_size, int err) { if (logged) return; logged = 1; + // CRITICAL FIX: Increment lock depth FIRST before any LIBC calls + // fopen/fclose/getrlimit/fprintf all may call malloc internally + // Must bypass HAKMEM wrapper to avoid header mismatch crash + extern __thread int g_hakmem_lock_depth; + g_hakmem_lock_depth++; // Force wrapper to use __libc_malloc + struct rlimit rl = {0}; if (getrlimit(RLIMIT_AS, &rl) != 0) { rl.rlim_cur = RLIM_INFINITY; @@ -125,10 +131,6 @@ static void log_superslab_oom_once(size_t ss_size, size_t alloc_size, int err) { unsigned long vm_size_kb = 0; unsigned long vm_rss_kb = 0; - // CRITICAL FIX: fopen/fclose use GLIBC malloc/free internally - // Must bypass HAKMEM wrapper to avoid header mismatch crash - extern __thread int g_hakmem_lock_depth; - g_hakmem_lock_depth++; // Force wrapper to use __libc_malloc FILE* status = fopen("/proc/self/status", "r"); if (status) { char line[256];