diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2013-10-03 17:14:35 +0000 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2013-10-03 17:14:35 +0000 |
| commit | 302ec7b9bc49c4c88fd7c9e579de897005bff45e (patch) | |
| tree | 10b6c3ee296fe16a96e51b19c989040c4afac91b /compiler-rt/lib/tsan/rtl/tsan_rtl.cc | |
| parent | 72f55d46c8873a76d9070ca200eeede6aca64d7c (diff) | |
| download | bcm5719-llvm-302ec7b9bc49c4c88fd7c9e579de897005bff45e.tar.gz bcm5719-llvm-302ec7b9bc49c4c88fd7c9e579de897005bff45e.zip | |
tsan: add memory_limit_mb flag
The flag allows to bound maximum process memory consumption (best effort).
If RSS reaches memory_limit_mb, tsan flushes all shadow memory.
llvm-svn: 191913
Diffstat (limited to 'compiler-rt/lib/tsan/rtl/tsan_rtl.cc')
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_rtl.cc | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc index aa8934adab4..9703bb46a89 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc @@ -130,17 +130,38 @@ static void BackgroundThread(void *arg) { } u64 last_flush = NanoTime(); + uptr last_rss = 0; for (int i = 0; ; i++) { SleepForSeconds(1); u64 now = NanoTime(); // Flush memory if requested. - if (flags()->flush_memory_ms) { + if (flags()->flush_memory_ms > 0) { if (last_flush + flags()->flush_memory_ms * kMs2Ns < now) { + if (flags()->verbosity > 0) + Printf("ThreadSanitizer: periodic memory flush\n"); FlushShadowMemory(); last_flush = NanoTime(); } } + if (flags()->memory_limit_mb > 0) { + uptr rss = GetRSS(); + uptr limit = uptr(flags()->memory_limit_mb) << 20; + if (flags()->verbosity > 0) { + Printf("ThreadSanitizer: memory flush check" + " RSS=%llu LAST=%llu LIMIT=%llu\n", + (u64)rss>>20, (u64)last_rss>>20, (u64)limit>>20); + } + if (2 * rss > limit + last_rss) { + if (flags()->verbosity > 0) + Printf("ThreadSanitizer: flushing memory due to RSS\n"); + FlushShadowMemory(); + rss = GetRSS(); + if (flags()->verbosity > 0) + Printf("ThreadSanitizer: memory flushed RSS=%llu\n", (u64)rss>>20); + } + last_rss = rss; + } // Write memory profile if requested. if (mprof_fd != kInvalidFd) |

