From:
anon-390528
Views: 934
Comments: 1
Mono: A Developer's Notebook ,banned books library, library cart dvd, windows media player remote library, british library ip
Slide 1: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
SGen — Mono’s new Garbage Collector
Mark Probst
Novell / LINBIT
04 February 2011
Slide 2: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Outline
1 Introduction 2 Simple garbage collection 3 Generational garbage collection 4 SGen 5 Improving your program’s performance 6 Tuning SGen
Slide 3: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Me
On the Mono team since 2007
Generic code sharing Initial PPC64 port
Working on SGen since April 2009
Slide 4: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Why not Boehm for Life?
Slow allocation Not generational Hard to do precise GC with App Domains Fragmentation issues
Slide 5: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Mark-and-Sweep
Root
R
Slide 6: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Mark-and-Sweep
Root
R
Slide 7: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Mark-and-Sweep
Root
R
Slide 8: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Mark-and-Sweep
Root
R
Slide 9: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Mark-and-Sweep
Root
R
Slide 10: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Mark-and-Sweep
Root
R
Slide 11: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Mark-and-Sweep
Root
R
Slide 12: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Copying
Root
R
Slide 13: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Copying
Root
R
Slide 14: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Copying
Root
R
Slide 15: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Copying
Root
R
Slide 16: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Copying
Root
R
Slide 17: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Copying
Root
R
Slide 18: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Copying
Root
R
Slide 19: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
The generational hypothesis
Most objects die young Those that don’t live for a long time
Slide 20: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Generations
Separate heaps for young and old objects Young objects are collected frequently Those that survive get "promoted"
Slide 21: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Write barriers
Nursery
Root
Major Heap
Slide 22: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Write barriers
Nursery
Root
Major Heap
Slide 23: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Generations
Nursery Major heap Large Object Space (LOS)
For objects ≥ 8000 bytes Logically part of the major heap
Slide 24: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Thread Local Allocation Buffers (TLAB)
Nursery
Thread 1
Thread 2
Thread 3
Each thread gets a small part of the nursery Uncontested pointer-bumping allocation
Slide 25: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Pinning
Not everything is scanned precisely Even then, not all precisely scanned pointers can be changed
Everything on the stack
Slide 26: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Pinning
We cannot move some objects This is problematic mostly in the nursery
Because it’s small and fast allocation depends on it
Slide 27: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Mark-and-Sweep
Fixed-size blocks (16kb) Each block contains objects of the same size That helps prevent fragmentation
Slide 28: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Evacuation
Slide 29: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Allocation is cheap
p u b l i c c l a s s Test { int a , b ; p u b l i c s t a t i c i n t Main ( ) { f o r ( i n t i = 0 ; i < 5 0 0 0 0 0 0 0 ; ++i ) T e s t t = new T e s t ( ) ; return 0; } }
Boehm SGen SGen 128k nursery
Quad Core i7 Darwin 4s 11498 GCs (1.5s) 0.45s 191/1 GCs (3.6ms) 0.8s 6141/1 GCs (69ms)
Dual Core i7 Linux 3s 17321 GCs (1.7s) 0.5s 287/1 GCs (6ms) 1.1s 9215/1 GCs (152ms)
Slide 30: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Don’t use free lists
Live objects are a continuous cost Unless you don’t do any other allocation at all
Even then, see previous slide
Slide 31: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Don’t write to reference fields
Especially not in old objects Better yet, don’t have them in the first place
Objects without reference fields are processed faster
Slide 32: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Weak refs are expensive
But less expensive than on Boehm
Slide 33: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Finalization is expensive (and evil)
Time of finalization is not determined Finalization order is not determined Objects are kept alive longer
Slide 34: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Environment Variable
MONO_GC_PARAMS
See man page
Slide 35: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Nursery Size
nursery-size=
must be a power of two Default is 4m Going too low leads to over-pinning Enlarge if you have more threads
Slide 36: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Major Collector
major=
marksweep
The cautious default
marksweep-par marksweep-fixed
Use this unless you have good reason not to
marksweep-fixed-par
Better yet, use this and report bugs
copying
Slide 37: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Concurrent Sweep
no-concurrent-sweep
Currently the default
concurrent-sweep
Use this, report bugs
Slide 38: SGen — Mono’s new Garbage Collector Mark Probst Introduction Simple garbage collection Generational garbage collection SGen Improving your program’s performance Tuning SGen
Write Barrier
wbarrier=
cardtable
The default Slow for large heaps
remset
Very bad if you do lots of reference field writes Good if you do very few
Subject to short term change!