ruby-changes:31961
From: ko1 <ko1@a...>
Date: Fri, 6 Dec 2013 19:27:12 +0900 (JST)
Subject: [ruby-changes:31961] ko1:r44040 (trunk): * gc.c: change oldmalloc meaning.
ko1 2013-12-06 19:27:02 +0900 (Fri, 06 Dec 2013) New Revision: 44040 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44040 Log: * gc.c: change oldmalloc meaning. Increase oldmalloc_increase with malloc_increase instead of using obj_memsize_of(). This change will avoid the danger of memory full without major GC. Modified files: trunk/ChangeLog trunk/gc.c Index: ChangeLog =================================================================== --- ChangeLog (revision 44039) +++ ChangeLog (revision 44040) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Dec 6 19:18:02 2013 Koichi Sasada <ko1@a...> + + * gc.c: change oldmalloc meaning. + Increase oldmalloc_increase with malloc_increase + instead of using obj_memsize_of(). + + This change will avoid the danger of memory full without major GC. + Fri Dec 6 19:08:48 2013 Koichi Sasada <ko1@a...> * gc.c (atomic_sub_nounderflow): not 0 but val itself. Index: gc.c =================================================================== --- gc.c (revision 44039) +++ gc.c (revision 44040) @@ -2889,17 +2889,11 @@ gc_before_sweep(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L2889 objspace->rgengc.need_major_gc = GPR_FLAG_MAJOR_BY_OLDMALLOC;; objspace->rgengc.oldmalloc_increase_limit = (size_t)(objspace->rgengc.oldmalloc_increase_limit * gc_params.oldmalloc_limit_growth_factor); + if (objspace->rgengc.oldmalloc_increase_limit > gc_params.oldmalloc_limit_max) { objspace->rgengc.oldmalloc_increase_limit = gc_params.oldmalloc_limit_max; } } - else { - objspace->rgengc.oldmalloc_increase_limit = - (size_t)(objspace->rgengc.oldmalloc_increase_limit / ((gc_params.oldmalloc_limit_growth_factor - 1)/10 + 1)); - if (objspace->rgengc.oldmalloc_increase_limit < gc_params.oldmalloc_limit_min) { - objspace->rgengc.oldmalloc_increase_limit = gc_params.oldmalloc_limit_min; - } - } if (0) fprintf(stderr, "%d\t%d\t%u\t%u\t%d\n", (int)rb_gc_count(), objspace->rgengc.need_major_gc, (unsigned int)objspace->rgengc.oldmalloc_increase, @@ -2909,6 +2903,14 @@ gc_before_sweep(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L2903 else { /* major GC */ objspace->rgengc.oldmalloc_increase = 0; + + if ((objspace->profile.latest_gc_info & GPR_FLAG_MAJOR_BY_OLDMALLOC) == 0) { + objspace->rgengc.oldmalloc_increase_limit = + (size_t)(objspace->rgengc.oldmalloc_increase_limit / ((gc_params.oldmalloc_limit_growth_factor - 1)/10 + 1)); + if (objspace->rgengc.oldmalloc_increase_limit < gc_params.oldmalloc_limit_min) { + objspace->rgengc.oldmalloc_increase_limit = gc_params.oldmalloc_limit_min; + } + } } #endif @@ -3619,11 +3621,6 @@ gc_mark_children(rb_objspace_t *objspace https://github.com/ruby/ruby/blob/trunk/gc.c#L3621 /* infant -> old */ objspace->rgengc.old_object_count++; objspace->rgengc.parent_object_is_old = TRUE; - -#if RGENGC_ESTIMATE_OLDMALLOC - objspace->rgengc.oldmalloc_increase += obj_memsize_of((VALUE)obj, FALSE); -#endif - #endif rgengc_report(3, objspace, "gc_mark_children: promote infant -> young %p (%s).\n", (void *)obj, obj_type_name((VALUE)obj)); } @@ -3635,9 +3632,6 @@ gc_mark_children(rb_objspace_t *objspace https://github.com/ruby/ruby/blob/trunk/gc.c#L3632 /* young -> old */ RVALUE_PROMOTE_YOUNG((VALUE)obj); objspace->rgengc.old_object_count++; -#if RGENGC_ESTIMATE_OLDMALLOC - objspace->rgengc.oldmalloc_increase += obj_memsize_of((VALUE)obj, FALSE); -#endif rgengc_report(3, objspace, "gc_mark_children: promote young -> old %p (%s).\n", (void *)obj, obj_type_name((VALUE)obj)); } else { @@ -4867,7 +4861,7 @@ garbage_collect_body(rb_objspace_t *objs https://github.com/ruby/ruby/blob/trunk/gc.c#L4861 if (immediate_sweep) reason |= GPR_FLAG_IMMEDIATE_SWEEP; full_mark = (reason & GPR_FLAG_MAJOR_MASK) ? TRUE : FALSE; - if (GC_NOTIFY) fprintf(stderr, "start garbage_collect(%d, %d, %d)\n", full_mark, immediate_sweep, reason); + if (GC_NOTIFY) fprintf(stderr, "start garbage_collect(%d, %d, %d)\n", full_mark, immediate_sweep, reason); objspace->profile.count++; objspace->profile.latest_gc_info = reason; @@ -5826,9 +5820,11 @@ objspace_malloc_increase(rb_objspace_t * https://github.com/ruby/ruby/blob/trunk/gc.c#L5820 { if (new_size > old_size) { ATOMIC_SIZE_ADD(malloc_increase, new_size - old_size); + ATOMIC_SIZE_ADD(objspace->rgengc.oldmalloc_increase, new_size - old_size); } else { atomic_sub_nounderflow(&malloc_increase, old_size - new_size); + atomic_sub_nounderflow(&objspace->rgengc.oldmalloc_increase, old_size - new_size); } if (type == MEMOP_TYPE_MALLOC) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/