Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect when --with-jemalloc is specified and install jemalloc #349

Open
postmodern opened this issue Jul 23, 2019 · 12 comments
Open

Detect when --with-jemalloc is specified and install jemalloc #349

postmodern opened this issue Jul 23, 2019 · 12 comments

Comments

@postmodern
Copy link
Owner

postmodern commented Jul 23, 2019

Detect when --with-jemalloc is given as an additional configuration option (ex: ruby-install ruby 2.6 -- --with-jemalloc), and automatically append the appropriate jemalloc package name (based on the $package_manager) to list of package dependencies.

@svoop
Copy link

svoop commented Dec 6, 2021

This would be very useful, even more so on newer Homebrew installs which no longer reside in /usr/local but in /opt/homebrew and therefore requires quite a bit more yada yada:

# Homebrew in /usr/local
ruby-install -s ~/.rubies_src ruby 3 -- --with-jemalloc

# Homebrew in /opt/homebrew
ruby-install -s ~/.rubies_src ruby 3 -- --with-jemalloc CPPFLAGS="-I$HOMEBREW_PREFIX/opt/jemalloc/include" LDFLAGS="-L$HOMEBREW_PREFIX/opt/jemalloc/lib"

@pjg
Copy link

pjg commented Jan 10, 2022

This would be extremely helpful. I almost gave up trying to install ruby 2.7 with jemalloc support before stumbling upon this issue with detailed guide on what needs to be set in the command line to install it properly (thanks @svoop!).

@nscott
Copy link

nscott commented Jan 18, 2023

I recently stumbled over this same issue with Ruby 3.2.0 on Ubuntu 22.04 (jammy) in a docker container.

Very similar fix to what @svoop mentioned, just obviously slightly changed for Ubuntu:

LDFLAGS="-Wl,--no-as-needed" CPPFLAGS="-I/usr/include/jemalloc" ruby-install --system ruby 3.2.0

If I didn't pass in the both LDFLAGS and CPPFLAGS, enabling jemalloc with the LD_PRELOAD environment variable would segfault every single time. Effectively I couldn't use jemalloc at all. See https://bugs.ruby-lang.org/issues/18409 for a similar bug report.

I think this is the best read to highlight what's actually going on: grpc/grpc#25450 (comment)

I'm not well-versed in the general chain/Ruby compilation/OS-library-picking workflow, just figured I'd note that it's both still a problem in 3.2.0 and very unintuitive to fix.

Is this something ruby-install should fix? Honestly, no idea, but hopefully other lost souls will be able to look at all these links and understand why jemalloc isn't working with the flag.

Here's a 'slim' version of my Dockerfile:

FROM ubuntu:jammy

RUN apt-get -y clean && apt-get update
RUN apt-get install -y --no-install-recommends apt-utils build-essential bzip2 coreutils curl git gzip libc-dev tar xz-utils \
    autoconf bison patch build-essential rustc libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev uuid-dev libjemalloc-dev

ENV MAKE_OPTS="-j 4"
ENV RUBY_CFLAGS="-O3"
ENV RUBY_CONFIGURE_OPTS="--enable-yjit --disable-install-doc --with-jemalloc"
RUN curl -s -L https://github.com/postmodern/ruby-install/archive/v0.8.5.tar.gz --output ./ruby-install-0.8.5.tar.gz
RUN tar -xzvf ./ruby-install-0.8.5.tar.gz
RUN cd ruby-install-0.8.5 && make install

RUN LDFLAGS="-Wl,--no-as-needed" CPPFLAGS="-I/usr/include/jemalloc" ruby-install --system ruby 3.2.0
RUN rm -rf ./ruby-install*

RUN apt-get -y autoremove && apt-get -y clean

@postmodern
Copy link
Owner Author

How would people feel about an explicit --enable jemalloc or --feature jemalloc option?

ruby-install --enable jemalloc ruby
ruby-install --feature jemalloc ruby

Or do people prefer that ruby-install auto-detect when you specify --with-jemalloc as an additional configuration option?

ruby-install ruby -- --with-jemalloc

@svoop

This comment was marked as outdated.

@nscott
Copy link

nscott commented Jan 19, 2023

@postmodern I think I disagree with @svoop here, as long as --feature jemalloc is well documented in the README (or where ever you want to put documentation). I don't like shadowing build flags, so --with-jemalloc feels like it should be left alone.

@postmodern postmodern self-assigned this Jan 19, 2023
@nscott
Copy link

nscott commented Jan 19, 2023

I'm also scratching my head even more since all of the Ruby patches and comments seem to indicate this should be fixed in 3.1+.. like I mentioned above, I'm not even sure if this is a ruby-install issue or if this is a fundamental Ruby compilation problem.

Let me know if you need any of my build logs to look at configuration options, linker args, etc @postmodern

@svoop
Copy link

svoop commented Jan 13, 2024

January is Ruby upping month, so I revisit this issue. With some time gone by, I now second @nscott, --feature jemalloc would be a great extension to ruby-install. Happy new year! 😉

@monfresh

This comment was marked as spam.

@postmodern
Copy link
Owner Author

@monfresh you don't seem to be previously involved in this conversation. Please refrain from using ruby-install issues to advertise Ruby on Mac, as this isn't the appropriate place for advertising. Thanks.

@monfresh
Copy link

Sorry about that! It won't happen again.

@airblade
Copy link

I presume this is about compiling jemalloc into Ruby rather than using it at runtime via an LD_PRELOAD flag?

If so, I have no opinion on how to tell ruby-install "yes please, I would like jemalloc". But it would be great to have!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants