<div dir="ltr">The problem with tcmalloc seems like a real problem.  I can't think of any good workarounds.  My best worst idea is to try to figure out if malloc is coming from libc with dlsym and dlopen, and then use that to decide whether we add these two numbers together.</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Apr 22, 2014 at 6:34 AM, Dan Liew <span dir="ltr"><<a href="mailto:dan@su-root.co.uk" target="_blank">dan@su-root.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
This is a proposed fix for bug 16847 [1]. It is essentially the patch<br>
provided by Martin Nowack in the bug report but I have added a test<br>
case and an ifdef macro around the modified code in<br>
Process::GetMallocUsage()<br>
<br>
The issue seems to be that the ptmalloc2 allocator used in glibc (in<br>
my case 2.19) does not include mmap()'ed memory in mallinfo.uordblks<br>
and so mallinfo.hblkhd needs to be added to the value that<br>
Process::GetMallocUsage() will return.<br>
<br>
Another easy way to see this issue (other than running the unit test)<br>
is to build and run the attached "malloc-test.c" program on a system<br>
that uses glibc. You will see that after malloc'ing 256MiB of memory<br>
uordblks is still zero but hblkhd has increased.<br>
<br>
This is an RFC because I'm not very happy with my use of...<br>
<br>
#if defined(__GLIBC__)<br>
<br>
This will work in the common case where glibc is being used with its<br>
standard allocator. However it will completely fail in the case where<br>
LLVM is being used as a library and a developer chooses to use a<br>
different allocator. For example if tcmalloc [2] is used then the<br>
calculation is wrong[3] because mallinfo.uordblks includes mmap()'ed<br>
memory and so we would count mmap()'ed memory twice!<br>
<br>
Thoughts?<br>
<br>
[1] <a href="http://llvm.org/bugs/show_bug.cgi?id=16847" target="_blank">http://llvm.org/bugs/show_bug.cgi?id=16847</a><br>
[2] <a href="http://goog-perftools.sourceforge.net/doc/tcmalloc.html" target="_blank">http://goog-perftools.sourceforge.net/doc/tcmalloc.html</a><br>
[3] <a href="https://github.com/klee/klee/pull/116" target="_blank">https://github.com/klee/klee/pull/116</a><br>
<br>
Thanks,<br>
<span class="HOEnZb"><font color="#888888">--<br>
Dan Liew<br>
PhD Student - Imperial College London<br>
</font></span><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>