Last Updated
Viewed 11 Times
     

I've built and installed rub 2.6.5 from source with jemalloc. However when I check to see if its there I'm not seeing an entry. Is there something else I should have been doing?

ubuntu:~$ uname -a
Linux ip-10-0-3-198 4.15.0-1032-aws #34-Ubuntu SMP Thu Jan 17 15:18:09 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
ubuntu:~$ ./configure --enable-shared --with-jemalloc
ubuntu:~$ make
ubuntu:~$ make install

Which results in:

ubuntu:~$ ruby -r rbconfig -e "puts RbConfig::CONFIG['LIBS']"
-lm 

Tracking memory usage once deployed I'm also not seeing a drop compared to similarly configured servers without jemalloc in place.

I'm not sure what I need to be doing in order to get jemalloc working.

Thanks!

I am on ubuntu 12.04.5 LTS and tried installing ruby with jemalloc. The jemalloc got installed successfully(https://blog.scalingo.com/2017/05/02/improve-ruby-application-memory-jemalloc.html) but while installing the ruby 2.3.4, it gave this following error.

>rvm install 2.3.4 -C --with-jemalloc

Warning, new version of rvm available '1.29.1', you are using older version '1.27.0'.
You can disable this warning with:    echo rvm_autoupdate_flag=0 >> ~/.rvmrc
You can enable  auto-update  with:    echo rvm_autoupdate_flag=2 >> ~/.rvmrc
ruby-2.3.4 - #removing src/ruby-2.3.4..
Checking requirements for ubuntu.
Requirements installation successful.
Installing Ruby from source to: /home/deploy/.rvm/rubies/ruby-2.3.4, this may take a while depending on your cpu(s)...
ruby-2.3.4 - #downloading ruby-2.3.4, this may take a while depending on your connection...
ruby-2.3.4 - #extracting ruby-2.3.4 to /home/deploy/.rvm/src/ruby-2.3.4....
ruby-2.3.4 - #configuring...........................................................
ruby-2.3.4 - #post-configuration..
ruby-2.3.4 - #compiling.....
Error running '__rvm_make -j2',
showing last 15 lines of /home/deploy/.rvm/log/1494486344_ruby-2.3.4/make.log
compiling enumerator.c
compiling error.c
compiling eval.c
eval.c: In function 'rb_raise_jump':
eval.c:763:8: warning: unused variable 'mid' [-Wunused-variable]
compiling load.c
compiling proc.c
compiling file.c
compiling gc.c
In file included from gc.c:50:0:
/usr/include/malloc.h:152:15: error: conflicting types for 'malloc_usable_size'
/usr/include/jemalloc/jemalloc.h:45:8: note: previous declaration of 'malloc_usable_size' was here
make: *** [gc.o] Error 1
make: *** Waiting for unfinished jobs....
++ return 2
There has been an error while running make. Halting the installation.

Has anyone encountered it before or may have the experience with it, please help.

This command should show -ljemalloc but it is not. I could see it with ruby-2.4.3 and ruby-2.5.x but not with ruby-2.6.x

$ ruby -r rbconfig -e "puts RbConfig::CONFIG['LIBS']"
-lm                                                                                                                                    
$ cat /etc/environment


PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.1

I am using ubuntu 18 LTS and with other ruby version , I am getting the jemalloc file library as mention above

So, I've got a memory leak in my Sidekiq worker. I have a worker server with one queue for this worker task only, that gets to about 10G RSS in a week.

I tried to reproduce it locally with only 1 worker thread and voila - I get from 200M to 1G in one night, processing 1 task/min. Naturally, I want to know what's leaking, so I'm also logging RSS, heap_live_slots and heap_free_slots. When I plot results I can see steady RSS growth while live and free slots fluctuate randomly but in well defined and constant boundaries, while their sum remains constant.

At this point I come to the conclusion that the leak likely occurs not in Ruby code, but rather in some native extension. So I reinstall ruby with Jemalloc support via RVM: rvm reinstall 2.4.2 --with-jemalloc

Then I set up MALLOC_CONF:

export MALLOC_CONF='prof_leak:true,lg_prof_sample:0,prof_final:true,stats_print:true'

And fire up Sidekiq. Freshly started Sidekiq with 1 worker thread is worth about 200M RSS, but when I press Ctrl+C and look at stats output of jemalloc I see something completely different:

Arenas: 32
Quantum size: 16
Page size: 4096
Maximum thread-cached size class: 32768
Allocated: 34056, active: 61440, metadata: 2949272, resident: 2981888, mapped: 6352896, retained: 2035712

What? 6M mapped? This cannot be true. So I start irb and do the following:

2.4.2 :001 > arr = []
 => [] 
2.4.2 :002 > loop do
2.4.2 :003 >   arr << 'a'*10000000
2.4.2 :004?>   sleep 1
2.4.2 :005?> end

After waiting until irb process climbs to about 1G RSS I stop the process... and see exactly same numbers. Maybe visualizing the call graph will help me understand what's going on?

jeprof --show_bytes --pdf `which ruby` jeprof.10536.0.f.heap > ruby.pdf

Using local file /home/mhi/.rvm/rubies/ruby-2.4.2/bin/ruby.
Using local file jeprof.10536.0.f.heap.
No nodes to print

So something is clearly wrong, and that's what I need help figuring out.

Here's full output from jemalloc stat: https://pastebin.com/RiMLtqA6

UPD.

So I've updated all the native-extension related gems, here's output of bundle exec ruby -e 'puts Gem.loaded_specs.values.select{ |i| !i.extensions.empty? }.map{ |i| "#{i.name} #{i.version}" }':

io-console 0.4.6
nokogiri 1.8.1
bcrypt 3.1.11
debug_inspector 0.0.3
binding_of_caller 0.7.2
json 2.1.0
capybara-webkit 1.14.0
damerau-levenshtein 1.3.0
unf_ext 0.0.7.4
eventmachine 1.2.5
ffi 1.9.18
kgio 2.11.0
msgpack 1.1.0
mysql2 0.4.9
rainbow 2.2.2
raindrops 0.18.0
rbtrace 0.4.8
stackprof 0.2.10
therubyracer 0.12.3
unicode 0.4.4.4
unicorn 5.3.0

Same result: RSS, Memory slots

Similar Question 4 (1 solutions) : Jemalloc functions not declared in this scope

Similar Question 5 (2 solutions) : jemalloc not detecting memory corruption

Similar Question 6 (1 solutions) : Spring boot application not using jemalloc

Similar Question 8 (1 solutions) : How do jemalloc and tcmalloc track threads?

Similar Question 9 (1 solutions) : How to dlopen jemalloc dynamic library

cc