@@ -209,6 +209,7 @@ typedef struct rb_objspace {
209209 struct {
210210 size_t limit ;
211211 size_t increase ;
212+ size_t increase2 ;
212213#if CALC_EXACT_MALLOC_SIZE
213214 size_t allocated_size ;
214215 size_t allocations ;
@@ -271,6 +272,7 @@ int *ruby_initial_gc_stress_ptr = &rb_objspace.gc_stress;
271272#endif
272273#define malloc_limit objspace->malloc_params.limit
273274#define malloc_increase objspace->malloc_params.increase
275+ #define malloc_increase2 objspace->malloc_params.increase2
274276#define heaps objspace->heap.ptr
275277#define heaps_length objspace->heap.length
276278#define heaps_used objspace->heap.used
@@ -1976,6 +1978,8 @@ before_gc_sweep(rb_objspace_t *objspace)
19761978 objspace -> heap .free_num = 0 ;
19771979 objspace -> heap .free_slots = NULL ;
19781980
1981+ malloc_increase2 += ATOMIC_SIZE_EXCHANGE (malloc_increase ,0 );
1982+
19791983 /* sweep unlinked method entries */
19801984 if (GET_VM ()-> unlinked_method_entry_list ) {
19811985 rb_sweep_method_entry (GET_VM ());
@@ -1994,6 +1998,9 @@ after_gc_sweep(rb_objspace_t *objspace)
19941998 }
19951999
19962000 inc = ATOMIC_SIZE_EXCHANGE (malloc_increase , 0 );
2001+ inc += malloc_increase2 ;
2002+ malloc_increase2 = 0 ;
2003+
19972004 if (inc > malloc_limit ) {
19982005 malloc_limit +=
19992006 (size_t )((inc - malloc_limit ) * (double )objspace -> heap .marked_num / (heaps_used * HEAP_OBJ_LIMIT ));
@@ -3479,8 +3486,9 @@ vm_malloc_prepare(rb_objspace_t *objspace, size_t size)
34793486 size += sizeof (size_t );
34803487#endif
34813488
3489+ ATOMIC_SIZE_ADD (malloc_increase , size );
34823490 if ((ruby_gc_stress && !ruby_disable_gc_stress ) ||
3483- ( malloc_increase + size ) > malloc_limit ) {
3491+ malloc_increase > malloc_limit ) {
34843492 garbage_collect_with_gvl (objspace );
34853493 }
34863494
@@ -3490,8 +3498,6 @@ vm_malloc_prepare(rb_objspace_t *objspace, size_t size)
34903498static inline void *
34913499vm_malloc_fixup (rb_objspace_t * objspace , void * mem , size_t size )
34923500{
3493- ATOMIC_SIZE_ADD (malloc_increase , size );
3494-
34953501#if CALC_EXACT_MALLOC_SIZE
34963502 ATOMIC_SIZE_ADD (objspace -> malloc_params .allocated_size , size );
34973503 ATOMIC_SIZE_INC (objspace -> malloc_params .allocations );
@@ -4077,7 +4083,7 @@ gc_prof_set_malloc_info(rb_objspace_t *objspace)
40774083 if (objspace -> profile .run ) {
40784084 gc_profile_record * record = & objspace -> profile .record [objspace -> profile .count ];
40794085 if (record ) {
4080- record -> allocate_increase = malloc_increase ;
4086+ record -> allocate_increase = malloc_increase + malloc_increase2 ;
40814087 record -> allocate_limit = malloc_limit ;
40824088 }
40834089 }
0 commit comments