<GCHeapAffinitizeMask > 元素<GCHeapAffinitizeMask> element

定义 GC 堆和单个处理器之间的关联。Defines the affinity between GC heaps and individual processors.

<配置 > <configuration>
  <运行时 >   <runtime>
    <GCHeapAffinitizeMask >    <GCHeapAffinitizeMask>



特性和元素Attributes and elements

下列各节描述了特性、子元素和父元素。The following sections describe attributes, child elements, and parent elements.


特性Attribute 描述Description
enabled 必需的特性。Required attribute.

指定 GC 堆和单个处理器之间的相关性。Specifies the affinity between GC heaps and individual processors.

enabled 属性enabled attribute

“值”Value 描述Description
nnnn 一个十进制值,它构成一个位掩码,用于定义服务器 GC 堆和单个处理器之间的相关性。A decimal value that forms a bitmask defining the affinity between server GC heaps and individual processors.

子元素Child elements


父元素Parent elements

元素Element 描述Description
configuration 公共语言运行时和 .NET Framework 应用程序所使用的每个配置文件中的根元素。The root element in every configuration file used by the common language runtime and .NET Framework applications.
runtime 包含有关程序集绑定和垃圾回收的信息。Contains information about assembly binding and garbage collection.


默认情况下,服务器 GC 线程使用各自的 CPU 进行关联,以便为每个处理器提供一个 GC 堆、一个服务器 GC 线程,以及一个后台服务器垃圾回收线程。By default, server GC threads are hard-affinitized with their respective CPU so that there is one GC heap, one server GC thread, and one background server GC thread for each processor. 从 .NET Framework 4.6.2 开始,当堆数受GCHeapCount元素限制时,可以使用GCHeapAffinitizeMask元素控制服务器 GC 堆与处理器之间的相关性。Starting with .NET Framework 4.6.2, you can use the GCHeapAffinitizeMask element to control the affinity between server GC heaps and processors when the number of heaps is limited by the GCHeapCount element.

GCHeapAffinitizeMask通常与其他两个标志一起使用:GCHeapAffinitizeMask is typically used along with two other flags:

  • GCNoAffinitize,控制服务器 GC 线程/堆是否与 cpu 关联。GCNoAffinitize, which controls whether server GC threads/heaps are affinitized with CPUs. GCNoAffinitize元素的 enabled 属性必须是要使用的GCHeapAffinitizeMask设置的 false (其默认值)。The enabled attribute of the GCNoAffinitize element must be false (its default value) for the GCHeapAffinitizeMask setting to be used.

  • GCHeapCount,用于限制进程用于服务器 GC 的堆数。GCHeapCount, which limits the number of heaps used by the process for server GC. 默认情况下,每个处理器都有一个堆。By default, there is one heap for each processor.

nnnn是以十进制值表示的位掩码。nnnn is a bit mask expressed as a decimal value. 字节0的位0表示处理器0,第1个字节表示处理器1,依此类推。Bit 0 of byte 0 represents processor 0, bit 1 of byte 0 represents processor 1, and so on. 例如:For example:

<GCHeapAffinitizeMask enabled="1023"/>

值1023为0x3FF 或 0011 1111 1111b。A value of 1023 is 0x3FF or 0011 1111 1111b. 此过程使用10个处理器,从处理器0到处理器9。The process uses 10 processors, from processor 0 through processor 9.


下面的示例指示应用程序使用具有10个堆/线程的服务器 GC。The following example indicates that an application uses server GC with 10 heaps/threads. 由于不希望这些堆与系统上运行的其他应用程序中的堆重叠,因此,请使用GCHeapAffinitizeMask指定进程应使用 cpu 0 到9。Since you don't want those heaps to overlap with heaps from other applications running on the system, use GCHeapAffinitizeMask to specify that the process should use CPUs 0 through 9.

      <gcServer enabled="true"/>
      <GCHeapCount enabled="10"/>
      <GCHeapAffinitizeMask enabled="1023"/>

请参阅See also