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


Ruby use generally falls into one of two categories: short-lived or very long-lived.

For short-lived Ruby scripts MALLOC_ARENA_MAX could, and maybe should, be left as is?

For long-lived Ruby processes MALLOC_ARENA_MAX absolutely should be reduced from the glibc default as noted in this request and [#14718](https://bugs.ruby-lang.org/issues/14718). Hopefully, in time glibc can be improved, but that may be many years away.

I wonder if a new runtime flag should be added to the Ruby executable, `--long-lived`? That flag could tweak internals to favour long runtimes. For the moment it could tweak `MALLOC_ARENA_MAX`, in the future it could tweak other aspects to favour low memory fragmentation.

Rails, Sinatra, Sidekiq users would then be encouraged to invoke Ruby via `ruby --long-lived`?

I suspect some/many folks would not like that since that will not be the default behaviour. But that would avoid the weird regression noted above that concerns @shyouhei. Ideally we don't want to penalise short-lived Ruby users for the benefit of long-lived Ruby users.

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

* 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/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>