Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Unsupported Software
  • Search

Linking everything with jemalloc at build time

This forum covers all Gentoo-related software not officially supported by Gentoo. Ebuilds/software posted here might harm the health and stability of your system(s), and are not supported by Gentoo developers. Bugs/errors caused by ebuilds from overlays.gentoo.org are covered by this forum, too.
Post Reply
Advanced search
8 posts • Page 1 of 1
Author
Message
s_j_newbury
n00b
n00b
Posts: 58
Joined: Thu Apr 05, 2007 12:18 pm
Location: UK

Linking everything with jemalloc at build time

  • Quote

Post by s_j_newbury » Wed Dec 21, 2016 3:22 pm

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! ;-)
Top
kernelOfTruth
Watchman
Watchman
User avatar
Posts: 6111
Joined: Tue Dec 20, 2005 10:34 pm
Location: Vienna, Austria; Germany; hello world :)
Contact:
Contact kernelOfTruth
Website

  • Quote

Post by kernelOfTruth » Mon Dec 26, 2016 6:41 pm

Interesting approach !

I'm running chromium with explicitly disabled tcmalloc and ld_preload jemalloc,

so how's the performance or latency impact when running it on a system-wide basis ?
https://github.com/kernelOfTruth/ZFS-fo ... scCD-4.9.0
https://github.com/kernelOfTruth/pulsea ... zer-ladspa

Hardcore Gentoo Linux user since 2004 :D
Top
Gatak
Apprentice
Apprentice
Posts: 174
Joined: Sun Jan 04, 2004 11:00 pm

  • Quote

Post by Gatak » Tue Nov 26, 2019 11:40 pm

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?
Top
Ant P.
Watchman
Watchman
Posts: 6920
Joined: Sat Apr 18, 2009 7:18 pm
Contact:
Contact Ant P.
Website

  • Quote

Post by Ant P. » Wed Nov 27, 2019 5:19 am

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.
Top
Gatak
Apprentice
Apprentice
Posts: 174
Joined: Sun Jan 04, 2004 11:00 pm

  • Quote

Post by Gatak » Wed Nov 27, 2019 11:58 am

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?
Top
pqy330
n00b
n00b
Posts: 2
Joined: Wed Feb 28, 2018 1:11 am

  • Quote

Post by pqy330 » Fri Aug 01, 2025 6:25 am

How about adding jemalloc to the dependency list of libc.so.6 by using patchelf --add-needed?
Because almost everything depends on libc.so.6, so everything depends on libjemalloc.so. :lol:
Top
Hu
Administrator
Administrator
Posts: 24383
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Fri Aug 01, 2025 2:00 pm

This thread is very old.

I recommend against modifying libc.so.6 in this way, for multiple reasons.
  • Almost everything depends on libc.so. If you break libc.so, you will have very little use of your system until it is repaired. In particular, patchelf needs libc.so, so you cannot use patchelf to repair a broken libc.so. Restoring from a backup would be the simplest recovery path, assuming a valid backup exists.
  • libjemalloc.so probably depends on libc.so, so introducing a dependency in the other direction might cause problems. I have not verified whether this breaks.
  • jemalloc development has ceased, so if it does not work for you as-is, you may not get any upstream help.
Top
stefan11111
Veteran
Veteran
Posts: 1024
Joined: Sun Jan 29, 2023 6:08 pm
Location: Romania
Contact:
Contact stefan11111
Website

  • Quote

Post by stefan11111 » Fri Aug 01, 2025 2:18 pm

Does jemalloc replace the system malloc, it doesn't use it's own symbols?
What about tcmalloc?

I know palemoon uses jemalloc to speed up allocations. What is the impact of using a different allocator system-wide like this?
My overlay: https://github.com/stefan11111/stefan_overlay
INSTALL_MASK="/etc/systemd /lib/systemd /usr/lib/systemd /usr/lib/modules-load.d *udev* /usr/lib/tmpfiles.d *tmpfiles* /var/lib/dbus /usr/bin/gdbus /lib/udev"
Top
Post Reply

8 posts • Page 1 of 1

Return to “Unsupported Software”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy