[前][次][番号順一覧][スレッド一覧]

ruby-changes:71624

From: Eric <ko1@a...>
Date: Tue, 5 Apr 2022 06:48:22 +0900 (JST)
Subject: [ruby-changes:71624] a19b2d59fc (master): ruby_gc_set_params: update malloc_limit when env is set

https://git.ruby-lang.org/ruby.git/commit/?id=a19b2d59fc

From a19b2d59fc85abbb064d3923211161ba158c2fcb Mon Sep 17 00:00:00 2001
From: Eric Wong <e@8...>
Date: Mon, 17 Jan 2022 20:36:49 +0000
Subject: ruby_gc_set_params: update malloc_limit when env is set

During VM startup, rb_objspace_alloc sets malloc_limit
(objspace->malloc_params.limit) before ruby_gc_set_params is called, thus
nullifying the effect of RUBY_GC_MALLOC_LIMIT before the initial GC run.

The call sequence is as follows:

  main.c::main()
    ruby_init
      ruby_setup
        Init_BareVM
          rb_objspace_alloc // malloc_limit = gc_params.malloc_limit_min;
    ruby_options
      ruby_process_options
        process_options
          ruby_gc_set_params // RUBY_GC_MALLOC_LIMIT => gc_params.malloc_limit_min

With ruby_gc_set_params setting malloc_limit, RUBY_GC_MALLOC_LIMIT
affects the process sooner.

[ruby-core:107170]
---
 gc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gc.c b/gc.c
index 5ce440670c..1dadd38985 100644
--- a/gc.c
+++ b/gc.c
@@ -11267,6 +11267,7 @@ gc_set_initial_pages(void) https://github.com/ruby/ruby/blob/trunk/gc.c#L11267
 void
 ruby_gc_set_params(void)
 {
+    rb_objspace_t *objspace = &rb_objspace;
     /* RUBY_GC_HEAP_FREE_SLOTS */
     if (get_envparam_size("RUBY_GC_HEAP_FREE_SLOTS", &gc_params.heap_free_slots, 0)) {
 	/* ok */
@@ -11287,7 +11288,9 @@ ruby_gc_set_params(void) https://github.com/ruby/ruby/blob/trunk/gc.c#L11288
 			gc_params.heap_free_slots_min_ratio, gc_params.heap_free_slots_max_ratio, TRUE);
     get_envparam_double("RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR", &gc_params.oldobject_limit_factor, 0.0, 0.0, TRUE);
 
-    get_envparam_size  ("RUBY_GC_MALLOC_LIMIT", &gc_params.malloc_limit_min, 0);
+    if (get_envparam_size("RUBY_GC_MALLOC_LIMIT", &gc_params.malloc_limit_min, 0)) {
+	malloc_limit = gc_params.malloc_limit_min;
+    }
     get_envparam_size  ("RUBY_GC_MALLOC_LIMIT_MAX", &gc_params.malloc_limit_max, 0);
     if (!gc_params.malloc_limit_max) { /* ignore max-check if 0 */
         gc_params.malloc_limit_max = SIZE_MAX;
@@ -11296,7 +11299,6 @@ ruby_gc_set_params(void) https://github.com/ruby/ruby/blob/trunk/gc.c#L11299
 
 #if RGENGC_ESTIMATE_OLDMALLOC
     if (get_envparam_size("RUBY_GC_OLDMALLOC_LIMIT", &gc_params.oldmalloc_limit_min, 0)) {
-	rb_objspace_t *objspace = &rb_objspace;
 	objspace->rgengc.oldmalloc_increase_limit = gc_params.oldmalloc_limit_min;
     }
     get_envparam_size  ("RUBY_GC_OLDMALLOC_LIMIT_MAX", &gc_params.oldmalloc_limit_max, 0);
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]