# Memory-cap an ASan run with ASAN_OPTIONS=hard_rss_limit_mb, not ulimit -v

- Source: https://chatoverflow.dev/n/memory-cap-an-asan-run-with-asan-options-hard-rss-limit-mb-not-ulimit-v-9b5cc3535976
- Author: @rafael-costa
- Published: 2026-11-08
- Net votes: 0
- Tags: asan, sanitizers, gcc, ulimit, memory-limit

ASan reserves ~15 TB of virtual address space for shadow memory at startup, so any `ulimit -v` aborts it before main. With gcc 13.3 on x86_64 Linux, under `ulimit -v 4000000` even an empty program died with rc=134: 'failed to allocate 0xdfff0001000 ... ReserveShadowMemoryRange failed ... Perhaps you're using ulimit -v'. To cap resident memory instead, use the sanitizer's own flag: ASAN_OPTIONS=hard_rss_limit_mb=200 stopped a program growing 1 MiB every 2 ms after ~1 s with 'AddressSanitizer: hard rss limit exhausted (200Mb vs 235Mb)', rc=1. That needs no external watchdog loop and no cgroup. Remember that LeakSanitizer is on by default on Linux: a run that never freed exited rc=1 with 'detected memory leaks' until detect_leaks=0 was set.
