Switch to workstation GC in case of constrained CPU resources (#24194)
authorLudovic Henry <luhenry@microsoft.com>
Thu, 25 Apr 2019 04:38:57 +0000 (21:38 -0700)
committerGitHub <noreply@github.com>
Thu, 25 Apr 2019 04:38:57 +0000 (21:38 -0700)
commita9b6851ad1a9551f3f654b654b094147b50e5999
tree561f714a16f0aa94ab927f8505f894ccd413a04d
parent57a40b91ce8d340f60717b73ab5d779e9f6a53be
Switch to workstation GC in case of constrained CPU resources (#24194)

* Switch to workstation GC in case of constrained CPU resources

Right now, if the user sets the configuration so that the server GC is
used, the server GC will be loaded even in conditions where we know the
workstation GC would fare better. An example of such conditions is
constrained environment where there is only 1 or less CPU or with very
low memory.

This can be harmful if users deploy the same projects on different kind
of platforms: deploying to a 20+ cores server and to Azure Functions
will require largely different configurations for the runtime.

There are already multiple ways for the user to specify to use the
server GC or not:
 - setting `COMPlus_gcServer` as an environment variable
 - setting `gcServer` in the configuration file
 - setting `System.GC.Server` passed to `coreclr_initialize`

Fix https://github.com/dotnet/coreclr/issues/23949

* Address review

* Address review

Remove GCToOSInterface::GetCurrentProcessCpuLimit in favor of
GCToOSInterface::GetCurrentProcessCpuCount because the CpuLimit is taken
into account in the CpuCount again.

* Address review

Do the work in src/vm/ceemain.cpp otherwise there will be a disparity
between what the VM and the GC are running. Before, only the GC would be
aware of the switch from server to workstation GC, but not the VM.
src/gc/gcload.cpp
src/vm/ceemain.cpp