Ticket #1742: compact-pool.diff

File compact-pool.diff, 2.5 KB (added by nwellnhof, 4 years ago)
  • src/gc/alloc_resources.c

    diff --git a/src/gc/alloc_resources.c b/src/gc/alloc_resources.c
    index cd96ffb..2740f34 100644
    a b  
    454454    if (mem_pools->gc_sweep_block_level) 
    455455        return; 
    456456 
     457    ++mem_pools->gc_collect_runs; 
     458 
     459    /* Snag a block big enough for everything */ 
     460    total_size = pad_pool_size(pool); 
     461 
     462    if (total_size == 0) 
     463        return; 
     464 
    457465    ++mem_pools->gc_sweep_block_level; 
    458466 
    459467    /* We're collecting */ 
    460468    mem_pools->mem_allocs_since_last_collect    = 0; 
    461469    mem_pools->header_allocs_since_last_collect = 0; 
    462     ++mem_pools->gc_collect_runs; 
    463  
    464     /* Snag a block big enough for everything */ 
    465     total_size = pad_pool_size(pool); 
    466470 
    467471    alloc_new_block(mem_pools, total_size, pool, "inside compact"); 
    468472 
     
    526530size minus the reclaimable size. Add a minimum block to the current amount, so 
    527531we can avoid having to allocate it in the future. 
    528532 
     533Returns 0 if all blocks below the top block are almost full. In this case 
     534compacting is not needed. 
     535 
    529536TODO - Big blocks 
    530537 
    531538Currently all available blocks are compacted into one new 
     
    550557pad_pool_size(ARGIN(const Variable_Size_Pool *pool)) 
    551558{ 
    552559    ASSERT_ARGS(pad_pool_size) 
    553     Memory_Block *cur_block = pool->top_block; 
     560    Memory_Block *cur_block = pool->top_block->prev; 
    554561 
    555562    UINTVAL total_size   = 0; 
    556563#if RESOURCE_DEBUG 
    557     size_t  total_blocks = 0; 
     564    size_t  total_blocks = 1; 
    558565#endif 
    559566 
    560567    while (cur_block) { 
    561         total_size += cur_block->size - cur_block->freed - cur_block->free; 
     568        if (!is_block_almost_full(cur_block)) 
     569            total_size += cur_block->size - cur_block->freed - cur_block->free; 
    562570        cur_block   = cur_block->prev; 
    563571#if RESOURCE_DEBUG 
    564572        ++total_blocks; 
    565573#endif 
    566574    } 
    567575 
     576    if (total_size == 0) 
     577        return 0; 
     578 
     579    cur_block = pool->top_block; 
     580    if (!is_block_almost_full(cur_block)) 
     581        total_size += cur_block->size - cur_block->freed - cur_block->free; 
     582 
    568583    /* this makes for ever increasing allocations but fewer collect runs */ 
    569584#if WE_WANT_EVER_GROWING_ALLOCATIONS 
    570585    total_size += pool->minimum_block_size; 
     
    759774is_block_almost_full(ARGIN(const Memory_Block *block)) 
    760775{ 
    761776    ASSERT_ARGS(is_block_almost_full) 
    762     return (block->free + block->freed) < block->size * 0.2; 
     777    return 5 * (block->free + block->freed) < block->size; 
    763778} 
    764779 
    765780/*