Address sanitizer use a lot of memory

ownssh ownsshaim@aol.com
Sat Apr 12 18:32:00 GMT 2014


I did more research and I found this is because address sanitizer use 
mmap to allocate the fake stack.
First address sanitizer will get the fake stack size from RLIMIT_STACK 
in sanitizer_linux.cc:GetThreadStackTopAndBottom,
then allocate in asan_fake_stack.cc:AllocateOneSizeClass.

One way to reduce the memory usage is set a smaller RLIMIT_STACK, 
example:
sh -c "ulimit -s 32; ASAN_OPTIONS=verbosity=1 ./a.out"
But the better solusion maybe reduce the real memory usage from mmap.

Also this issue are exist in clang 3.4 because it take same approach.
I will continue post if I found anything more.

regard.

On 11 April 2014 20:03, ownssh wrote:
> Address sanitizer use a lot of memory with pthread of this code:
> ---
> #include <vector>
> #include <iostream>
> #include <chrono>
> #include <thread>
> using namespace std;
>
> void thread_main(int thread_id) {
> 	cout << thread_id << endl;
> 	this_thread::sleep_for(chrono::milliseconds(5000));
> }
>
> int main() {
> 	vector<shared_ptr<thread>> thread_list;
> 	for (int i=0; i<200; i++) {
> 		thread_list.push_back(make_shared<thread>(thread_main, i));
> 	}
> 	for (auto t: thread_list) {
> 		t->join();
> 	}
> 	thread_list.clear();
> 	return 0;
> }
> ---
> before add -fsanitize=address it used 1.6mb, after add it used 
270.5mb.
>
> this code just simply create 200 threads, I have no idea why it will 
use so much.
>
>
> GCC version is "gcc version 4.8.2 20140120 (Red Hat 4.8.2-15) (GCC)",
> from rhel 6 devtoolset.
> Please let me known if you found anything about this, thanks.
>
> regard.

---
ownssh
ownsshaim@aol.com




More information about the Gcc-help mailing list