ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: dennisb55@hotmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:87209] [Ruby trunk Feature#14759] [PATCH] set M_ARENA_MAX for glibc malloc
Date: Mon, 21 May 2018 05:19:18 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-72199.20180521051917.8398f6894e1572e9@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-14759.20180515082552@ruby-lang.org

Issue #14759 has been updated by bluz71 (Dennis B).


Mike,

Yusuke script is still interesting for the datum that a Ruby script with `MALLOC_ARENA_MAX=2` consumed **more** memory than a case using the default arena count (usually 32 on 4 core machines).

Here are my results of Yusuke's script on my 4-core machine (Intel i5-4590 quad-core, 16GB RAM, Linux Mint 18.3 with kernel 4.15.0).

~~~
% time ruby frag2.rb 
VmRSS:   1,238,108 kB
real    0m38.792s

% time MALLOC_ARENA_MAX=2 ruby frag2.rb 
VmRSS:   1,561,624 kB
real    0m39.002s

% time MALLOC_ARENA_MAX=4 ruby frag2.rb 
VmRSS:   1,516,216 kB
real    0m36.614s

% time MALLOC_ARENA_MAX=32 ruby frag2.rb 
VmRSS:   1,218,180 kB
real    0m36.857s
~~~

This is perplexing. Clearly Ruby should not be changing defaults until we understand results like this.

Here are jemalloc results (3.6.0 first and 5.0.1 second):

~~~
% time LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so ruby frag2.rb 
VmRSS:    933,328 kB
real    1m33.660s

% time LD_PRELOAD=/home/bluz71/.linuxbrew/Cellar/jemalloc/5.0.1/lib/libjemalloc.so ruby frag2.rb 
VmRSS:   1,613,252 kB
real    0m27.530s
~~~

jemalloc 3.6.0 is extremely slow but with very low RSS.
jemalloc 5.0.1 is very fast (much faster than glibc) but also has the highest RSS.

Ruby can not be linked against a system supplied jemalloc since different jemalloc versions are extremely different; jemalloc 3.6 and 5.0 are basically different allocators that share the same name.


But we need to always remember that long lived Ruby processes on Linux have a very bad memory fragmentation as seen here:

![jemalloc](https://www.mikeperham.com/images/jemalloc.jpg)

What can the Ruby maintainers do?

I am less certain now what they should do than a week ago. But I still want to see the memory fragmentation issue reduced for default Ruby.

----------------------------------------
Feature #14759: [PATCH] set M_ARENA_MAX for glibc malloc
https://bugs.ruby-lang.org/issues/14759#change-72199

* Author: normalperson (Eric Wong)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Not everybody benefits from jemalloc and the extra download+install
time is not always worth it.  Lets make the user experience for
glibc malloc users better, too.

Personally, I prefer using M_ARENA_MAX=1 (via MALLOC_ARENA_MAX
env) myself, but there is currently a performance penalty for
that.


gc.c (Init_GC): set M_ARENA_MAX=2 for glibc malloc

glibc malloc creates too many arenas and leads to fragmentation.
Given the existence of the GVL, clamping to two arenas seems
to be a reasonable trade-off for performance and memory usage.

Some users (including myself for several years, now) prefer only
one arena, now, so continue to respect users' wishes when
MALLOC_ARENA_MAX is set.

Thanks to Mike Perham for the reminder [ruby-core:86843]


This doesn't seem to conflict with jemalloc, so it should be safe
for all glibc-using systems.


---Files--------------------------------
0001-gc.c-Init_GC-set-M_ARENA_MAX-2-for-glibc-malloc.patch (1.46 KB)


-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2018-05-21  5:19 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-14759.20180515082552@ruby-lang.org>
2018-05-15  8:25 ` [ruby-core:87035] [Ruby trunk Feature#14759] [PATCH] set M_ARENA_MAX for glibc malloc normalperson
2018-05-16  5:03 ` [ruby-core:87059] " dennisb55
2018-05-16  5:24   ` [ruby-core:87063] " Eric Wong
2018-05-19  3:04 ` [ruby-core:87187] " dennisb55
2018-05-19 14:03 ` [ruby-core:87193] " mame
2018-05-21  6:30   ` [ruby-core:87211] " Eric Wong
2018-05-20 17:58 ` [ruby-core:87199] " mperham
2018-05-21  5:19 ` dennisb55 [this message]
2018-08-01  0:20 ` [ruby-core:88240] " sam.saffron
2018-08-01  9:41   ` [ruby-core:88255] " Eric Wong
2018-08-01  9:57     ` [ruby-core:88258] " Eric Wong
2018-08-01 13:04 ` [ruby-core:88259] " eregontp
2018-08-01 19:18   ` [ruby-core:88262] " Eric Wong
2018-08-01 20:55 ` [ruby-core:88263] " eregontp
2018-08-08  6:10 ` [ruby-core:88343] " ko1
2018-08-08  6:27 ` [ruby-core:88344] " ko1
2018-08-09 11:35 ` [ruby-core:88394] " shyouhei
2018-08-09 17:43   ` [ruby-core:88402] " Eric Wong
2018-08-10  0:51 ` [ruby-core:88406] " shyouhei
2018-08-10  1:42   ` [ruby-core:88409] " Eric Wong
2018-08-10  2:07 ` [ruby-core:88411] " shyouhei
2018-08-10  2:16   ` [ruby-core:88412] " Eric Wong
2018-08-10  5:37 ` [ruby-core:88418] " dennisb55
2019-03-15  6:54 ` [ruby-core:91844] " dennisb55

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-72199.20180521051917.8398f6894e1572e9@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).