[LLVMdev] [RFC] [PATCH] Fix for sys::Process::GetMallocUsage() when using ptmalloc2 allocator in glibc

Dan Liew dan at su-root.co.uk
Mon Apr 28 15:40:25 PDT 2014


Thanks for the reply.

On 28 April 2014 20:01, Reid Kleckner <rnk at google.com> wrote:
> 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.

I'm not sure we can always assume libc is a dynamic library. A user
can statically link to libc if they really want to. For the static
case something like libbfd could help provided the symbol table was
still around.

It seems to me whatever we do is going to incur some overhead. Calling
dlsym() sounds a little bit expensive so we might be best off doing
the test on the first call to sys::Process::GetMallocUsage() and
storing a static variable that indicates the result of the test so we
don't need to do it again on subsequent calls to GetMallocUsage().
This would mean if an application decided to change its allocator
during execution GetMallocUsage() might break but changing the
allocator during execution sounds insane anyway, so hopefully no one
does that.

-- 
Dan Liew
PhD Student - Imperial College London



More information about the llvm-dev mailing list