<div dir="ltr">Of course, thanks! <div>r225546.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 9, 2015 at 1:07 AM, Jay Foad <span dir="ltr"><<a href="mailto:jay.foad@gmail.com" target="_blank">jay.foad@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Should this be memory_order_acquire ?<br>
<br>
  bool RssLimitIsExceeded() {<br>
    return atomic_load(&rss_limit_is_exceeded_, memory_order_release);<br>
<div class="HOEnZb"><div class="h5">  }<br>
<br>
On 9 January 2015 at 09:03, Jay Foad <<a href="mailto:jay.foad@gmail.com">jay.foad@gmail.com</a>> wrote:<br>
> Hi Kostya,<br>
><br>
> This commit seems to be causing a bunch of failures in check-asan on<br>
> PowerPC64 Linux, using GCC 4.8.3 as the host compiler:<br>
><br>
> Failing Tests (80):<br>
>     AddressSanitizer64 :: TestCases/Linux/coverage-caller-callee-total-count.cc<br>
>     AddressSanitizer64 :: TestCases/Linux/coverage-caller-callee.cc<br>
>     AddressSanitizer64 :: TestCases/Linux/coverage-direct-activation.cc<br>
>     AddressSanitizer64 :: TestCases/Linux/coverage-direct-large.cc<br>
>     AddressSanitizer64 :: TestCases/Linux/coverage-direct.cc<br>
>     AddressSanitizer64 :: TestCases/Linux/coverage-module-unloaded.cc<br>
>     AddressSanitizer64 :: TestCases/Linux/function-sections-are-bad.cc<br>
>     AddressSanitizer64 :: TestCases/Linux/interception_malloc_test.cc<br>
>     AddressSanitizer64 :: TestCases/Linux/interception_readdir_r_test.cc<br>
>     AddressSanitizer64 :: TestCases/Linux/interception_test.cc<br>
>     AddressSanitizer64 :: TestCases/Linux/malloc_delete_mismatch.cc<br>
>     AddressSanitizer64 :: TestCases/Linux/sized_delete_test.cc<br>
>     AddressSanitizer64 :: TestCases/Linux/stack-trace-dlclose.cc<br>
>     AddressSanitizer64 :: TestCases/Linux/stress_dtls.c<br>
>     AddressSanitizer64 :: TestCases/Linux/uar_signals.cc<br>
>     AddressSanitizer64 :: TestCases/Posix/asan-symbolize-sanity-test.cc<br>
>     AddressSanitizer64 :: TestCases/Posix/asprintf.cc<br>
>     AddressSanitizer64 :: TestCases/Posix/assign_large_valloc_to_global.cc<br>
>     AddressSanitizer64 :: TestCases/Posix/glob.cc<br>
>     AddressSanitizer64 :: TestCases/Posix/init-order-dlopen.cc<br>
>     AddressSanitizer64 :: TestCases/Posix/large_allocator_unpoisons_on_free.cc<br>
>     AddressSanitizer64 :: TestCases/Posix/new_array_cookie_test.cc<br>
>     AddressSanitizer64 :: TestCases/Posix/new_array_cookie_uaf_test.cc<br>
>     AddressSanitizer64 ::<br>
> TestCases/Posix/new_array_cookie_with_new_from_class.cc<br>
>     AddressSanitizer64 :: TestCases/Posix/shared-lib-test.cc<br>
>     AddressSanitizer64 :: TestCases/Posix/start-deactivated.cc<br>
>     AddressSanitizer64 :: TestCases/Posix/tsd_dtor_leak.cc<br>
>     AddressSanitizer64 :: TestCases/allocator_returns_null.cc<br>
>     AddressSanitizer64 :: TestCases/asan_and_llvm_coverage_test.cc<br>
>     AddressSanitizer64 :: TestCases/atexit_stats.cc<br>
>     AddressSanitizer64 :: TestCases/contiguous_container.cc<br>
>     AddressSanitizer64 :: TestCases/current_allocated_bytes.cc<br>
>     AddressSanitizer64 :: TestCases/debug_locate.cc<br>
>     AddressSanitizer64 :: TestCases/debug_report.cc<br>
>     AddressSanitizer64 :: TestCases/debug_stacks.cc<br>
>     AddressSanitizer64 :: TestCases/deep_stack_uaf.cc<br>
>     AddressSanitizer64 :: TestCases/deep_thread_stack.cc<br>
>     AddressSanitizer64 :: TestCases/describe_address.cc<br>
>     AddressSanitizer64 :: TestCases/double-free.cc<br>
>     AddressSanitizer64 :: TestCases/free_hook_realloc.cc<br>
>     AddressSanitizer64 :: TestCases/frexp_interceptor.cc<br>
>     AddressSanitizer64 :: TestCases/gc-test.cc<br>
>     AddressSanitizer64 :: TestCases/heap-overflow-large.cc<br>
>     AddressSanitizer64 :: TestCases/heap-overflow.cc<br>
>     AddressSanitizer64 :: TestCases/huge_negative_hea_oob.cc<br>
>     AddressSanitizer64 :: TestCases/init-order-pthread-create.cc<br>
>     AddressSanitizer64 :: TestCases/inline.cc<br>
>     AddressSanitizer64 :: TestCases/interception_failure_test.cc<br>
>     AddressSanitizer64 :: TestCases/intra-object-overflow.cc<br>
>     AddressSanitizer64 :: TestCases/invalid-free.cc<br>
>     AddressSanitizer64 :: TestCases/large_func_test.cc<br>
>     AddressSanitizer64 :: TestCases/log-path_test.cc<br>
>     AddressSanitizer64 :: TestCases/lsan_annotations.cc<br>
>     AddressSanitizer64 :: TestCases/malloc_context_size.cc<br>
>     AddressSanitizer64 :: TestCases/malloc_fill.cc<br>
>     AddressSanitizer64 :: TestCases/max_redzone.cc<br>
>     AddressSanitizer64 :: TestCases/memset_test.cc<br>
>     AddressSanitizer64 :: TestCases/on_error_callback.cc<br>
>     AddressSanitizer64 :: TestCases/partial_right.cc<br>
>     AddressSanitizer64 :: TestCases/poison_partial.cc<br>
>     AddressSanitizer64 :: TestCases/print_summary.cc<br>
>     AddressSanitizer64 :: TestCases/printf-2.c<br>
>     AddressSanitizer64 :: TestCases/sanity_check_pure_c.c<br>
>     AddressSanitizer64 :: TestCases/stack-overflow.cc<br>
>     AddressSanitizer64 :: TestCases/stack-use-after-return.cc<br>
>     AddressSanitizer64 :: TestCases/strdup_oob_test.cc<br>
>     AddressSanitizer64 :: TestCases/strip_path_prefix.c<br>
>     AddressSanitizer64 :: TestCases/suppressions-function.cc<br>
>     AddressSanitizer64 :: TestCases/suppressions-interceptor.cc<br>
>     AddressSanitizer64 :: TestCases/suppressions-library.cc<br>
>     AddressSanitizer64 :: TestCases/throw_call_test.cc<br>
>     AddressSanitizer64 :: TestCases/throw_catch.cc<br>
>     AddressSanitizer64 :: TestCases/throw_invoke_test.cc<br>
>     AddressSanitizer64 :: TestCases/time_interceptor.cc<br>
>     AddressSanitizer64 :: TestCases/uar_and_exceptions.cc<br>
>     AddressSanitizer64 :: TestCases/unaligned_loads_and_stores.cc<br>
>     AddressSanitizer64 :: TestCases/use-after-delete.cc<br>
>     AddressSanitizer64 :: TestCases/use-after-free-right.cc<br>
>     AddressSanitizer64 :: TestCases/use-after-free.cc<br>
>     AddressSanitizer64 :: TestCases/use-after-poison.cc<br>
><br>
>   Expected Passes    : 63<br>
>   Expected Failures  : 6<br>
>   Unsupported Tests  : 107<br>
>   Unexpected Failures: 80<br>
><br>
> Many (all?) of the failing tests print this:<br>
><br>
> ==58738==AddressSanitizer CHECK failed:<br>
> /home/foad/llvm-project/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_atomic_clang_other.h:28<br>
> "((mo & (memory_order_relaxed | memory_order_consume |<br>
> memory_order_acquire | memory_order_seq_cst))) != (0)" (0x0, 0x0)<br>
><br>
> Here's a call stack at the point of failure.<br>
><br>
> (gdb) bt<br>
> #0  __sanitizer::CheckFailed (<br>
>     file=0x100f8c88<br>
> "/home/foad/llvm-project/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_atomic_clang_other.h",<br>
> line=28,<br>
>     cond=0x100f96e8 "((mo & (memory_order_relaxed |<br>
> memory_order_consume | memory_order_acquire | memory_order_seq_cst)))<br>
> != (0)", v1=0, v2=0)<br>
>     at /home/foad/llvm-project/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_common.cc:123<br>
> #1  0x0000000010024b90 in atomic_load<__sanitizer::atomic_uint8_t> (<br>
>     mo=__sanitizer::memory_order_release,<br>
>     a=0x1034a249 <__asan::instance+2097793>)<br>
>     at /home/foad/llvm-project/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_atomic_clang_other.h:27<br>
> #2  RssLimitIsExceeded (this=0x10149fc8 <__asan::instance>)<br>
>     at /home/foad/llvm-project/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_allocator.h:1321<br>
> #3  Allocate (check_rss_limit=true, cleared=false, alignment=8,<br>
>     size=<optimized out>, cache=<optimized out>,<br>
>     this=0x10149fc8 <__asan::instance>)<br>
>     at /home/foad/llvm-project/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_allocator.h:1288<br>
> #4  __asan::Allocator::Allocate (this=0x10149fc8 <__asan::instance>,<br>
>     size=<optimized out>, alignment=<optimized out>, stack=0x3fffffffdfe0,<br>
>     alloc_type=<optimized out>, can_fill=<optimized out>)<br>
>     at /home/foad/llvm-project/llvm/projects/compiler-rt/lib/asan/asan_allocator.cc:368<br>
> #5  0x00000000100f6208 in operator new (size=154)<br>
>     at /home/foad/llvm-project/llvm/projects/compiler-rt/lib/asan/asan_new_delete.cc:62<br>
> #6  0x00003fffb7ebbf34 in .std::string::_Rep::_S_create(unsigned long,<br>
> unsigned long, std::allocator<char> const&) () from<br>
> /lib64/libstdc++.so.6<br>
> #7  0x00003fffb7ebed10 in .char* std::string::_S_construct<char<br>
> const*>(char const*, char const*, std::allocator<char> const&,<br>
> std::forward_iterator_tag) ()<br>
>    from /lib64/libstdc++.so.6<br>
> #8  0x00003fffb7ebf4e8 in .std::basic_string<char,<br>
> std::char_traits<char>, std::allocator<char> >::basic_string(char<br>
> const*, std::allocator<char> const&) ()<br>
>    from /lib64/libstdc++.so.6<br>
> #9  0x00000000100f76ec in .main ()<br>
>     at /home/foad/llvm-project/llvm/projects/compiler-rt/test/asan/TestCases/Posix/asan-symbolize-sanity-test.cc:25<br>
><br>
> Thanks,<br>
> Jay.<br>
><br>
> On 6 January 2015 at 23:53, Kostya Serebryany <<a href="mailto:kcc@google.com">kcc@google.com</a>> wrote:<br>
>> Author: kcc<br>
>> Date: Tue Jan  6 17:53:32 2015<br>
>> New Revision: 225323<br>
>><br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=225323&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=225323&view=rev</a><br>
>> Log:<br>
>> [asan] add a flag soft_rss_limit_mb<br>
>><br>
>> Added:<br>
>>     compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cc<br>
>> Modified:<br>
>>     compiler-rt/trunk/lib/asan/asan_allocator.cc<br>
>>     compiler-rt/trunk/lib/asan/asan_allocator.h<br>
>>     compiler-rt/trunk/lib/asan/asan_rtl.cc<br>
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h<br>
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h<br>
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc<br>
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc<br>
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h<br>
>><br>
>> Modified: compiler-rt/trunk/lib/asan/asan_allocator.cc<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator.cc?rev=225323&r1=225322&r2=225323&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator.cc?rev=225323&r1=225322&r2=225323&view=diff</a><br>
>> ==============================================================================<br>
>> --- compiler-rt/trunk/lib/asan/asan_allocator.cc (original)<br>
>> +++ compiler-rt/trunk/lib/asan/asan_allocator.cc Tue Jan  6 17:53:32 2015<br>
>> @@ -361,15 +361,21 @@ struct Allocator {<br>
>><br>
>>      AsanThread *t = GetCurrentThread();<br>
>>      void *allocated;<br>
>> +    bool check_rss_limit = true;<br>
>>      if (t) {<br>
>>        AllocatorCache *cache = GetAllocatorCache(&t->malloc_storage());<br>
>> -      allocated = allocator.Allocate(cache, needed_size, 8, false);<br>
>> +      allocated =<br>
>> +          allocator.Allocate(cache, needed_size, 8, false, check_rss_limit);<br>
>>      } else {<br>
>>        SpinMutexLock l(&fallback_mutex);<br>
>>        AllocatorCache *cache = &fallback_allocator_cache;<br>
>> -      allocated = allocator.Allocate(cache, needed_size, 8, false);<br>
>> +      allocated =<br>
>> +          allocator.Allocate(cache, needed_size, 8, false, check_rss_limit);<br>
>>      }<br>
>><br>
>> +    if (!allocated)<br>
>> +      return allocator.ReturnNullOrDie();<br>
>> +<br>
>>      if (*(u8 *)MEM_TO_SHADOW((uptr)allocated) == 0 && CanPoisonMemory()) {<br>
>>        // Heap poisoning is enabled, but the allocator provides an unpoisoned<br>
>>        // chunk. This is possible if CanPoisonMemory() was false for some<br>
>> @@ -771,6 +777,10 @@ void asan_mz_force_unlock() {<br>
>>    instance.ForceUnlock();<br>
>>  }<br>
>><br>
>> +void AsanSoftRssLimitExceededCallback(bool exceeded) {<br>
>> +  instance.allocator.SetRssLimitIsExceeded(exceeded);<br>
>> +}<br>
>> +<br>
>>  }  // namespace __asan<br>
>><br>
>>  // --- Implementation of LSan-specific functions --- {{{1<br>
>><br>
>> Modified: compiler-rt/trunk/lib/asan/asan_allocator.h<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator.h?rev=225323&r1=225322&r2=225323&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator.h?rev=225323&r1=225322&r2=225323&view=diff</a><br>
>> ==============================================================================<br>
>> --- compiler-rt/trunk/lib/asan/asan_allocator.h (original)<br>
>> +++ compiler-rt/trunk/lib/asan/asan_allocator.h Tue Jan  6 17:53:32 2015<br>
>> @@ -173,6 +173,7 @@ void asan_mz_force_lock();<br>
>>  void asan_mz_force_unlock();<br>
>><br>
>>  void PrintInternalAllocatorStats();<br>
>> +void AsanSoftRssLimitExceededCallback(bool exceeded);<br>
>><br>
>>  }  // namespace __asan<br>
>>  #endif  // ASAN_ALLOCATOR_H<br>
>><br>
>> Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=225323&r1=225322&r2=225323&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=225323&r1=225322&r2=225323&view=diff</a><br>
>> ==============================================================================<br>
>> --- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)<br>
>> +++ compiler-rt/trunk/lib/asan/asan_rtl.cc Tue Jan  6 17:53:32 2015<br>
>> @@ -396,6 +396,7 @@ static void AsanInitInternal() {<br>
>>    InitializeAllocator(allocator_options);<br>
>><br>
>>    MaybeStartBackgroudThread();<br>
>> +  SetSoftRssLimitExceededCallback(AsanSoftRssLimitExceededCallback);<br>
>><br>
>>    // On Linux AsanThread::ThreadStart() calls malloc() that's why asan_inited<br>
>>    // should be set to 1 prior to initializing the threads.<br>
>><br>
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h?rev=225323&r1=225322&r2=225323&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h?rev=225323&r1=225322&r2=225323&view=diff</a><br>
>> ==============================================================================<br>
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h (original)<br>
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h Tue Jan  6 17:53:32 2015<br>
>> @@ -1279,12 +1279,14 @@ class CombinedAllocator {<br>
>>    }<br>
>><br>
>>    void *Allocate(AllocatorCache *cache, uptr size, uptr alignment,<br>
>> -                 bool cleared = false) {<br>
>> +                 bool cleared = false, bool check_rss_limit = false) {<br>
>>      // Returning 0 on malloc(0) may break a lot of code.<br>
>>      if (size == 0)<br>
>>        size = 1;<br>
>>      if (size + alignment < size)<br>
>>        return ReturnNullOrDie();<br>
>> +    if (check_rss_limit && RssLimitIsExceeded())<br>
>> +      return ReturnNullOrDie();<br>
>>      if (alignment > 8)<br>
>>        size = RoundUpTo(size, alignment);<br>
>>      void *res;<br>
>> @@ -1315,6 +1317,15 @@ class CombinedAllocator {<br>
>>      atomic_store(&may_return_null_, may_return_null, memory_order_release);<br>
>>    }<br>
>><br>
>> +  bool RssLimitIsExceeded() {<br>
>> +    return atomic_load(&rss_limit_is_exceeded_, memory_order_release);<br>
>> +  }<br>
>> +<br>
>> +  void SetRssLimitIsExceeded(bool rss_limit_is_exceeded) {<br>
>> +    atomic_store(&rss_limit_is_exceeded_, rss_limit_is_exceeded,<br>
>> +                 memory_order_release);<br>
>> +  }<br>
>> +<br>
>>    void Deallocate(AllocatorCache *cache, void *p) {<br>
>>      if (!p) return;<br>
>>      if (primary_.PointerIsMine(p))<br>
>> @@ -1428,6 +1439,7 @@ class CombinedAllocator {<br>
>>    SecondaryAllocator secondary_;<br>
>>    AllocatorGlobalStats stats_;<br>
>>    atomic_uint8_t may_return_null_;<br>
>> +  atomic_uint8_t rss_limit_is_exceeded_;<br>
>>  };<br>
>><br>
>>  // Returns true if calloc(size, n) should return 0 due to overflow in size*n.<br>
>><br>
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=225323&r1=225322&r2=225323&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=225323&r1=225322&r2=225323&view=diff</a><br>
>> ==============================================================================<br>
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)<br>
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Tue Jan  6 17:53:32 2015<br>
>> @@ -254,6 +254,12 @@ typedef void (*CheckFailedCallbackType)(<br>
>>                                         u64, u64);<br>
>>  void SetCheckFailedCallback(CheckFailedCallbackType callback);<br>
>><br>
>> +// Callback will be called if soft_rss_limit_mb is given and the limit is<br>
>> +// exceeded (exceeded==true) or if rss went down below the limit<br>
>> +// (exceeded==false).<br>
>> +// The callback should be registered once at the tool init time.<br>
>> +void SetSoftRssLimitExceededCallback(void (*Callback)(bool exceeded));<br>
>> +<br>
>>  // Functions related to signal handling.<br>
>>  typedef void (*SignalHandlerType)(int, void *, void *);<br>
>>  bool IsDeadlySignal(int signum);<br>
>><br>
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc?rev=225323&r1=225322&r2=225323&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc?rev=225323&r1=225322&r2=225323&view=diff</a><br>
>> ==============================================================================<br>
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc (original)<br>
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc Tue Jan  6 17:53:32 2015<br>
>> @@ -60,10 +60,18 @@ void ReportErrorSummary(const char *erro<br>
>>  #endif<br>
>>  }<br>
>><br>
>> +static void (*SoftRssLimitExceededCallback)(bool exceeded);<br>
>> +void SetSoftRssLimitExceededCallback(void (*Callback)(bool exceeded)) {<br>
>> +  CHECK_EQ(SoftRssLimitExceededCallback, nullptr);<br>
>> +  SoftRssLimitExceededCallback = Callback;<br>
>> +}<br>
>> +<br>
>>  void BackgroundThread(void *arg) {<br>
>>    uptr hard_rss_limit_mb = common_flags()->hard_rss_limit_mb;<br>
>> +  uptr soft_rss_limit_mb = common_flags()->soft_rss_limit_mb;<br>
>>    uptr prev_reported_rss = 0;<br>
>>    uptr prev_reported_stack_depot_size = 0;<br>
>> +  bool reached_soft_rss_limit = false;<br>
>>    while (true) {<br>
>>      SleepForMillis(100);<br>
>>      uptr current_rss_mb = GetRSS() >> 20;<br>
>> @@ -91,13 +99,28 @@ void BackgroundThread(void *arg) {<br>
>>        DumpProcessMap();<br>
>>        Die();<br>
>>      }<br>
>> +    if (soft_rss_limit_mb) {<br>
>> +      if (soft_rss_limit_mb < current_rss_mb && !reached_soft_rss_limit) {<br>
>> +        reached_soft_rss_limit = true;<br>
>> +        Report("%s: soft rss limit exhausted (%zdMb vs %zdMb)\n",<br>
>> +               SanitizerToolName, soft_rss_limit_mb, current_rss_mb);<br>
>> +        if (SoftRssLimitExceededCallback)<br>
>> +          SoftRssLimitExceededCallback(true);<br>
>> +      } else if (soft_rss_limit_mb >= current_rss_mb &&<br>
>> +                 reached_soft_rss_limit) {<br>
>> +        reached_soft_rss_limit = false;<br>
>> +        if (SoftRssLimitExceededCallback)<br>
>> +          SoftRssLimitExceededCallback(false);<br>
>> +      }<br>
>> +    }<br>
>>    }<br>
>>  }<br>
>><br>
>>  void MaybeStartBackgroudThread() {<br>
>>    if (!SANITIZER_LINUX) return;  // Need to implement/test on other platforms.<br>
>> -  // Currently, only start the background thread if hard_rss_limit_mb is given.<br>
>> -  if (!common_flags()->hard_rss_limit_mb) return;<br>
>> +  // Start the background thread if one of the rss limits is given.<br>
>> +  if (!common_flags()->hard_rss_limit_mb &&<br>
>> +      !common_flags()->soft_rss_limit_mb) return;<br>
>>    if (!real_pthread_create) return;  // Can't spawn the thread anyway.<br>
>>    internal_start_thread(BackgroundThread, nullptr);<br>
>>  }<br>
>><br>
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc?rev=225323&r1=225322&r2=225323&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc?rev=225323&r1=225322&r2=225323&view=diff</a><br>
>> ==============================================================================<br>
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc (original)<br>
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc Tue Jan  6 17:53:32 2015<br>
>> @@ -91,10 +91,19 @@ COMMON_FLAG(uptr, mmap_limit_mb, 0,<br>
>>              "Limit the amount of mmap-ed memory (excluding shadow) in Mb; "<br>
>>              "not a user-facing flag, used mosly for testing the tools")<br>
>>  COMMON_FLAG(uptr, hard_rss_limit_mb, 0,<br>
>> -            "RSS limit in Mb."<br>
>> +            "Hard RSS limit in Mb."<br>
>>              " If non-zero, a background thread is spawned at startup"<br>
>>              " which periodically reads RSS and aborts the process if the"<br>
>>              " limit is reached")<br>
>> +COMMON_FLAG(uptr, soft_rss_limit_mb, 0,<br>
>> +            "Soft RSS limit in Mb."<br>
>> +            " If non-zero, a background thread is spawned at startup"<br>
>> +            " which periodically reads RSS. If the limit is reached"<br>
>> +            " all subsequent malloc/new calls will fail or return NULL"<br>
>> +            " (depending on the value of allocator_may_return_null)"<br>
>> +            " until the RSS goes below the soft limit."<br>
>> +            " This limit does not affect memory allocations other than"<br>
>> +            " malloc/new.")<br>
>>  COMMON_FLAG(<br>
>>      bool, coverage, false,<br>
>>      "If set, coverage information will be dumped at program shutdown (if the "<br>
>><br>
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h?rev=225323&r1=225322&r2=225323&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h?rev=225323&r1=225322&r2=225323&view=diff</a><br>
>> ==============================================================================<br>
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h (original)<br>
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h Tue Jan  6 17:53:32 2015<br>
>> @@ -134,6 +134,7 @@ class QuarantineCache {<br>
>>        size += sizeof(QuarantineBatch);  // Count the batch in Quarantine size.<br>
>>      }<br>
>>      QuarantineBatch *b = list_.back();<br>
>> +    CHECK(b);<br>
>>      b->batch[b->count++] = ptr;<br>
>>      b->size += size;<br>
>>      SizeAdd(size);<br>
>> @@ -172,6 +173,7 @@ class QuarantineCache {<br>
>><br>
>>    NOINLINE QuarantineBatch* AllocBatch(Callback cb) {<br>
>>      QuarantineBatch *b = (QuarantineBatch *)cb.Allocate(sizeof(*b));<br>
>> +    CHECK(b);<br>
>>      b->count = 0;<br>
>>      b->size = 0;<br>
>>      list_.push_back(b);<br>
>><br>
>> Added: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cc<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cc?rev=225323&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cc?rev=225323&view=auto</a><br>
>> ==============================================================================<br>
>> --- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cc (added)<br>
>> +++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cc Tue Jan  6 17:53:32 2015<br>
>> @@ -0,0 +1,62 @@<br>
>> +// Check soft_rss_limit_mb. Not all sanitizers implement it yet.<br>
>> +// RUN: %clangxx -O2 %s -o %t<br>
>> +//<br>
>> +// Run with limit should fail:<br>
>> +// RUN: %tool_options=soft_rss_limit_mb=400:quarantine_size=1:allocator_may_return_null=1     %run %t 2>&1 | FileCheck %s -check-prefix=CHECK_MAY_RETURN_1<br>
>> +// RUN: %tool_options=soft_rss_limit_mb=400:quarantine_size=1:allocator_may_return_null=0 not %run %t 2>&1 | FileCheck %s -check-prefix=CHECK_MAY_RETURN_0<br>
>> +<br>
>> +// FIXME: make it work for other sanitizers.<br>
>> +// XFAIL: lsan<br>
>> +// XFAIL: tsan<br>
>> +// XFAIL: msan<br>
>> +#include <stdlib.h><br>
>> +#include <stdio.h><br>
>> +#include <string.h><br>
>> +#include <unistd.h><br>
>> +<br>
>> +static const int kMaxNumAllocs = 1 << 10;<br>
>> +static const int kAllocSize = 1 << 20;  // Large enough to go vi mmap.<br>
>> +<br>
>> +static char *allocs[kMaxNumAllocs];<br>
>> +<br>
>> +int main() {<br>
>> +  int num_allocs = kMaxNumAllocs / 4;<br>
>> +  for (int i = 0; i < 3; i++, num_allocs *= 2) {<br>
>> +    fprintf(stderr, "[%d] allocating %d times\n", i, num_allocs);<br>
>> +    int zero_results = 0;<br>
>> +    for (int j = 0; j < num_allocs; j++) {<br>
>> +      if ((j % (num_allocs / 4)) == 0) {<br>
>> +        usleep(100000);<br>
>> +        fprintf(stderr, "  [%d]\n", j);<br>
>> +      }<br>
>> +      allocs[j] = (char*)malloc(kAllocSize);<br>
>> +      if (allocs[j])<br>
>> +        memset(allocs[j], -1, kAllocSize);<br>
>> +      else<br>
>> +        zero_results++;<br>
>> +    }<br>
>> +    if (zero_results)<br>
>> +      fprintf(stderr, "Some of the malloc calls returned null: %d\n",<br>
>> +              zero_results);<br>
>> +    if (zero_results != num_allocs)<br>
>> +      fprintf(stderr, "Some of the malloc calls returned non-null: %d\n",<br>
>> +              num_allocs - zero_results);<br>
>> +    for (int j = 0; j < num_allocs; j++) {<br>
>> +      free(allocs[j]);<br>
>> +    }<br>
>> +  }<br>
>> +}<br>
>> +<br>
>> +// CHECK_MAY_RETURN_1: allocating 256 times<br>
>> +// CHECK_MAY_RETURN_1: Some of the malloc calls returned non-null: 256<br>
>> +// CHECK_MAY_RETURN_1: allocating 512 times<br>
>> +// CHECK_MAY_RETURN_1: Some of the malloc calls returned null:<br>
>> +// CHECK_MAY_RETURN_1: Some of the malloc calls returned non-null:<br>
>> +// CHECK_MAY_RETURN_1: allocating 1024 times<br>
>> +// CHECK_MAY_RETURN_1: Some of the malloc calls returned null:<br>
>> +// CHECK_MAY_RETURN_1: Some of the malloc calls returned non-null:<br>
>> +<br>
>> +// CHECK_MAY_RETURN_0: allocating 256 times<br>
>> +// CHECK_MAY_RETURN_0: Some of the malloc calls returned non-null: 256<br>
>> +// CHECK_MAY_RETURN_0: allocating 512 times<br>
>> +// CHECK_MAY_RETURN_0: allocator is terminating the process instead of returning<br>
>><br>
>><br>
>> _______________________________________________<br>
>> llvm-commits mailing list<br>
>> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div>