On Tue, Oct 01, 2002 at 07:23:24AM +0000, Leopold Toetsch wrote: > # New Ticket Created by Leopold Toetsch > # Please include the string: [perl #17702] > # in the subject line of all future correspondence about this issue. > # <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=17702 > > > > This patch stops parrot from permanently allocating increasing amounts > of memory: > > Please try this: > > $ cd languages/perl6 > $ perl6 -B examples/life.p6 > $ cd - > $ ./parrot -d languages/perl6/examples/life.p6 N > > where N is e.g. 1, 10, 100, 1000 and watch memory usage of parrot and > allocated memory reported by -d. > > I tried different things to fix this (e.g correcting the statistics by > sizeof(struct Memory_Block), omitting the additional allocated 32 bytes > (what are they used for?) - but this all didn't help.
Applied, nervously. Clearly the previous behavior was not good -- but was there a reason for it? Does it avoid some worst-case behavior, or work around a subtle problem? It was added in revision 1.81, which was a Peter Gibbs and Mike Lambert patch adding COW support. The relevant chunk is: @@ -158,10 +169,17 @@ static void compact_pool(struct Parrot_I /* total-reclaimable == currently used. Add a minimum block to the * current amount, so we can avoid having to allocate it in the * future. */ - total_size = pool->total_allocated - pool->reclaimable + pool->minimum_block_size; - /* total_size = pool->total_allocated; */ - /* TODO: can reduce this by pool->total_reclaimable if we want to - * be precise */ + { + struct Memory_Block *cur_block, *next_block; + total_size = 0; + cur_block = pool->top_block; + while (cur_block) { + total_size += cur_block->size - cur_block->free; + cur_block = cur_block->prev; + } + } + total_size += pool->minimum_block_size; + /* Snag a block big enough for everything */ new_block = alloc_new_block(interpreter, total_size, pool);