View previous topic :: View next topic |
Author |
Message |
s_j_newbury n00b
Joined: 05 Apr 2007 Posts: 56 Location: UK
|
Posted: Wed Dec 21, 2016 3:22 pm Post subject: Linking everything with jemalloc at build time |
|
|
I don't know if anybody else has tried this, but I've been emerging my systems lately with jemalloc linked in unconditionally, not using any LD_PRELOAD tricks.
I've achieved this through LIBS+="-Wl,-no-as-needed -ljemalloc -Wl,-as-needed" or LDFLAGS as needed. The reason for the no-as-needed/as-needed is otherwise the Gentoo system-wide default of "as-needed" results in jemalloc being dropped since glibc meets the symbol resolution requirements. Some packages had to be patched not to complain about using non-library flags in LIBS, this is a little contraversial since it's generally accepted that LIBS should only contain libraries, and LDFLAGS link flags, but the implementation of as-needed is per library, that is it applies to all following libraries on the link command line unless subsequently toggled, the only of doing this is to allow as-needed in LIBS (or add the lib to LDFLAGS).
The only real problem package is www-client/chromium which segfaults if you try this, so don't! Solution there would be to add jemalloc as a malloc option in the Chromium codebase since it already makes use of the malloc hooks internally.
World emerged this way results in a system with much better memory utililisation/performance characteristics than with the default glibc malloc. Well, that's what the Kool Aid tastes like anyway! |
|
Back to top |
|
|
kernelOfTruth Watchman
Joined: 20 Dec 2005 Posts: 6111 Location: Vienna, Austria; Germany; hello world :)
|
|
Back to top |
|
|
Gatak Apprentice
Joined: 04 Jan 2004 Posts: 174
|
Posted: Tue Nov 26, 2019 11:40 pm Post subject: |
|
|
Really nice! I've been using the LD_PRELOAD trick on things like Apache, php, etc with good effect. I'll try your method now instead
I haven't seen the use of "LIBS". What is the difference against using LDFLAGS? |
|
Back to top |
|
|
Ant P. Watchman
Joined: 18 Apr 2009 Posts: 6920
|
Posted: Wed Nov 27, 2019 5:19 am Post subject: |
|
|
Gatak wrote: | I haven't seen the use of "LIBS". What is the difference against using LDFLAGS? |
LDFLAGS and LIBS both get picked up automagically by GNU Makefile default rules, and anything that tries to be compatible. The LDFLAGS string is inserted before the source files and LIBS comes after them.
--as-needed and -l flags are actually position-sensitive, which is why this hack works. |
|
Back to top |
|
|
Gatak Apprentice
Joined: 04 Jan 2004 Posts: 174
|
Posted: Wed Nov 27, 2019 11:58 am Post subject: |
|
|
I see. Thanks. Anyone that can share some experience in using jemalloc systemwide? For now I have enabled it during compile of specific apps. Was thinking to use package.env in the future instead of force linking to jemalloc on all applications. Do all applications use malloc anyway? |
|
Back to top |
|
|
|