Jon Harrop said:
Here, you say that the "GC runs on a single thread".
Yep. One GC thread per GC heap, you can't have multiple threads collecting a
single GC heap (no parallelism).
Workstation GC: 1 (user) thread per process collecting the (single) heap.
Server GC: one dedicated GC thread per GC heap (one GC heap per processor).
Say each user thread requires 33% CPU time from the GC. Then a
single-threaded GC can satisfy the allocation needs of up to 3 such
threads. If you have 1..3 such user threads then performance will scale.
But if you have 4... user threads then a single-threaded GC will saturate
and the user threads will be allocation-limited.
Here, you say that there is one GC thread for each CPU. Is that not
contrary
to your original statement "GC runs on a single thread"?
Each GC thread collects a single heap, note that this is only valid for
serverGc enabled processes. The workstation version GC runs on the user
thread that triggered a collection, this is the single thread in the process
actually collecting the one and only GC heap.
For this you need:
1) multiple CPU's (or cores).
2) the following in your config file:
<configuration>
<runtime>
<gcServer enabled="true"/>
</runtime>
If there are more user threads than GC heaps then two or more user threads
must share a single GC heap. So they must synchronize their allocations?
True, if you have more threads running than actual processors, you will
share a heap across multiple threads, not sure what you mean with
"synchronize their allocations" though.
Say you have 6 threads running on a quad core, with 'gcServer' enabled, you
may notice the first 4 thread allocating from different heap, while the two
remaining threads are sharing a heap with one of the first four threads.
However, this all depends on the allocation scheme, the CLR version and a
number of (undocumented) heuristics.
The CLR keeps track of the allocation frequency, allocation size number of
managed threads in the process. User threads with a "low allocation
frequency" tend to share a single heap, while threads with an high
allocation frequency , *may* get their own heap.
Say that you start 4 threads on a quad box, and each of these threads do
only allocate less than a few hundred small objects per second, then you
will probably share a single heap for the four threads, while running 4
threads that do have a much higher allocation frequency may occupy 4
different heaps.
That makes sense. Who is responsible for collecting the main heap? Is
there
a server GC thread that suspends all user threads and then traverses the
whole heap? What are the stalling implications of this for soft real-time
applications?
There is no such thing like a "main heap", each GC heap has it's own GC
thread, this one will/can only collect his own heap.
I guess you are referring to something different.
Willy.