View
215
Download
0
Category
Preview:
Citation preview
Copyright (c) 2004 Borys Bradel
Myths and Realities:The Performance Impact
of Garbage Collection
Paper: Stephen M. Blackburn, Perry Cheng, and Kathryn S.
McKinleyPresentation: Borys Bradel
2
IntroductionGarbage collection makes life easier
Additional level of abstractionNo worries about memory management
How to make it efficient?What are the tradeoffs?
4
Runtime ComponentsMutator:
the executing programincludes time for object allocation and, if necessary, a write barrier
Garbage collectors:allocate memory in a simple mannerperiodically identify unused memory and free it
5
AllocatorsContiguous: append new objectsFree-List: k size-segregated free-listsExample:
a: allocate 8 bytesb: allocate 12 bytesc: allocate 16 bytesfree bd: allocate 16 bytes
10
Contiguous
a: 8b: 12c: 16free bd: 16
a b c d
Good spatial locality sequential allocation creates
sequential memory location
No reclamation quickly run out of space
15
Free-List
a: 8b: 12c: 16free bd: 16
a
c d
8 byte
16 byte
Bad spatial locality: different queues
Reclamation Some fragmentation
16
CollectorsWhole heap
work on entire heaptreats everything the same: slow
Generationaldivide heap into old and newoptimize for the common case: faster
Tracing – compute transitive closureReference Counting
23
SemiSpaceContiguous allocatorDivide space into twoAt collection time move live data overd
ef
gh
defgh
26
Mark and SweepFree-list allocatorCollect when heap is fullUse bitmapsCopies long lived objects many timesd
e f
g
h
d
e f
g
h
d
f
31
Reference Counting
a
b
d: 2
f: 1
Roots Free-List
allocator Time
proportional to dead objects
Detects cycles Uses object
logging at writing
32
Generational Collector“Weak generational hypothesis”
the young die quickly, the old die slowly
Put young objects in a nurseryWhen nursery full, collect it and move survivors to old generation, a la SemiSpace
When heap full, perform all out collection
38
Generational CollectorsOn writes, record pointers from mature to nursery objectsNursery
is smaller than half of memorygenerally just contiguously allocatedsurvivors copied over into mature space
Mature space uses one of the three collectors – has their benefits/pitfalls
39
BenchmarksLow memory usage: 201, 222Low nursery survival: 202, 228, 205, 227High nursery survival: 213, 209, jbbfocus: accesses/size
Table 1 in [1]
40
ResultsLarger heap size decreases frequency of collection, up to a pointSmall difference in sizes cause different behavioursGenerational are big win
Less examined at each collectionFewer collections too, especially Mark and Sweep
Figure 1 in [1]
41
More ResultsWrite Barrier
Up to 13.6% overhead, average of 3.2%Benefit from generations more than makes up for the overhead
Free-List versus contiguous allocation
Free-List 11% slower.
42
Mutator CostsWhole heap
SemiSpace 7-15% over Mark and Sweep Mainly due to cache effects
GenerationalLocality of mature objects not a factor (except when it is, like in jbb)So fewer collections for Mark and Sweep are a win
Figure 2 in [1]
43
More ResultsFor small heaps, collection overhead dominates – want generational Mark and SweepFor large heaps generational SemiSpaceReference counting too expensive
44
Infinite HeapsNo garbage collection has small effect on mutator compared to when garbage collection is performed
Most reference patterns exhibit temporal locality, not spatial localityWhen spatial locality is important, garbage collection results in better performance
45
Nursery SizeSweetspot well beyond size of L2 cache
Larger size leads to fewer collectionsEventually too big
Figure 4 in [1]
46
ConclusionsContiguous allocation yields better localityFree-lists are more space efficient, so less collectionCounters myth that collection frequency is first order effect on performance?Explicit allocation is bad because free list can’t capture locality???
Recommended