Ticket #1737: gc-timing-two.patch

File gc-timing-two.patch, 9.3 KB (added by chromatic, 4 years ago)

revision of first patch

  • src/gc/alloc_resources.c

    diff --git a/src/gc/alloc_resources.c b/src/gc/alloc_resources.c
    index cd96ffb..6930bb8 100644
    a b  
    321321         * TODO pass required allocation size to the GC system, 
    322322         *      so that collection can be skipped if needed 
    323323         */ 
     324        size_t new_mem = mem_pools->memory_used - 
     325                         mem_pools->mem_used_last_collect; 
    324326        if (!mem_pools->gc_mark_block_level 
    325         &&   mem_pools->mem_allocs_since_last_collect) { 
     327            && new_mem > (mem_pools->mem_used_last_collect >> 1) 
     328            && new_mem > GC_SIZE_THRESHOLD) { 
    326329            Parrot_gc_mark_and_sweep(interp, GC_trace_stack_FLAG); 
    327330 
    328331            if (interp->gc_sys->sys_type != INF) { 
     
    360363    return_val             = pool->top_block->top; 
    361364    pool->top_block->top  += size; 
    362365    pool->top_block->free -= size; 
     366    mem_pools->memory_used += size; 
    363367 
    364368    return return_val; 
    365369} 
     
    512516    /* How much is free. That's the total size minus the amount we used */ 
    513517    new_block->free = new_block->size - (cur_spot - new_block->start); 
    514518    mem_pools->memory_collected +=      (cur_spot - new_block->start); 
     519    mem_pools->memory_used      +=      (cur_spot - new_block->start); 
    515520 
    516521    free_old_mem_blocks(mem_pools, pool, new_block, total_size); 
    517522 
     
    719724        else { 
    720725            /* Note that we don't have it any more */ 
    721726            mem_pools->memory_allocated -= cur_block->size; 
     727            mem_pools->memory_used -= 
     728                cur_block->size - cur_block->free - cur_block->freed; 
    722729 
    723730            /* We know the pool body and pool header are a single chunk, so 
    724731             * this is enough to get rid of 'em both */ 
  • src/gc/gc_ms.c

    diff --git a/src/gc/gc_ms.c b/src/gc/gc_ms.c
    index c244730..e67d6f2 100644
    a b  
    3535        __attribute__nonnull__(1); 
    3636 
    3737static void gc_ms_add_free_object(SHIM_INTERP, 
    38     SHIM(Memory_Pools *mem_pools), 
     38    ARGMOD(Memory_Pools *mem_pools), 
    3939    ARGMOD(Fixed_Size_Pool *pool), 
    4040    ARGIN(void *to_add)) 
     41        __attribute__nonnull__(2) 
    4142        __attribute__nonnull__(3) 
    4243        __attribute__nonnull__(4) 
     44        FUNC_MODIFIES(*mem_pools) 
    4345        FUNC_MODIFIES(*pool); 
    4446 
    4547static void gc_ms_alloc_objects(PARROT_INTERP, 
     
    134136PARROT_CANNOT_RETURN_NULL 
    135137PARROT_WARN_UNUSED_RESULT 
    136138static void * gc_ms_get_free_object(PARROT_INTERP, 
    137     ARGIN(Memory_Pools *mem_pools), 
     139    ARGMOD(Memory_Pools *mem_pools), 
    138140    ARGMOD(Fixed_Size_Pool *pool)) 
    139141        __attribute__nonnull__(1) 
    140142        __attribute__nonnull__(2) 
    141143        __attribute__nonnull__(3) 
     144        FUNC_MODIFIES(*mem_pools) 
    142145        FUNC_MODIFIES(*pool); 
    143146 
    144147static size_t gc_ms_get_gc_info(PARROT_INTERP, Interpinfo_enum which) 
     
    253256#define ASSERT_ARGS_gc_ms_active_sized_buffers __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    254257       PARROT_ASSERT_ARG(mem_pools)) 
    255258#define ASSERT_ARGS_gc_ms_add_free_object __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    256        PARROT_ASSERT_ARG(pool) \ 
     259       PARROT_ASSERT_ARG(mem_pools) \ 
     260    , PARROT_ASSERT_ARG(pool) \ 
    257261    , PARROT_ASSERT_ARG(to_add)) 
    258262#define ASSERT_ARGS_gc_ms_alloc_objects __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    259263       PARROT_ASSERT_ARG(interp) \ 
     
    560564    ++mem_pools->gc_mark_runs; 
    561565    --mem_pools->gc_mark_block_level; 
    562566    mem_pools->header_allocs_since_last_collect = 0; 
     567    mem_pools->mem_used_last_collect = mem_pools->memory_used; 
    563568 
    564569    return; 
    565570} 
     
    10981103    &&  (pool->top_block->top  == (char *)Buffer_bufstart(buffer) + old_size)) { 
    10991104        pool->top_block->free -= needed; 
    11001105        pool->top_block->top  += needed; 
     1106        interp->mem_pools->memory_used += needed; 
    11011107        Buffer_buflen(buffer)  = newsize; 
    11021108        return; 
    11031109    } 
     
    12101216    &&  pool->top_block->top  == (char *)Buffer_bufstart(str) + old_size) { 
    12111217        pool->top_block->free -= needed; 
    12121218        pool->top_block->top  += needed; 
     1219        interp->mem_pools->memory_used += needed; 
    12131220        Buffer_buflen(str) = new_size - sizeof (void *); 
    12141221        return; 
    12151222    } 
     
    12311238 
    12321239    /* Decrease usage */ 
    12331240    PARROT_ASSERT(Buffer_pool(str)); 
    1234     Buffer_pool(str)->freed  += ALIGNED_STRING_SIZE(Buffer_buflen(str)); 
     1241    Buffer_pool(str)->freed += old_size; 
     1242    interp->mem_pools->memory_used -= old_size; 
    12351243 
    12361244    /* copy mem from strstart, *not* bufstart */ 
    12371245    oldmem             = str->strstart; 
     
    14941502        ARGMOD(Fixed_Size_Pool *pool)) 
    14951503{ 
    14961504    ASSERT_ARGS(gc_ms_more_traceable_objects) 
     1505    size_t new_mem = mem_pools->memory_used 
     1506                   - mem_pools->mem_used_last_collect; 
    14971507 
    14981508    if (pool->skip == GC_ONE_SKIP) 
    14991509        pool->skip = GC_NO_SKIP; 
    15001510    else if (pool->skip == GC_NEVER_SKIP 
    15011511         || (pool->skip == GC_NO_SKIP 
    1502          &&  mem_pools->header_allocs_since_last_collect >= GC_SIZE_THRESHOLD)) 
     1512         && (new_mem > (mem_pools->mem_used_last_collect >> 1) 
     1513         &&  mem_pools->header_allocs_since_last_collect >= GC_SIZE_THRESHOLD))) 
    15031514            Parrot_gc_mark_and_sweep(interp, GC_trace_stack_FLAG); 
    15041515 
    15051516    /* requires that num_free_objects be updated in Parrot_gc_mark_and_sweep. 
     
    15231534 
    15241535static void 
    15251536gc_ms_add_free_object(SHIM_INTERP, 
    1526         SHIM(Memory_Pools *mem_pools), 
     1537        ARGMOD(Memory_Pools *mem_pools), 
    15271538        ARGMOD(Fixed_Size_Pool *pool), 
    15281539        ARGIN(void *to_add)) 
    15291540{ 
     
    15341545 
    15351546    object->next_ptr = pool->free_list; 
    15361547    pool->free_list  = object; 
     1548    mem_pools->memory_used -= pool->object_size; 
    15371549} 
    15381550 
    15391551/* 
     
    15541566PARROT_WARN_UNUSED_RESULT 
    15551567static void * 
    15561568gc_ms_get_free_object(PARROT_INTERP, 
    1557         ARGIN(Memory_Pools *mem_pools), 
     1569        ARGMOD(Memory_Pools *mem_pools), 
    15581570        ARGMOD(Fixed_Size_Pool *pool)) 
    15591571{ 
    15601572    ASSERT_ARGS(gc_ms_get_free_object) 
     
    15841596    } 
    15851597 
    15861598    --pool->num_free_objects; 
     1599    mem_pools->memory_used += pool->object_size; 
    15871600 
    15881601    return ptr; 
    15891602} 
  • src/gc/gc_private.h

    diff --git a/src/gc/gc_private.h b/src/gc/gc_private.h
    index ad62b42..46bce80 100644
    a b  
    283283                                   * memory for headers or 
    284284                                   * internal structures or 
    285285                                   * anything */ 
     286    size_t  memory_used;              /* The total amount of 
     287                                       * memory used for 
     288                                       * buffers and headers */ 
     289    size_t  mem_used_last_collect;    /* The total amount of 
     290                                       * memory used after 
     291                                       * the last GC run */ 
    286292    UINTVAL memory_collected;     /* Total amount of memory copied 
    287293                                     during collection */ 
    288294    UINTVAL num_early_gc_PMCs;    /* how many PMCs want immediate destruction */ 
  • src/gc/mark_sweep.c

    diff --git a/src/gc/mark_sweep.c b/src/gc/mark_sweep.c
    index 757a060..ea76511 100644
    a b  
    3232/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */ 
    3333 
    3434static void free_buffer(SHIM_INTERP, 
    35     SHIM(Memory_Pools *mem_pools), 
     35    ARGMOD(Memory_Pools *mem_pools), 
    3636    ARGMOD(Fixed_Size_Pool *pool), 
    3737    ARGMOD(Buffer *b)) 
     38        __attribute__nonnull__(2) 
    3839        __attribute__nonnull__(3) 
    3940        __attribute__nonnull__(4) 
     41        FUNC_MODIFIES(*mem_pools) 
    4042        FUNC_MODIFIES(*pool) 
    4143        FUNC_MODIFIES(*b); 
    4244 
     
    7880        FUNC_MODIFIES(*mem_pools); 
    7981 
    8082#define ASSERT_ARGS_free_buffer __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    81        PARROT_ASSERT_ARG(pool) \ 
     83       PARROT_ASSERT_ARG(mem_pools) \ 
     84    , PARROT_ASSERT_ARG(pool) \ 
    8285    , PARROT_ASSERT_ARG(b)) 
    8386#define ASSERT_ARGS_free_pmc_in_pool __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 
    8487       PARROT_ASSERT_ARG(interp) \ 
     
    655658 
    656659static void 
    657660free_buffer(SHIM_INTERP, 
    658         SHIM(Memory_Pools *mem_pools), 
     661        ARGMOD(Memory_Pools *mem_pools), 
    659662        ARGMOD(Fixed_Size_Pool *pool), 
    660663        ARGMOD(Buffer *b)) 
    661664{ 
     
    680683 
    681684            /* We can have shared buffers. Don't count them (yet) */ 
    682685            if (!(*buffer_flags & Buffer_shared_FLAG)) { 
    683                 block->freed  += ALIGNED_STRING_SIZE(Buffer_buflen(b)); 
     686                size_t size = ALIGNED_STRING_SIZE(Buffer_buflen(b)); 
     687                block->freed += size; 
     688                mem_pools->memory_used -= size; 
    684689            } 
    685690 
    686691        }