ruby-install icon indicating copy to clipboard operation
ruby-install copied to clipboard

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

Open postmodern opened this issue 4 years ago • 12 comments

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.

postmodern avatar Jul 23 '19 22:07 postmodern

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"

svoop avatar Dec 06 '21 17:12 svoop

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!).

pjg avatar Jan 10 '22 14:01 pjg

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: https://github.com/grpc/grpc/issues/25450#issuecomment-910806034

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

nscott avatar Jan 18 '23 20:01 nscott

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

postmodern avatar Jan 19 '23 02:01 postmodern

@postmodern I'd prefer the latter I guess: There might be other features in the future which require dependencies as well, the same detection could be used then without the need to touch the ruby-install CLI.

svoop avatar Jan 19 '23 08:01 svoop

@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.

nscott avatar Jan 19 '23 09:01 nscott

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

nscott avatar Jan 19 '23 09:01 nscott

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! :wink:

svoop avatar Jan 13 '24 15:01 svoop

For the Mac users who are impatient and want to be able to use this feature today, I built a paid product called Ruby on Mac that does this for you. You would run it like this:

rom install ruby 3.1.4 --with-jemalloc

What's neat about Ruby on Mac, the Ultimate version specifically, is that it supports all the popular version managers, and you can easily switch from one to another. For example: rom config set manager chruby. It also supports Ruby versions as old as 1.9.3.

Happy New Year!

monfresh avatar Jan 13 '24 15:01 monfresh

@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.

postmodern avatar Jan 13 '24 22:01 postmodern

Sorry about that! It won't happen again.

monfresh avatar Jan 14 '24 02:01 monfresh

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!

airblade avatar Jan 14 '24 13:01 airblade