Project

General

Profile

Feature #2328 » suppress_malloc_increase-1.patch

wanabe (_ wanabe), 11/04/2009 08:28 AM

View differences:

gc.c (working copy)
296 296
    struct {
297 297
	size_t limit;
298 298
	size_t increase;
299
	size_t count;
299 300
#if CALC_EXACT_MALLOC_SIZE
300 301
	size_t allocated_size;
301 302
	size_t allocations;
......
345 346
#endif
346 347
#define malloc_limit		objspace->malloc_params.limit
347 348
#define malloc_increase 	objspace->malloc_params.increase
349
#define malloc_count		objspace->malloc_params.count
348 350
#define heap_slots		objspace->heap.slots
349 351
#define heaps			objspace->heap.ptr
350 352
#define heaps_length		objspace->heap.length
......
664 666
	}
665 667
    }
666 668
    malloc_increase += size;
669
    malloc_count++;
667 670

  
668 671
#if CALC_EXACT_MALLOC_SIZE
669 672
    objspace->malloc_params.allocated_size += size;
......
679 682
vm_xrealloc(rb_objspace_t *objspace, void *ptr, size_t size)
680 683
{
681 684
    void *mem;
685
    int increase_size;
682 686

  
683 687
    if ((ssize_t)size < 0) {
684 688
	negative_size_allocation_error("negative re-allocation size");
......
688 692
	vm_xfree(objspace, ptr);
689 693
	return 0;
690 694
    }
691
    if (ruby_gc_stress && !ruby_disable_gc_stress)
695

  
696
    increase_size = size - malloc_increase / (malloc_count + 1);
697
    if (increase_size < 0) {
698
	increase_size = 0;
699
    }
700
    
701
    if ((ruby_gc_stress && !ruby_disable_gc_stress) ||
702
	(malloc_increase+increase_size) > malloc_limit) {
692 703
	garbage_collect_with_gvl(objspace);
704
    }
693 705

  
694 706
#if CALC_EXACT_MALLOC_SIZE
695 707
    size += sizeof(size_t);
......
706 718
	    ruby_memerror();
707 719
        }
708 720
    }
709
    malloc_increase += size;
721
    malloc_increase += increase_size;
710 722

  
711 723
#if CALC_EXACT_MALLOC_SIZE
712 724
    objspace->malloc_params.allocated_size += size;
......
1921 1933
	if (malloc_limit < GC_MALLOC_LIMIT) malloc_limit = GC_MALLOC_LIMIT;
1922 1934
    }
1923 1935
    malloc_increase = 0;
1936
    malloc_count = 0;
1924 1937
    if (freed < free_min) {
1925 1938
        set_heaps_increment(objspace);
1926 1939
        heaps_increment(objspace);