diff --git a/compiler-rt/lib/asan/asan_allocator.cc b/compiler-rt/lib/asan/asan_allocator.cc index 7eadec5a3bc6d148be7e34895622b6014b3093e7..3573f20cacc66f993843a03b1dcbd0cef6b52323 100644 --- a/compiler-rt/lib/asan/asan_allocator.cc +++ b/compiler-rt/lib/asan/asan_allocator.cc @@ -43,10 +43,16 @@ namespace __asan { #define REDZONE FLAG_redzone static const size_t kMinAllocSize = REDZONE * 2; -static const size_t kMinMmapSize = 4UL << 20; // 4M static const uint64_t kMaxAvailableRam = 128ULL << 30; // 128G static const size_t kMaxThreadLocalQuarantine = 1 << 20; // 1M -static const size_t kMaxSizeForThreadLocalFreeList = 1 << 17; + +#if ASAN_LOW_MEMORY==1 +static const size_t kMinMmapSize = 4UL << 17; // 128K + static const size_t kMaxSizeForThreadLocalFreeList = 1 << 15; // 32K +#else +static const size_t kMinMmapSize = 4UL << 20; // 4M + static const size_t kMaxSizeForThreadLocalFreeList = 1 << 17; // 128K +#endif // Size classes less than kMallocSizeClassStep are powers of two. // All other size classes are multiples of kMallocSizeClassStep. diff --git a/compiler-rt/lib/asan/asan_rtl.cc b/compiler-rt/lib/asan/asan_rtl.cc index 70e4383ce5290e7c75b4669b02e536338ba177a4..f0e603fa951d73b74741c58662b2c72b3fdfd150 100644 --- a/compiler-rt/lib/asan/asan_rtl.cc +++ b/compiler-rt/lib/asan/asan_rtl.cc @@ -419,7 +419,15 @@ void __asan_init() { FLAG_v = IntFlagValue(options, "verbosity=", 0); +#if ASAN_LOW_MEMORY == 1 + FLAG_quarantine_size = + IntFlagValue(options, "quarantine_size=", 1UL << 24); // 16M + FLAG_redzone = IntFlagValue(options, "redzone=", 64); +#else + FLAG_quarantine_size = + IntFlagValue(options, "quarantine_size=", 1UL << 28); // 256M FLAG_redzone = IntFlagValue(options, "redzone=", 128); +#endif CHECK(FLAG_redzone >= 32); CHECK((FLAG_redzone & (FLAG_redzone - 1)) == 0); @@ -443,9 +451,6 @@ void __asan_init() { atexit(asan_atexit); } - FLAG_quarantine_size = - IntFlagValue(options, "quarantine_size=", 1UL << 28); - // interceptors InitializeAsanInterceptors(); diff --git a/compiler-rt/lib/asan/tests/asan_test.cc b/compiler-rt/lib/asan/tests/asan_test.cc index 8bd4eb13c77100c8ecfcfd9e320ee13d52ec3fae..c59c04566ace2b1bcf251b9cc9cf9ae4aa709666 100644 --- a/compiler-rt/lib/asan/tests/asan_test.cc +++ b/compiler-rt/lib/asan/tests/asan_test.cc @@ -453,7 +453,11 @@ static void MallocStress(size_t n) { } TEST(AddressSanitizer, MallocStressTest) { +#if ASAN_LOW_MEMORY==1 + MallocStress(20000); +#else MallocStress(200000); +#endif } static void TestLargeMalloc(size_t size) { @@ -468,6 +472,7 @@ TEST(AddressSanitizer, LargeMallocTest) { } } +#if ASAN_LOW_MEMORY != 1 TEST(AddressSanitizer, HugeMallocTest) { #ifdef __APPLE__ // It was empirically found out that 1215 megabytes is the maximum amount of @@ -480,12 +485,17 @@ TEST(AddressSanitizer, HugeMallocTest) { #endif TestLargeMalloc(n_megs << 20); } +#endif TEST(AddressSanitizer, ThreadedMallocStressTest) { const int kNumThreads = 4; pthread_t t[kNumThreads]; for (int i = 0; i < kNumThreads; i++) { +#if ASAN_LOW_MEMORY==1 + pthread_create(&t[i], 0, (void* (*)(void *x))MallocStress, (void*)10000); +#else pthread_create(&t[i], 0, (void* (*)(void *x))MallocStress, (void*)100000); +#endif } for (int i = 0; i < kNumThreads; i++) { pthread_join(t[i], 0); diff --git a/compiler-rt/lib/asan/tests/asan_test_config.h b/compiler-rt/lib/asan/tests/asan_test_config.h index de4ae95bd244837cae15ca82a55570147ee2b566..6cf0e695848405c083b9b54d888219f872eb55b0 100644 --- a/compiler-rt/lib/asan/tests/asan_test_config.h +++ b/compiler-rt/lib/asan/tests/asan_test_config.h @@ -39,6 +39,10 @@ using std::map; # error "please define ASAN_NEEDS_SEGV" #endif +#ifndef ASAN_LOW_MEMORY +#define ASAN_LOW_MEMORY 0 +#endif + #define ASAN_PCRE_DOTALL "" #endif // ASAN_TEST_CONFIG_H