Fix: Move g_hakmem_lock_depth++ to function start (27% → 70% success)
**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 <noreply@anthropic.com>
This commit is contained in:
@ -117,6 +117,12 @@ static void log_superslab_oom_once(size_t ss_size, size_t alloc_size, int err) {
|
|||||||
if (logged) return;
|
if (logged) return;
|
||||||
logged = 1;
|
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};
|
struct rlimit rl = {0};
|
||||||
if (getrlimit(RLIMIT_AS, &rl) != 0) {
|
if (getrlimit(RLIMIT_AS, &rl) != 0) {
|
||||||
rl.rlim_cur = RLIM_INFINITY;
|
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_size_kb = 0;
|
||||||
unsigned long vm_rss_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");
|
FILE* status = fopen("/proc/self/status", "r");
|
||||||
if (status) {
|
if (status) {
|
||||||
char line[256];
|
char line[256];
|
||||||
|
|||||||
Reference in New Issue
Block a user