gopalshankar / address-sanitizer

Automatically exported from code.google.com/p/address-sanitizer
0 stars 0 forks source link

Shadow memory has big footprint of large virtual memory. #292

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Like wiki said, shadow memory will use 1bit to map 8bit of the application 
memory,
and we known, malloc only allocate the virtual memory,
real memory wont use until we actual write something.

example:
char* a = (char*)malloc(104857600);
for (int i=0; i < 1048576; i++) {
  a[i] = 0;
}
If I know exactly, this code will use 100mb of virtual memory and 1.1mb of real 
memory.
Now I build this code with with address sanitizer, it used 15.1mb of real 
memory.
I keep changing the number in malloc and confirmed real memory increase rate is 
0.125.
I'm pretty sure memory increasingly have been used to shadow memory,
but I havn't look into code yet.

This footprint also exist with stack, if the max stack size of per thread is 
10mb,
then the footprint of per thread is 1.25mb.

Is this problem resolvable?
E.g keep shadow memory dirty or use other approach.
It maybe very hard or impossible.

Original issue reported on code.google.com by ripn...@gmail.com on 13 Apr 2014 at 5:12

GoogleCodeExporter commented 9 years ago
What version of asan are you using? 
I thought this should be fixed by 
http://llvm.org/viewvc/llvm-project?rev=201400&view=rev

Original comment by konstant...@gmail.com on 13 Apr 2014 at 7:28

GoogleCodeExporter commented 9 years ago
> This footprint also exist with stack,
> if the max stack size of per thread is 10mb,
> then the footprint of per thread is 1.25mb.

This may be thread context created by ASan (it's ~2.5mb on i686). Kernel 
sometimes merges it into memory region that was used for thread stack (because 
attributes are compatible).

Original comment by tetra2...@gmail.com on 13 Apr 2014 at 1:35

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
You can close it now. (I can't found where to)

Original comment by ripn...@gmail.com on 13 Apr 2014 at 3:44

GoogleCodeExporter commented 9 years ago
Oh, sorry for didn't read more before post here.
I'm using clang 3.4, and just build 3.5 from svn.
I can confirm this issue is already gone.
With clang and llvm 3.5 the footprint of per thread is about 0.08m (on x86),
what ever the max stack size I set.

Original comment by ripn...@gmail.com on 13 Apr 2014 at 3:48

GoogleCodeExporter commented 9 years ago

Original comment by konstant...@gmail.com on 13 Apr 2014 at 4:30