Skip to content
  • Matt Valentine-House's avatar
    a6dd859a
    Add expand_heap option to GC.verify_compaction_references · a6dd859a
    Matt Valentine-House authored
    In order to reliably test compaction we need to be able to move objects
    between size pools.
    
    In order for this to happen there must be pages in a size pool into
    which we can allocate.
    
    The existing implementation of `double_heap` only doubled the existing
    number of pages in the heap, so if a size pool had a low number of pages
    (or 0) it's not guaranteed that enough space will be created to move
    objects into that size pool.
    
    This commit deprecates the `double_heap` option and replaces it with
    `expand_heap` instead.
    
    expand heap will expand each heap by enough pages to hold a number of
    slots defined by `GC_HEAP_INIT_SLOTS` or by `heap->total_pags` whichever
    is larger.
    
    If both `double_heap` and `expand_heap` are present, a deprecation
    warning will be shown for `double_heap` and the `expand_heap` behaviour
    will take precedence
    
    Given that this is an API intended for debugging and testing GC
    compaction I'm not concerned about the extra memory usage or time taken
    to create the pages. However, for completeness:
    
    Running the following `test.rb` and using `time` on my Macbook Pro shows
    the following memory usage and time impact:
    
    pp "RSS (kb): #{`ps -o rss #{Process.pid}`.lines.last.to_i}"
    GC.verify_compaction_references(double_heap: true, toward: :empty)
    pp "RSS (kb): #{`ps -o rss #{Process.pid}`.lines.last.to_i}"
    
    ❯ time make run
    ./miniruby -I./lib -I. -I.ext/common  -r./arm64-darwin21-fake  ./test.rb
    "RSS (kb): 24000"
    <internal:gc>:251: warning: double_heap is deprecated and will be removed
    "RSS (kb): 25232"
    
    ________________________________________________________
    Executed in  124.37 millis    fish           external
       usr time   82.22 millis    0.09 millis   82.12 millis
       sys time   28.76 millis    2.61 millis   26.15 millis
    
    ❯ time make run
    ./miniruby -I./lib -I. -I.ext/common  -r./arm64-darwin21-fake  ./test.rb
    "RSS (kb): 24000"
    "RSS (kb): 49040"
    
    ________________________________________________________
    Executed in  150.13 millis    fish           external
       usr time  103.32 millis    0.10 millis  103.22 millis
       sys time   35.73 millis    2.59 millis   33.14 millis
    a6dd859a
    Add expand_heap option to GC.verify_compaction_references
    Matt Valentine-House authored
    In order to reliably test compaction we need to be able to move objects
    between size pools.
    
    In order for this to happen there must be pages in a size pool into
    which we can allocate.
    
    The existing implementation of `double_heap` only doubled the existing
    number of pages in the heap, so if a size pool had a low number of pages
    (or 0) it's not guaranteed that enough space will be created to move
    objects into that size pool.
    
    This commit deprecates the `double_heap` option and replaces it with
    `expand_heap` instead.
    
    expand heap will expand each heap by enough pages to hold a number of
    slots defined by `GC_HEAP_INIT_SLOTS` or by `heap->total_pags` whichever
    is larger.
    
    If both `double_heap` and `expand_heap` are present, a deprecation
    warning will be shown for `double_heap` and the `expand_heap` behaviour
    will take precedence
    
    Given that this is an API intended for debugging and testing GC
    compaction I'm not concerned about the extra memory usage or time taken
    to create the pages. However, for completeness:
    
    Running the following `test.rb` and using `time` on my Macbook Pro shows
    the following memory usage and time impact:
    
    pp "RSS (kb): #{`ps -o rss #{Process.pid}`.lines.last.to_i}"
    GC.verify_compaction_references(double_heap: true, toward: :empty)
    pp "RSS (kb): #{`ps -o rss #{Process.pid}`.lines.last.to_i}"
    
    ❯ time make run
    ./miniruby -I./lib -I. -I.ext/common  -r./arm64-darwin21-fake  ./test.rb
    "RSS (kb): 24000"
    <internal:gc>:251: warning: double_heap is deprecated and will be removed
    "RSS (kb): 25232"
    
    ________________________________________________________
    Executed in  124.37 millis    fish           external
       usr time   82.22 millis    0.09 millis   82.12 millis
       sys time   28.76 millis    2.61 millis   26.15 millis
    
    ❯ time make run
    ./miniruby -I./lib -I. -I.ext/common  -r./arm64-darwin21-fake  ./test.rb
    "RSS (kb): 24000"
    "RSS (kb): 49040"
    
    ________________________________________________________
    Executed in  150.13 millis    fish           external
       usr time  103.32 millis    0.10 millis  103.22 millis
       sys time   35.73 millis    2.59 millis   33.14 millis
Loading