Good day! I have a fork-on-connect daemon. After profiling it with perf tool, I found out that function "do_lookup_x" consume lot's of CPU time. All the function calls for shared-libraries functions are after fork.
Is there any way to lookup all symbols before fork?
Best How To :
Setting the environment variable
LD_BIND_NOW should help achieving just that.
Set it with
then execute your program.
ELF platforms (Linux, Solaris, FreeBSD, HP-UX, IRIX, etc.) support lazy binding of procedure addresses, which is an optimization that yields better performance overall but a genuine problem for applications that need uniform performance after startup (eg: trading systems.) When an ELF application starts up, the loader (by default) initializes the Procedure Linkage Table (PLT) with a bunch of fix-up code that'll be run on the first invocation of each function. On the fix-up call, the function's position within the virtual address space is looked up and placed into the PLT so that future invocations of the function won't need to be looked up again.
The possible solutions:
If you care about latency after startup, there's a few things you can do:
Have a "warmup phase" of your application that does a dlsym() lookup on every function;
Use static libraries instead of shared libraries;
Set LD_BIND_NOW=1 and force the loader to do the PLT fixups at startup;
Use the "-z now" option on your linker (if you have it available).
Please see here for the full article and here for further info.