[svn:parrot] r48466 - branches/unshared_buffers/src/gc

darbelo at svn.parrot.org darbelo at svn.parrot.org
Fri Aug 13 23:42:30 UTC 2010


Author: darbelo
Date: Fri Aug 13 23:42:30 2010
New Revision: 48466
URL: https://trac.parrot.org/parrot/changeset/48466

Log:
Apply nwellnhof's patch from TT #1742.

Modified:
   branches/unshared_buffers/src/gc/alloc_resources.c

Modified: branches/unshared_buffers/src/gc/alloc_resources.c
==============================================================================
--- branches/unshared_buffers/src/gc/alloc_resources.c	Fri Aug 13 17:10:18 2010	(r48465)
+++ branches/unshared_buffers/src/gc/alloc_resources.c	Fri Aug 13 23:42:30 2010	(r48466)
@@ -453,6 +453,12 @@
     if (mem_pools->gc_sweep_block_level)
         return;
 
+    /* Snag a block big enough for everything */
+    total_size = pad_pool_size(pool);
+
+    if (total_size)
+        return;
+
     ++mem_pools->gc_sweep_block_level;
 
     /* We're collecting */
@@ -460,9 +466,6 @@
     mem_pools->header_allocs_since_last_collect = 0;
     ++mem_pools->gc_collect_runs;
 
-    /* Snag a block big enough for everything */
-    total_size = pad_pool_size(pool);
-
     alloc_new_block(mem_pools, total_size, pool, "inside compact");
 
     new_block = pool->top_block;
@@ -529,6 +532,9 @@
 size minus the reclaimable size. Add a minimum block to the current amount, so
 we can avoid having to allocate it in the future.
 
+Returns 0 if all blocks below the top block are almost full. In this case
+compacting is not needed.
+
 TODO - Big blocks
 
 Currently all available blocks are compacted into one new
@@ -553,21 +559,29 @@
 pad_pool_size(ARGIN(const Variable_Size_Pool *pool))
 {
     ASSERT_ARGS(pad_pool_size)
-    Memory_Block *cur_block = pool->top_block;
+    Memory_Block *cur_block = pool->top_block->prev;
 
     UINTVAL total_size   = 0;
 #if RESOURCE_DEBUG
-    size_t  total_blocks = 0;
+    size_t  total_blocks = 1;
 #endif
 
     while (cur_block) {
-        total_size += cur_block->size - cur_block->freed - cur_block->free;
+        if (!is_block_almost_full(cur_block))
+            total_size += cur_block->size - cur_block->freed - cur_block->free;
         cur_block   = cur_block->prev;
 #if RESOURCE_DEBUG
         ++total_blocks;
 #endif
     }
 
+    if (total_size == 0)
+        return 0;
+
+    cur_block = pool->top_block;
+    if (!is_block_almost_full(cur_block))
+        total_size += cur_block->size - cur_block->freed - cur_block->free;
+
     /* this makes for ever increasing allocations but fewer collect runs */
 #if WE_WANT_EVER_GROWING_ALLOCATIONS
     total_size += pool->minimum_block_size;
@@ -732,7 +746,7 @@
 is_block_almost_full(ARGIN(const Memory_Block *block))
 {
     ASSERT_ARGS(is_block_almost_full)
-    return (block->free + block->freed) < block->size * 0.2;
+    return 5 * (block->free + block->freed) < block->size;
 }
 
 /*


More information about the parrot-commits mailing list