Unable to preload libumem to replace libc malloc #9
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I'm trying to use
LD_PRELOAD
withlibumem
to replace thelibc malloc()
. I'm seeing it get loaded but with perf top I'm not seeing malloc from libc being used when I performance profile.I'm benchmarking using Haywire
I thought perhaps I needed to load
libumem_malloc.so
but if I try the followingcalloc()
is running over and over even before I run any kind of benchmark against the service and the service never starts correctly.I've replicated your issue by doing exactly what you did (and what anyone would do, it's in the INSTALL directions after all!) and discovered that changing one step in your process fixes the issue, why I don't know as yet (but I have some guesses I'm looking into). Configuring with the
CFLAGS
set to-O0
or-Og
eliminates the issue (I've been testing withgcc version 6.2.0 20160901 (Ubuntu 6.2.0-3ubuntu11~16.04)
).$ ./configure CFLAGS="-g -Og -march=native -mtune=native"
A simple "hello, world!" application with a single call to malloc 1KB of memory on entry to main() was used to test this.
So, somewhere GCC is optimizing (reordering, eliminating or whatever) some critical section of the code. Feel free to test Haywire with umem built without optimizations while I continue to look for the root cause.
Yup I think that's working now. Performance is terrible but we did turn off optimizations :)
Any profiling data that pointed at hotspots in umem would be helpful to me, if you have the time to collect the data.
-O0 trick doesn't work with clang compiler :(
What I discovered is: when app starts, there is a call to calloc (from a thread creation, before main). Then, calloc calls umem_alloc, which in turn calls umem_cache_alloc, which creates a thread, which calls calloc... Indefinite loop and app crashes with a stack overflow...
So we need to link our app with pthread compiled against non-umem calloc somehow. Any thoughts?
I stumbled across the issue with getting stuck in calloc. A recent gcc converts the call to malloc+memset into a call to calloc, which makes calloc recurse into itself. I renamed
malloc
intomalloc_rpl
and then called that incalloc
and added added amalloc
that forwards tomalloc_rpl
and that seems to work around the issue.just try
-fno-builtin-calloc
to prevent gcc optimize malloc+memset as callocfixed
e1eb2c8413