ruby-changes:29968
From: ko1 <ko1@a...>
Date: Wed, 17 Jul 2013 13:35:24 +0900 (JST)
Subject: [ruby-changes:29968] ko1:r42020 (trunk): * gc.c: fix heaps_header and heaps_slot to reduce memory consumption.
ko1 2013-07-17 13:34:57 +0900 (Wed, 17 Jul 2013) New Revision: 42020 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42020 Log: * gc.c: fix heaps_header and heaps_slot to reduce memory consumption. (1) move heaps_header::start and limit to heaps_slot. (2) remove heaps_header::end which can be calculated by start+limit. * gc.c: catch up above change. Modified files: trunk/ChangeLog trunk/gc.c Index: ChangeLog =================================================================== --- ChangeLog (revision 42019) +++ ChangeLog (revision 42020) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Jul 17 13:29:16 2013 Koichi Sasada <ko1@a...> + + * gc.c: fix heaps_header and heaps_slot to reduce memory consumption. + (1) move heaps_header::start and limit to heaps_slot. + (2) remove heaps_header::end which can be calculated by start+limit. + + * gc.c: catch up above change. + Wed Jul 17 12:30:05 2013 Tanaka Akira <akr@f...> * include/ruby/st.h (st_strcasecmp): Macro defined for compatibility. Index: gc.c =================================================================== --- gc.c (revision 42019) +++ gc.c (revision 42020) @@ -265,9 +265,6 @@ enum { https://github.com/ruby/ruby/blob/trunk/gc.c#L265 struct heaps_header { struct heaps_slot *base; - RVALUE *start; - RVALUE *end; - size_t limit; }; struct gc_list { @@ -420,6 +417,9 @@ enum { https://github.com/ruby/ruby/blob/trunk/gc.c#L417 struct heaps_slot { struct heaps_header *header; + RVALUE *start; + size_t limit; + RVALUE *freelist; struct heaps_slot *next; struct heaps_slot *prev; @@ -785,9 +785,11 @@ assign_heap_slot(rb_objspace_t *objspace https://github.com/ruby/ruby/blob/trunk/gc.c#L785 /* adjust obj_limit (object number available in this slot) */ start = (RVALUE*)((VALUE)header + sizeof(struct heaps_header)); if ((VALUE)start % sizeof(RVALUE) != 0) { - start = (RVALUE*)((VALUE)start + sizeof(RVALUE) - ((VALUE)start % sizeof(RVALUE))); + int delta = sizeof(RVALUE) - ((VALUE)start % sizeof(RVALUE)); + start = (RVALUE*)((VALUE)start + delta); limit = (HEAP_SIZE - (size_t)((VALUE)start - (VALUE)header))/sizeof(RVALUE); } + end = start + limit; /* setup objspace->heap.sorted */ lo = 0; @@ -812,11 +814,10 @@ assign_heap_slot(rb_objspace_t *objspace https://github.com/ruby/ruby/blob/trunk/gc.c#L814 } objspace->heap.sorted[hi] = header; - /* setup header */ - header->start = start; - header->end = end = start + limit; - header->base = heaps; - header->limit = limit; + /* setup header and slot */ + header->base = slot; + slot->start = start; + slot->limit = limit; if (lomem == 0 || lomem > start) lomem = start; if (himem < end) himem = end; @@ -1143,8 +1144,8 @@ is_pointer_to_heap(rb_objspace_t *objspa https://github.com/ruby/ruby/blob/trunk/gc.c#L1144 while (lo < hi) { mid = (lo + hi) / 2; heap = objspace->heap.sorted[mid]; - if (heap->start <= p) { - if (p < heap->end) + if (heap->base->start <= p) { + if (p < heap->base->start + heap->base->limit) return TRUE; lo = mid + 1; } @@ -1207,7 +1208,7 @@ free_unused_heaps(rb_objspace_t *objspac https://github.com/ruby/ruby/blob/trunk/gc.c#L1208 struct heaps_header *last = 0; for (i = j = 1; j < heaps_used; i++) { - if (objspace->heap.sorted[i]->limit == 0) { + if (objspace->heap.sorted[i]->base->limit == 0) { if (!last) { last = objspace->heap.sorted[i]; } @@ -1423,8 +1424,8 @@ objspace_each_objects(VALUE arg) https://github.com/ruby/ruby/blob/trunk/gc.c#L1424 break; membase = (RVALUE *)objspace->heap.sorted[i]; - pstart = objspace->heap.sorted[i]->start; - pend = pstart + objspace->heap.sorted[i]->limit; + pstart = objspace->heap.sorted[i]->base->start; + pend = pstart + objspace->heap.sorted[i]->base->limit; for (; pstart != pend; pstart++) { if (pstart->as.basic.flags) { @@ -1788,7 +1789,7 @@ finalize_list(rb_objspace_t *objspace, R https://github.com/ruby/ruby/blob/trunk/gc.c#L1789 } else { struct heaps_slot *slot = (struct heaps_slot *)(VALUE)RDATA(p)->dmark; - slot->header->limit--; + slot->limit--; } p = tmp; } @@ -1885,7 +1886,7 @@ rb_objspace_call_finalizer(rb_objspace_t https://github.com/ruby/ruby/blob/trunk/gc.c#L1886 /* run data object's finalizers */ for (i = 0; i < heaps_used; i++) { - p = objspace->heap.sorted[i]->start; pend = p + objspace->heap.sorted[i]->limit; + p = objspace->heap.sorted[i]->base->start; pend = p + objspace->heap.sorted[i]->base->limit; while (p < pend) { if (BUILTIN_TYPE(p) == T_DATA && DATA_PTR(p) && RANY(p)->as.data.dfree && @@ -1940,7 +1941,7 @@ is_swept_object(rb_objspace_t *objspace, https://github.com/ruby/ruby/blob/trunk/gc.c#L1941 struct heaps_slot *slot = objspace->heap.sweep_slots; while (slot) { - if ((VALUE)slot->header->start <= ptr && ptr < (VALUE)(slot->header->end)) + if ((VALUE)slot->start <= ptr && ptr < (VALUE)(slot->start + slot->limit)) return FALSE; slot = slot->next; } @@ -2154,7 +2155,7 @@ count_objects(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/gc.c#L2155 for (i = 0; i < heaps_used; i++) { RVALUE *p, *pend; - p = objspace->heap.sorted[i]->start; pend = p + objspace->heap.sorted[i]->limit; + p = objspace->heap.sorted[i]->base->start; pend = p + objspace->heap.sorted[i]->base->limit; for (;p < pend; p++) { if (p->as.basic.flags) { counts[BUILTIN_TYPE(p)]++; @@ -2163,7 +2164,7 @@ count_objects(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/gc.c#L2164 freed++; } } - total += objspace->heap.sorted[i]->limit; + total += objspace->heap.sorted[i]->base->limit; } if (hash == Qnil) { @@ -2260,7 +2261,7 @@ slot_sweep(rb_objspace_t *objspace, stru https://github.com/ruby/ruby/blob/trunk/gc.c#L2261 rgengc_report(1, objspace, "slot_sweep: start.\n"); sweep_slot->freelist = NULL; - p = sweep_slot->header->start; pend = p + sweep_slot->header->limit; + p = sweep_slot->start; pend = p + sweep_slot->limit; offset = p - NUM_IN_SLOT(p); bits = GET_HEAP_MARK_BITS(p); @@ -2317,15 +2318,15 @@ slot_sweep(rb_objspace_t *objspace, stru https://github.com/ruby/ruby/blob/trunk/gc.c#L2318 } #endif - if (final_num + freed_num + empty_num == sweep_slot->header->limit && - objspace->heap.free_num > objspace->heap.do_heap_free) { + if (final_num + freed_num + empty_num == sweep_slot->limit && + objspace->heap.free_num > objspace->heap.do_heap_free) { RVALUE *pp; for (pp = deferred_final_list; pp != final; pp = pp->as.free.next) { RDATA(pp)->dmark = (void (*)(void *))(VALUE)sweep_slot; pp->as.free.flags |= FL_SINGLETON; /* freeing page mark */ } - sweep_slot->header->limit = final_num; + sweep_slot->limit = final_num; unlink_heap_slot(objspace, sweep_slot); } else { @@ -3848,7 +3849,7 @@ rgengc_rememberset_mark(rb_objspace_t *o https://github.com/ruby/ruby/blob/trunk/gc.c#L3849 #endif for (i=0; i<heaps_used; i++) { - p = objspace->heap.sorted[i]->start; + p = objspace->heap.sorted[i]->base->start; bits = GET_HEAP_REMEMBERSET_BITS(p); offset = p - NUM_IN_SLOT(p); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/