|
| 1 | +--- |
| 2 | +title: Garbage collector config settings |
| 3 | +description: Learn about run-time settings for configuring how the garbage collector manages memory. |
| 4 | +ms.date: 11/13/2019 |
| 5 | +ms.topic: reference |
| 6 | +--- |
| 7 | +# Run-time configuration options for garbage collection |
| 8 | + |
| 9 | +This page contains information about garbage collector (GC) settings that can be changed at run time. If you're trying to achieve peak performance of a running app, consider using these settings. However, the defaults provide optimum performance for most applications in typical situations. |
| 10 | + |
| 11 | +Settings are arranged into groups on this page. The settings within each group are commonly used in conjunction with each other to achieve a specific result. |
| 12 | + |
| 13 | +> [!NOTE] |
| 14 | +> |
| 15 | +> - These settings can also be changed dynamically by the app as it's running, so any run-time settings you set may be overridden. |
| 16 | +> - Some settings, such as [latency level](../../standard/garbage-collection/latency.md), are typically set only through the API at design time. Such settings are omitted from this page. |
| 17 | +
|
| 18 | +## Flavors of garbage collection |
| 19 | + |
| 20 | +The two main flavors of garbage collection are workstation GC and server GC. For more information about differences between the two, see [Fundamentals of garbage collection](../../standard/garbage-collection/fundamentals.md#workstation-and-server-garbage-collection). |
| 21 | + |
| 22 | +The subflavors of garbage collection are background and non-concurrent. |
| 23 | + |
| 24 | +Use the following settings to select flavors of garbage collection: |
| 25 | + |
| 26 | +### System.GC.Server/COMPlus_gcServer |
| 27 | + |
| 28 | +- Configures whether the application uses workstation garbage collection or server garbage collection. |
| 29 | +- Default: Workstation garbage collection (`false`). |
| 30 | +- For more information, see [Configure garbage collection](../../standard/garbage-collection/fundamentals.md#configuring-garbage-collection). |
| 31 | + |
| 32 | +| | Setting name | Values | Version introduced | |
| 33 | +| - | - | - | - | |
| 34 | +| **runtimeconfig.json** | `System.GC.Server` | `false` - workstation<br/>`true` - server | .NET Core 1.0 | |
| 35 | +| **Environment variable** | `COMPlus_gcServer` | 0 - workstation<br/>1 - server | .NET Core 1.0 | |
| 36 | +| **app.config for .NET Framework** | [GCServer](../../framework/configure-apps/file-schema/runtime/gcserver-element.md) | `false` - workstation<br/>`true` - server | | |
| 37 | + |
| 38 | +### System.GC.Concurrent/COMPlus_gcConcurrent |
| 39 | + |
| 40 | +- Configures whether background (concurrent) garbage collection is enabled. |
| 41 | +- Default: Enabled (`true`). |
| 42 | +- For more information, see [Background garbage collection](../../standard/garbage-collection/fundamentals.md#background-workstation-garbage-collection) and [Background server garbage collection](../../standard/garbage-collection/fundamentals.md#background-server-garbage-collection). |
| 43 | + |
| 44 | +| | Setting name | Values | Version introduced | |
| 45 | +| - | - | - | - | |
| 46 | +| **runtimeconfig.json** | `System.GC.Concurrent` | `true` - background GC<br/>`false` - non-concurrent GC | .NET Core 1.0 | |
| 47 | +| **Environment variable** | `COMPlus_gcConcurrent` | `true` - background GC<br/>`false` - non-concurrent GC | .NET Core 1.0 | |
| 48 | +| **app.config for .NET Framework** | [gcConcurrent](../../framework/configure-apps/file-schema/runtime/gcconcurrent-element.md) | `true` - background GC<br/>`false` - non-concurrent GC | | |
| 49 | + |
| 50 | +## Manage resource usage |
| 51 | + |
| 52 | +Use the settings described in this section to manage the garbage collector's memory and processor usage. |
| 53 | + |
| 54 | +For more information about some of these settings, see the [Middle ground between workstation and server GC](https://devblogs.microsoft.com/dotnet/middle-ground-between-server-and-workstation-gc/) blog entry. |
| 55 | + |
| 56 | +### System.GC.HeapCount/COMPlus_GCHeapCount |
| 57 | + |
| 58 | +- Limits the number of heaps created by the garbage collector. |
| 59 | +- Applies to server garbage collection (GC) only. |
| 60 | +- If GC thread/processor affinity is enabled, which is the default, the heap count setting affinitizes *number* GC heaps/threads to the first *number* processors. (Use the affinitize mask or affinitize ranges settings to specify exactly which processors to affinitize.) |
| 61 | +- If GC thread/processor affinity is disabled, this setting limits the number of GC heaps. |
| 62 | +- For more information, see the [GCHeapCount remarks](../../framework/configure-apps/file-schema/runtime/gcheapcount-element.md#remarks). |
| 63 | + |
| 64 | +| | Setting name | Values | Version introduced | |
| 65 | +| - | - | - | - | |
| 66 | +| **runtimeconfig.json** | `System.GC.HeapCount` | *number* | .NET Core 3.0 | |
| 67 | +| **Environment variable** | `COMPlus_GCHeapCount` | *number* | .NET Core 3.0 | |
| 68 | +| **app.config for .NET Framework** | [GCHeapCount](../../framework/configure-apps/file-schema/runtime/gcheapcount-element.md) | *number* | 4.6.2 | |
| 69 | + |
| 70 | +### System.GC.HeapAffinitizeMask/COMPlus_GCHeapAffinitizeMask |
| 71 | + |
| 72 | +- Specifies the exact processors that garbage collector threads should use. |
| 73 | +- If processor affinity is disabled by setting `System.GC.NoAffinitize` to `true`, this setting is ignored. |
| 74 | +- Applies to server garbage collection (GC) only. |
| 75 | +- The decimal value is a bit mask that defines the processors that are available to the process. For example, a decimal value of 1023 is equivalent to 0x3FF in hexadecimal notation and 0011 1111 1111 in binary notation. This specifies that the first 10 processors are to be used. To specify the next 10 processors, that is, processors 10-19, specify a decimal value of 1047552, which is equivalent to 0xFFC00 in hexadecimal and 1111 1111 1100 0000 0000 in binary. |
| 76 | + |
| 77 | +| | Setting name | Values | Version introduced | |
| 78 | +| - | - | - | - | |
| 79 | +| **runtimeconfig.json** | `System.GC.HeapAffinitizeMask` | *decimal value* | .NET Core 3.0 | |
| 80 | +| **Environment variable** | `COMPlus_GCHeapAffinitizeMask` | *decimal value* | .NET Core 3.0 | |
| 81 | +| **app.config for .NET Framework** | [GCHeapAffinitizeMask](../../framework/configure-apps/file-schema/runtime/gcheapaffinitizemask-element.md) | *decimal value* | 4.6.2 | |
| 82 | + |
| 83 | +### System.GC.GCHeapAffinitizeRanges/COMPlus_GCHeapAffinitizeRanges |
| 84 | + |
| 85 | +- Specifies the list of processors to use for garbage collector threads. |
| 86 | +- This setting is similar to `System.GC.HeapAffinitizeMask`, except it allows you to specify more than 64 processors. |
| 87 | +- For Windows operating systems, prefix the processor number or range with the corresponding [CPU group](/windows/win32/procthread/processor-groups), for example, "0:1-10,0:12,1:50-52,1:70". |
| 88 | +- If processor affinity is disabled by setting `System.GC.NoAffinitize` to `true`, this setting is ignored. |
| 89 | +- Applies to server garbage collection (GC) only. |
| 90 | +- For more information, see [Making CPU configuration better for GC on machines with > 64 CPUs](https://devblogs.microsoft.com/dotnet/making-cpu-configuration-better-for-gc-on-machines-with-64-cpus/) on Maoni Stephens' blog. |
| 91 | + |
| 92 | +| | Setting name | Values | Version introduced | |
| 93 | +| - | - | - | - | |
| 94 | +| **runtimeconfig.json** | `System.GC.GCHeapAffinitizeRanges` | Comma-separated list of processor numbers or ranges of processor numbers.<br/>Unix example: "1-10,12,50-52,70"<br/>Windows example: "0:1-10,0:12,1:50-52,1:70" | .NET Core 1.0 | |
| 95 | +| **Environment variable** | `COMPlus_GCHeapAffinitizeRanges` | Comma-separated list of processor numbers or ranges of processor numbers.<br/>Unix example: "1-10,12,50-52,70"<br/>Windows example: "0:1-10,0:12,1:50-52,1:70" | .NET Core 1.0 | |
| 96 | +| **app.config for .NET Framework** | N/A | N/A | N/A | |
| 97 | + |
| 98 | +### COMPlus_GCCpuGroup |
| 99 | + |
| 100 | +- Configures whether the garbage collector uses [CPU groups](/windows/win32/procthread/processor-groups) or not. |
| 101 | + |
| 102 | + When a 64-bit Windows computer has multiple CPU groups, that is, there are more than 64 processors, enabling this element extends garbage collection across all CPU groups. The garbage collector uses all cores to create and balance heaps. |
| 103 | + |
| 104 | +- Applies to server garbage collection (GC) on 64-bit Windows operation systems only. |
| 105 | +- Default: Disabled (0). |
| 106 | +- For more information, see [Maoni Stephens' blog entry](https://devblogs.microsoft.com/dotnet/making-cpu-configuration-better-for-gc-on-machines-with-64-cpus/). |
| 107 | + |
| 108 | +| | Setting name | Values | Version introduced | |
| 109 | +| - | - | - | - | |
| 110 | +| **runtimeconfig.json** | N/A | N/A | N/A | |
| 111 | +| **Environment variable** | `COMPlus_GCCpuGroup` | 0 - disabled<br/>1 - enabled | .NET Core 1.0 | |
| 112 | +| **app.config for .NET Framework** | [GCCpuGroup](../../framework/configure-apps/file-schema/runtime/gccpugroup-element.md) | `false` - disabled<br/>`true` - enabled | | |
| 113 | + |
| 114 | +### System.GC.NoAffinitize/COMPlus_GCNoAffinitize |
| 115 | + |
| 116 | +- Specifies whether to affinitize garbage collection threads with processors. That is, whether to create a dedicated heap, GC thread, and background GC thread (if background garbage collection is enabled) for each processor. |
| 117 | +- Applies to server garbage collection (GC) only. |
| 118 | +- Default: Affinitize garbage collection threads with processors (`false`). |
| 119 | + |
| 120 | +| | Setting name | Values | Version introduced | |
| 121 | +| - | - | - | - | |
| 122 | +| **runtimeconfig.json** | `System.GC.NoAffinitize` | `false` - affinitize<br/>`true` - don't affinitize | .NET Core 3.0 | |
| 123 | +| **Environment variable** | `COMPlus_GCNoAffinitize` | 0 - affinitize<br/>1 - don't affinitize | .NET Core 3.0 | |
| 124 | +| **app.config for .NET Framework** | [GCNoAffinitize](../../framework/configure-apps/file-schema/runtime/gcnoaffinitize-element.md) | `false` - affinitize<br/>`true` - don't affinitize | 4.6.2 | |
| 125 | + |
| 126 | +### System.GC.HeapHardLimit/COMPlus_GCHeapHardLimit |
| 127 | + |
| 128 | +- Specifies the maximum commit size, in bytes, for the GC heap. |
| 129 | +- The value can range from 0 to 18,446,744,073,709,551,615. |
| 130 | + |
| 131 | +| | Setting name | Values | Version introduced | |
| 132 | +| - | - | - | - | |
| 133 | +| **runtimeconfig.json** | `System.GC.HeapHardLimit` | *decimal value* | .NET Core 3.0 | |
| 134 | +| **Environment variable** | `COMPlus_GCHeapHardLimit` | *decimal value* | .NET Core 3.0 | |
| 135 | + |
| 136 | +### System.GC.HeapHardLimitPercent/COMPlus_GCHeapHardLimitPercent |
| 137 | + |
| 138 | +- Specifies the GC heap usage as a percentage of the total memory. |
| 139 | +- Example value: 25 |
| 140 | + |
| 141 | +| | Setting name | Values | Version introduced | |
| 142 | +| - | - | - | - | |
| 143 | +| **runtimeconfig.json** | `System.GC.HeapHardLimitPercent` | *percentage* | .NET Core 3.0 | |
| 144 | +| **Environment variable** | `COMPlus_GCHeapHardLimitPercent` | *percentage* | .NET Core 3.0 | |
| 145 | + |
| 146 | +### System.GC.RetainVM/COMPlus_GCRetainVM |
| 147 | + |
| 148 | +- Configures whether segments that should be deleted are put on a standby list for future use or are released back to the operating system (OS). |
| 149 | +- Default: Release segments back to the operating system (`false`). |
| 150 | + |
| 151 | +| | Setting name | Values | Version introduced | |
| 152 | +| - | - | - | - | |
| 153 | +| **runtimeconfig.json** | `System.GC.RetainVM` | `false` - release to OS<br/>`true` - put on standby| .NET Core 1.0 | |
| 154 | +| **Environment variable** | `COMPlus_GCRetainVM` | 0 - release to OS<br/>1 - put on standby | .NET Core 1.0 | |
| 155 | + |
| 156 | +## Large pages |
| 157 | + |
| 158 | +### COMPlus_GCLargePages |
| 159 | + |
| 160 | +- Specifies whether large pages should be used when a heap hard limit is set. |
| 161 | +- Default: Disabled (0). |
| 162 | +- This is an experimental setting. |
| 163 | + |
| 164 | +| | Setting name | Values | Version introduced | |
| 165 | +| - | - | - | - | |
| 166 | +| **runtimeconfig.json** | N/A | N/A | N/A | |
| 167 | +| **Environment variable** | `COMPlus_GCLargePages` | 0 - disabled<br/>1 - enabled | .NET Core 1.0 | |
| 168 | +| **app.config for .NET Framework** | N/A | N/A | N/A | |
| 169 | + |
| 170 | +## Large objects |
| 171 | + |
| 172 | +### COMPlus_gcAllowVeryLargeObjects |
| 173 | + |
| 174 | +- Configures garbage collector support on 64-bit platforms for arrays that are greater than 2 gigabytes (GB) in total size. |
| 175 | +- Default: Enabled (1). |
| 176 | +- This option may become obsolete in a future version of .NET. |
| 177 | + |
| 178 | +| | Setting name | Values | Version introduced | |
| 179 | +| - | - | - | - | |
| 180 | +| **runtimeconfig.json** | N/A | N/A | N/A | |
| 181 | +| **Environment variable** | `COMPlus_gcAllowVeryLargeObjects` | 1 - enabled<br/> 0 - disabled | .NET Core 1.0 | |
| 182 | + |
| 183 | +## Large object heap threshold |
| 184 | + |
| 185 | +### System.GC.LOHThreshold/COMPlus_GCLOHThreshold |
| 186 | + |
| 187 | +- Specifies the threshold size, in bytes, that causes objects to go on the large object heap (LOH). |
| 188 | + |
| 189 | +| | Setting name | Values | Version introduced | |
| 190 | +| - | - | - | - | |
| 191 | +| **runtimeconfig.json** | `System.GC.LOHThreshold` | *size in bytes* | .NET Core 1.0 | |
| 192 | +| **Environment variable** | `COMPlus_GCLOHThreshold` | *size in bytes* | .NET Core 1.0 | |
| 193 | + |
| 194 | +## Standalone GC |
| 195 | + |
| 196 | +### COMPlus_GCName |
| 197 | + |
| 198 | +- Specifies a path to the library containing the garbage collector that the runtime intends to load. |
| 199 | +- For more information, see [Standalone GC loader design](https://github.com/dotnet/coreclr/blob/master/Documentation/design-docs/standalone-gc-loading.md). |
| 200 | + |
| 201 | +| | Setting name | Values | Version introduced | |
| 202 | +| - | - | - | - | |
| 203 | +| **runtimeconfig.json** | N/A | N/A | N/A | |
| 204 | +| **Environment variable** | `COMPlus_GCName` | *string_path* | .NET Core 1.0 | |
0 commit comments