Fix memory guard: remove RLIMIT_AS (blocks Python heap), VmRSS-only
This commit is contained in:
+6
-5
@@ -32,15 +32,16 @@ from common.risk import risk_summary
|
||||
from strategies.quant_report import compute_quant_report
|
||||
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
# Memory guard: cap RSS at 512MB, GC-aggressive at 256MB
|
||||
# Memory guard: check RSS via /proc, force GC at 256MB,
|
||||
# log warning at 384MB, hard exit at 512MB.
|
||||
# RLIMIT_AS disabled — Python heap needs virtual headroom.
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
import resource, gc, signal
|
||||
import gc, os as _os
|
||||
|
||||
MEM_SOFT_LIMIT = 256 * 1024 * 1024 # 256 MB — force GC
|
||||
MEM_WARN_LIMIT = 384 * 1024 * 1024 # 384 MB — log warning
|
||||
MEM_HARD_LIMIT = 512 * 1024 * 1024 # 512 MB — terminate
|
||||
|
||||
resource.setrlimit(resource.RLIMIT_AS, (MEM_HARD_LIMIT, MEM_HARD_LIMIT))
|
||||
|
||||
def check_memory():
|
||||
"""Check RSS, force GC if over soft limit, raise if over hard limit."""
|
||||
try:
|
||||
@@ -51,7 +52,7 @@ def check_memory():
|
||||
rss = rss_kb * 1024
|
||||
if rss > MEM_HARD_LIMIT:
|
||||
print(f"[CRIT] RSS {rss_kb // 1024}MB > 512MB — exiting", flush=True)
|
||||
os._exit(1)
|
||||
_os._exit(1)
|
||||
if rss > MEM_SOFT_LIMIT:
|
||||
gc.collect()
|
||||
gc.collect()
|
||||
|
||||
Reference in New Issue
Block a user