* gc.c (set_heaps_increment): fix memory allocation strategy by

determining heaps_inc from heaps_used, not objects_delta.
  (struct rb_objspace): delta removed.  change increment, length and
  used to long for LP64.
  (objects_delta): removed.
  (allocate_heaps): add next_heaps_length argument.
  (init_heap): renamed from add_heap.
  (garbage_collect): use heaps_increment in dont_gc.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16289 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-05-04 17:25:38 +00:00
parent d3677c3d05
commit 3e8e963837
2 changed files with 26 additions and 20 deletions

View File

@ -1,3 +1,14 @@
Mon May 5 02:10:23 2008 Tanaka Akira <akr@fsij.org>
* gc.c (set_heaps_increment): fix memory allocation strategy by
determining heaps_inc from heaps_used, not objects_delta.
(struct rb_objspace): delta removed. change increment, length and
used to long for LP64.
(objects_delta): removed.
(allocate_heaps): add next_heaps_length argument.
(init_heap): renamed from add_heap.
(garbage_collect): use heaps_increment in dont_gc.
Sun May 4 21:09:32 2008 Tanaka Akira <akr@fsij.org> Sun May 4 21:09:32 2008 Tanaka Akira <akr@fsij.org>
* lib/getoptlong.rb: use $stderr instead of $deferr. * lib/getoptlong.rb: use $stderr instead of $deferr.

35
gc.c
View File

@ -149,11 +149,10 @@ typedef struct rb_objspace {
unsigned long increase; unsigned long increase;
} params; } params;
struct { struct {
int delta; long increment;
int increment;
struct heaps_slot *ptr; struct heaps_slot *ptr;
int length; long length;
int used; long used;
RVALUE *freelist; RVALUE *freelist;
RVALUE *range[2]; RVALUE *range[2];
RVALUE *freed; RVALUE *freed;
@ -190,7 +189,6 @@ static rb_objspace_t rb_objspace = {{GC_MALLOC_LIMIT}, {HEAP_MIN_SLOTS}};
#define freelist objspace->heap.freelist #define freelist objspace->heap.freelist
#define lomem objspace->heap.range[0] #define lomem objspace->heap.range[0]
#define himem objspace->heap.range[1] #define himem objspace->heap.range[1]
#define objects_delta objspace->heap.delta
#define heaps_inc objspace->heap.increment #define heaps_inc objspace->heap.increment
#define heaps_freed objspace->heap.freed #define heaps_freed objspace->heap.freed
#define dont_gc objspace->flags.dont_gc #define dont_gc objspace->flags.dont_gc
@ -209,7 +207,6 @@ rb_objspace_alloc(void)
rb_objspace_t *objspace = malloc(sizeof(rb_objspace_t)); rb_objspace_t *objspace = malloc(sizeof(rb_objspace_t));
memset(objspace, 0, sizeof(*objspace)); memset(objspace, 0, sizeof(*objspace));
malloc_limit = GC_MALLOC_LIMIT; malloc_limit = GC_MALLOC_LIMIT;
objects_delta = HEAP_MIN_SLOTS;
return objspace; return objspace;
} }
@ -520,12 +517,12 @@ rb_gc_unregister_address(VALUE *addr)
static void static void
allocate_heaps(rb_objspace_t *objspace) allocate_heaps(rb_objspace_t *objspace, int next_heaps_length)
{ {
struct heaps_slot *p; struct heaps_slot *p;
int length; int length;
heaps_length += objects_delta / HEAP_OBJ_LIMIT; heaps_length = next_heaps_length;
length = heaps_length*sizeof(struct heaps_slot); length = heaps_length*sizeof(struct heaps_slot);
RUBY_CRITICAL( RUBY_CRITICAL(
if (heaps_used > 0) { if (heaps_used > 0) {
@ -597,15 +594,14 @@ assign_heap_slot(rb_objspace_t *objspace)
} }
static void static void
add_heap(rb_objspace_t *objspace) init_heap(rb_objspace_t *objspace)
{ {
int add, i; int add, i;
add = objects_delta / HEAP_OBJ_LIMIT; add = HEAP_MIN_SLOTS / HEAP_OBJ_LIMIT;
objects_delta *= 1.8;
if ((heaps_used + add) > heaps_length) { if ((heaps_used + add) > heaps_length) {
allocate_heaps(objspace); allocate_heaps(objspace, heaps_used + add);
} }
for (i = 0; i < add; i++) { for (i = 0; i < add; i++) {
@ -618,11 +614,10 @@ add_heap(rb_objspace_t *objspace)
static void static void
set_heaps_increment(rb_objspace_t *objspace) set_heaps_increment(rb_objspace_t *objspace)
{ {
heaps_inc += objects_delta / HEAP_OBJ_LIMIT; heaps_inc = heaps_used * 1.8 - heaps_used;
objects_delta *= 1.8;
if ((heaps_used + heaps_inc) > heaps_length) { if ((heaps_used + heaps_inc) > heaps_length) {
allocate_heaps(objspace); allocate_heaps(objspace, heaps_used + heaps_inc);
} }
} }
@ -1351,9 +1346,6 @@ free_unused_heaps(rb_objspace_t *objspace)
free(last); free(last);
} }
} }
if (i != j) {
objects_delta = heaps_used * HEAP_OBJ_LIMIT;
}
} }
void rb_gc_abort_threads(void); void rb_gc_abort_threads(void);
@ -1669,7 +1661,10 @@ garbage_collect(rb_objspace_t *objspace)
if (dont_gc || during_gc) { if (dont_gc || during_gc) {
if (!freelist) { if (!freelist) {
add_heap(objspace); if (!heaps_increment(objspace)) {
set_heaps_increment(objspace);
heaps_increment(objspace);
}
} }
return Qtrue; return Qtrue;
} }
@ -1864,7 +1859,7 @@ Init_heap(void)
if (!rb_gc_stack_start) { if (!rb_gc_stack_start) {
Init_stack(0); Init_stack(0);
} }
add_heap(&rb_objspace); init_heap(&rb_objspace);
} }
static VALUE static VALUE