David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and...

28
David F. Bacon David F. Bacon Perry Cheng Perry Cheng V.T. Rajan V.T. Rajan IBM T.J. Watson Research IBM T.J. Watson Research Center Center Controlling Controlling Fragmentation Fragmentation and Space Consumption and Space Consumption in the Metronome in the Metronome

Transcript of David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and...

Page 1: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

David F. BaconDavid F. Bacon

Perry ChengPerry Cheng

V.T. RajanV.T. Rajan

IBM T.J. Watson Research IBM T.J. Watson Research CenterCenter

ControllingControllingFragmentationFragmentation

and Space Consumption and Space Consumption in the Metronomein the Metronome

Page 2: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Problem Domain

• Hard real-time garbage collection – Implemented for Java

• Uniprocessor– Multiprocessors rare in real-time systems– Complication: collector must be finely

interleaved– Simplification: memory model easier to

program• No truly concurrent operations• Sequentially consistent

Page 3: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Metronome Project Goals

• Make GC feasible for hard real-time systems

• Provide simple application interface• Develop technology that is efficient:

– Throughput, Space comparable to stop-the-world

• BREAK THE MILLISECOND BARRIER– While providing even CPU utilization

Page 4: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Outline

• Overview of the Metronome• Empirical Results• What is Fragmentation?

– Static and dynamic measures

• How do we control space consumption?

• Conclusions

Page 5: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

The Metronome Collector

Page 6: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Real-time GC Approaches

• Mark-sweep (non-copying)– Fragmentation avoidance, coalescing– Subject to space explosion

• Semi-space Copying– Concurrently copies between spaces– Cost of copying, consistency, 2x

space

• The Metronome– Mark-sweep, selective

defragmentation– Best of both, adaptively adjusts

Page 7: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Components of the Metronome

• Incremental mark-sweep collector– Mark phase fixes stale pointers

• Selective incremental defragmentation– Moves < 2% of traced objects

• Time-based scheduling• Segregated free list allocator

– Geometric size progression limits internal fragmentation

Old New

Page 8: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Support Technologies

• Read barrier: to-space invariant [Brooks]– New techniques with only 4% overhead

• Write barrier: snapshot-at-the-beginning [Yuasa]

• Arraylets: bound fragmentation, large object ops

Old New

Page 9: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Empirical Results

Page 10: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Pause time distribution: javac

12 ms 12 ms

Time-based Scheduling Work-based Scheduling

Page 11: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Utilization vs. Time: javac

Time (s) Time (s)

0.4

0.2

0.0

0.6

0.8

1.0

Uti

liza

tio

n

(%)

0.4

0.2

0.0

0.6

0.8

1.0

Time-based Scheduling Work-based Scheduling

0.45

Page 12: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Space Usage: javac

Page 13: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Parameterization

Mutator

a*(ΔGC)m

Collector

R

Tuner

Δtsu

Allocation Rate

Maximum LiveMemory

Collection Rate

Real TimeInterval

Maximum UsedMemory

CPU Utilization

Page 14: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Is it real-time? Yes

• Maximum pause time < 4 ms [currently]

• MMU > 50% ±2%• Memory requirement < 2 X max

live

Page 15: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Static Fragmentation

Page 16: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Segregated Free List Allocator

• Heap divided into fixed-size pages• Each page divided into fixed-size

blocks• Objects allocated in smallest block

that fits

24

16

12

Page 17: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Fragmentation on a Page

• Internal: wasted space at end of object

• Page-internal: wasted space at end of page

• External: blocks needed for other size

external

internal page-internal

Page 18: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Fragmentation: ρ=1/8 vs. ρ=1/2

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Internal Page-Internal ExternalRecently Dead Live

Page 19: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Dynamic Fragmentation

Page 20: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Locality of Size: λ

• Measures reuse• Normalized: 0≤λ≤1

• Segregated by sizeByt

es

All

ocat

ed

Fre

ed

All

ocat

ed

Fre

ed

All

ocat

ed

Fre

ed

PerfectReuse

λ = Σi min ( fi / f, ai / a)

FreedReused

AllocatedReused

Page 21: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

λ in Real-time GC Context

• Mark-sweep (non-copying)

• Semi-space Copying

• The Metronome

Assumes λ=1

Assumes λ=0

Adapts as λ varies

Page 22: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

λ in Practice

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

javac db jack mtrt jess fragger

λ

% Defrag

Page 23: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Controlling Space Consumption

Page 24: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Triggering Collection

MS 1 MS 2 MS 3DF 1 DF 2

TIME

PA

GES

Free

Defrag

Page 25: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Factors in Space Consumption

MS 1 MS 2 MS 3DF 1 DF 2

R

λ

Page 26: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Reducing Space Consumption

• Collection Rate R– Higher rate: less memory reserve

needed– Speed up collector– Specify rate more precisely (bound

worst-case)

• Locality of Size λ – Higher locality: less free page reserve

needed– Specify page requirement more precisely

Page 27: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Conclusions

Page 28: David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.

Conclusions

• Contributions– Time-based scheduling (Tunable)– Mostly non-copying collection (λ varies)– Efficient software read barrier– Precise definition of fragmentation– Precise specification of collection triggers

• The Metronome provides true real-time GC– First collector to do so without major

sacrifice• Short pauses (4 ms)• High MMU during collection (50%)• Low memory consumption (2x max live)