18. • Fantastic worldwide community
• Ruby has changed a lot over 20 years
• MRI is a complex virtual machine with a lot of history behind
it’s design decisions.
20
25. Ruby has an incremental GC
Mark Sweep
Ruby
27
• GC work is interleaved with execution
• Minimizes mutator pause times
• Single threaded
• Serialized with the mutator
30. 32
Starting out with Mark Sweep
static int
gc_start(rb_objspace_t *objspace …)
{
…
OMR_GC_SystemCollect();
...
}
static int
newobj_of(rb_objspace_t *objspace …)
{
...
obj = rb_omr_get_freeobj(th, sizeof(RVALUE));
...
}
31. 33
Starting out with Mark Sweep
Need to support conservative collection
Conservative collection
Object Map (bit map)
• Object map allows us to support
conservative collection
• Bit Map used to keep track of objects
• Results in ~ 1.6% memory overhead
33. Multithreaded GC (Stop the world)
35
mark sweep
• Introducing Parallel Global GC
• Aggressively parallelized
• New APIs for parallelism
• Support for thread pooling and task
synchronization
34. Marking in parallel
36
mark sweep
Marking:
• Scan roots in parallel
• Break VM roots into subsets
• Complete marking in parallel
35. Sweeping in parallel
37
mark sweep
Sweeping:
• Free malloc space in parallel
• Clean up objects in parallel
• Move work out of finalization
49. How do we replace malloc/free?
• malloc/free callouts are expensive
• Rely on system for memory management concerns
• Still susceptible to fragmentation and concurrency
• Black box implementation
• Replace malloc and free with a new allocator
52
51. New built-in type OMRBuffers
• Create a new, variable sized object type
• Allocate all buffers on the heap as objects
typedef struct OMRBuffer {
VALUE flags;
long size;
} OMRBuffer;
56
buffer
52. 58
OMRBuffers on the heap!
string arrayhash data …
Managed Memory
buffer buffer buffer buffer
Malloc Memory
54. Getting user defined types on heap
• RDatas are used to create C-extension types.
• Typed RDatas have a new flag:
RDATA_HEAP_ALLOCATED
• Automatically heap allocates the data buffer at allocation
• No free method results in no object finalization
• Allows for heap allocation in extensions
• Extremely easy to use
60
56. Multithreaded allocations
• MRI does some work in backgrounded threads
• Use OMRBuffers in background threads
• Introduce finer grained locking than the GVL
• Allows for:
• multithreaded allocations
• GCing from a background thread
62
59. Generational GC in MRI
• Experimenting with non-copying generational GC
• Marking is already fast
• Heap fragmentations issues
• High memory overhead
65
60. Segregated heap in MRI
• Introduced a segregated heap into ruby
• Heap divided into regions of fixed sized objects
• Bounds maximum heap fragmentation
66
61. 67
Concurrent GC in MRI
• Adding Concurrent GC to Ruby
• Ruby threads incrementally mark
• Background thread scans
• Parallelized sweep (STW)
sweepmark
63. OMR GC in Ruby – what’s next
• Ongoing experimentation
• Balanced
• Semispace copying generational collection
• compaction
• Real time garbage collection
71
64. What’s next for OMR?
• Open source OMR
• Make our Ruby experiments available
• We want to hear from the experts (you)
• Lets make OMR and Ruby the best they can be
72
69. John Duimovich
CTO IBM Runtimes
duimovic@ca.ibm.com
@jduimovich
Ask us Anything!
Mark Stoodley
OMR Project Lead
mstoodle@ca.ibm.com
@mstoodle
Robert Young
OMR Developer
rwyoung@ca.ibm.com
@rwy0717
77
Charlie Gracie
OMR GC Architect
crgracie@ca.ibm.com
@crgracie
Craig Lehmann
OMR Developer
craigl@ca.ibm.com
@craiglehmann
73. Additional Important Disclaimers
• THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL
PURPOSES ONLY.
• WHILST EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE
INFORMATION CONTAINED IN THIS PRESENTATION, IT IS PROVIDED “AS IS”, WITHOUT WARRANTY
OF ANY KIND, EXPRESS OR IMPLIED.
• ALL PERFORMANCE DATA INCLUDED IN THIS PRESENTATION HAVE BEEN GATHERED IN A
CONTROLLED ENVIRONMENT. YOUR OWN TEST RESULTS MAY VARY BASED ON HARDWARE,
SOFTWARE OR INFRASTRUCTURE DIFFERENCES.
• ALL DATA INCLUDED IN THIS PRESENTATION ARE MEANT TO BE USED ONLY AS A GUIDE.
• IN ADDITION, THE INFORMATION CONTAINED IN THIS PRESENTATION IS BASED ON IBM’S CURRENT
PRODUCT PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM, WITHOUT NOTICE.
• IBM AND ITS AFFILIATED COMPANIES SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING
OUT OF THE USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER
DOCUMENTATION.
• NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF:
• - CREATING ANY WARRANT OR REPRESENTATION FROM IBM, ITS AFFILIATED COMPANIES OR ITS
OR THEIR SUPPLIERS AND/OR LICENSORS
89