文章出處

不均勻的Windows處理器編組

之前寫過一篇文章,關于SQLSERVER能識別多少個邏輯CPU的,前些天在論壇里有人問Windows處理器編組是如何劃分的??

SQLSERVER到底能識別多少個邏輯CPU?

在帖子給出了兩篇文章,我們現在來看一下

http://social.technet.microsoft.com/Forums/zh-CN/17f34500-08d5-4302-a484-3ce487899a83/windows-2008-r2sql-server-2005cpu?forum=sqlserverzhchs

Uneven Windows Processor Groups

SQL Server 2005 and 2008 versions may not detect all available processors on a machine with more than 64 logical processors


Uneven Windows Processor Groups(不均勻的處理器編組)

這篇文章主要討論64個邏輯cpu的硬件。

我們討論Windows 2008R2  他支持64個邏輯處理器。當前可用的硬件是8個核的物理處理器/socket接口。

盡管加上超線程,那么意味著是16個邏輯cpu。每一個socket接口形成一個或兩個NUMA節點。4個或8個邏輯cpu形成一個處理器編組。

處理器編組的分配是在操作系統啟動的時候分配好的。因為這個原因,Windows2008R2 和之后的Windows操作系統會檢查物理硬件架構為了

分配跟NUMA節點相對應的處理器編組,并且檢查內存延時,為了決定分配哪一個邏輯cpu到哪一個處理器編組。一旦分配完成,就不能再動態更改!

這樣的分配工作只會發生在超過64個邏輯cpu的硬件架構。在典型的8-socket服務器,資源和內存的分布通常是不均勻的,在不同的處理器編組之間

(除了一些在2009年和2010年的時候一些市場上出現的96個邏輯cpu的奇怪的硬件)

 

已經開發好的軟件面對處理器編組這個概念會發生什么?在大于64個邏輯cpu的時候,軟件會怎樣選擇不同的邏輯處理器

實際上,Windows會在應用程序啟動的時候分配其中一個處理器編組給它。應用程序會檢查64邏輯cpu窗口是否在運行。

然而應用程序會檢查完整的內存資源。典型的應用程序會被調度到其中一個處理器編組。

 

只要處理器編組有均勻的分布和軟件不需要依賴某些NUMA節點的可用性,一切都很好。

 

 

然而,這個平衡受到英特爾發布的最新版本的Intel Xeon E7處理器核心家族的( 10和20邏輯處理器)的影響

顯然,核心的數量和邏輯處理器的數量加起來不太好對于64核cpus。在我的博客里,我已經列出了我討論的

處理器影響到SQLSERVER服務器關聯掩碼的設置。

 

到目前位置我們并沒有討論到Windows2008R2是如何分配4-socket服務器上的80個邏輯處理器或一個8-socket服務器上的160個邏輯處理器的情況。

Windows2008R2的原來算法實現就是創建盡可能少的處理器編組并且保持每個處理器編組里的處理器數量盡可能足夠大。

因此我們使用這些新的10-core處理器最終會造成處理器編組的不均勻,讓我們看看發生了什么事。

 

 

檢測當前的處理器編組信息

為了檢測Windows2008R2上面的確切的處理器編組的信息,硬件通常需要編出超過64個邏輯CPU的線程。執行檢查的工具的名字叫“coreinfo ”

下載地址:http://technet.microsoft.com/en-us/sysinternals/cc835722.aspx

下載地址:http://files.cnblogs.com/lyhabc/Coreinfo.zip

 

 

 

請下載coreinfo .exe然后在cmd窗口里運行它。

最好使用下面語句將coreinfo的信息輸出到文本文件以便分析

coreinfo > structure.txt

 structure.txt文件內容

Intel(R) Pentium(R) CPU G630 @ 2.70GHz
Intel64 Family 6 Model 42 Stepping 7, GenuineIntel
HTT           *    Hyperthreading enabled
HYPERVISOR    -    Hypervisor is present
VMX           *    Supports Intel hardware-assisted virtualization
SVM           -    Supports AMD hardware-assisted virtualization
EM64T         *    Supports 64-bit mode

SMX           -    Supports Intel trusted execution
SKINIT        -    Supports AMD SKINIT

NX            *    Supports no-execute page protection
SMEP          -    Supports Supervisor Mode Execution Prevention
SMAP          -    Supports Supervisor Mode Access Prevention
PAGE1GB       -    Supports 1 GB large pages
PAE           *    Supports > 32-bit physical addresses
PAT           *    Supports Page Attribute Table
PSE           *    Supports 4 MB pages
PSE36         *    Supports > 32-bit address 4 MB pages
PGE           *    Supports global bit in page tables
SS            *    Supports bus snooping for cache operations
VME           *    Supports Virtual-8086 mode
RDWRFSGSBASE    -    Supports direct GS/FS base access

FPU           *    Implements i387 floating point instructions
MMX           *    Supports MMX instruction set
MMXEXT        -    Implements AMD MMX extensions
3DNOW         -    Supports 3DNow! instructions
3DNOWEXT      -    Supports 3DNow! extension instructions
SSE           *    Supports Streaming SIMD Extensions
SSE2          *    Supports Streaming SIMD Extensions 2
SSE3          *    Supports Streaming SIMD Extensions 3
SSSE3         *    Supports Supplemental SIMD Extensions 3
SSE4a         -    Supports Sreaming SIMDR Extensions 4a
SSE4.1        *    Supports Streaming SIMD Extensions 4.1
SSE4.2        *    Supports Streaming SIMD Extensions 4.2

AES           -    Supports AES extensions
AVX           -    Supports AVX intruction extensions
FMA           -    Supports FMA extensions using YMM state
MSR           *    Implements RDMSR/WRMSR instructions
MTRR          *    Supports Memory Type Range Registers
XSAVE         *    Supports XSAVE/XRSTOR instructions
OSXSAVE       *    Supports XSETBV/XGETBV instructions
RDRAND        -    Supports RDRAND instruction
RDSEED        -    Supports RDSEED instruction

CMOV          *    Supports CMOVcc instruction
CLFSH         *    Supports CLFLUSH instruction
CX8           *    Supports compare and exchange 8-byte instructions
CX16          *    Supports CMPXCHG16B instruction
BMI1          -    Supports bit manipulation extensions 1
BMI2          -    Supports bit manipulation extensions 2
ADX           -    Supports ADCX/ADOX instructions
DCA           -    Supports prefetch from memory-mapped device
F16C          -    Supports half-precision instruction
FXSR          *    Supports FXSAVE/FXSTOR instructions
FFXSR         -    Supports optimized FXSAVE/FSRSTOR instruction
MONITOR       *    Supports MONITOR and MWAIT instructions
MOVBE         -    Supports MOVBE instruction
ERMSB         -    Supports Enhanced REP MOVSB/STOSB
PCLULDQ       *    Supports PCLMULDQ instruction
POPCNT        *    Supports POPCNT instruction
LZCNT         -    Supports LZCNT instruction
SEP           *    Supports fast system call instructions
LAHF-SAHF     *    Supports LAHF/SAHF instructions in 64-bit mode
HLE           -    Supports Hardware Lock Elision instructions
RTM           -    Supports Restricted Transactional Memory instructions

DE            *    Supports I/O breakpoints including CR4.DE
DTES64        *    Can write history of 64-bit branch addresses
DS            *    Implements memory-resident debug buffer
DS-CPL        *    Supports Debug Store feature with CPL
PCID          *    Supports PCIDs and settable CR4.PCIDE
INVPCID       -    Supports INVPCID instruction
PDCM          *    Supports Performance Capabilities MSR
RDTSCP        *    Supports RDTSCP instruction
TSC           *    Supports RDTSC instruction
TSC-DEADLINE    *    Local APIC supports one-shot deadline timer
TSC-INVARIANT    *    TSC runs at constant rate
xTPR          *    Supports disabling task priority messages

EIST          *    Supports Enhanced Intel Speedstep
ACPI          *    Implements MSR for power management
TM            *    Implements thermal monitor circuitry
TM2           *    Implements Thermal Monitor 2 control
APIC          *    Implements software-accessible local APIC
x2APIC        -    Supports x2APIC

CNXT-ID       -    L1 data cache mode adaptive or BIOS

MCE           *    Supports Machine Check, INT18 and CR4.MCE
MCA           *    Implements Machine Check Architecture
PBE           *    Supports use of FERR#/PBE# pin

PSN           -    Implements 96-bit processor serial number

PREFETCHW     *    Supports PREFETCHW instruction

Maximum implemented CPUID leaves: 0000000D (Basic), 80000008 (Extended).

Logical to Physical Processor Map:
*-  Physical Processor 0
-*  Physical Processor 1

Logical Processor to Socket Map:
**  Socket 0

Logical Processor to NUMA Node Map:
**  NUMA Node 0

Logical Processor to Cache Map:
*-  Data Cache          0, Level 1,   32 KB, Assoc   8, LineSize  64
*-  Instruction Cache   0, Level 1,   32 KB, Assoc   8, LineSize  64
*-  Unified Cache       0, Level 2,  256 KB, Assoc   8, LineSize  64
-*  Data Cache          1, Level 1,   32 KB, Assoc   8, LineSize  64
-*  Instruction Cache   1, Level 1,   32 KB, Assoc   8, LineSize  64
-*  Unified Cache       1, Level 2,  256 KB, Assoc   8, LineSize  64
**  Unified Cache       2, Level 3,    3 MB, Assoc  12, LineSize  64

Logical Processor to Group Map:
**  Group 0
View Code

 

打開文件,你會看到類似于下面的section ,通常結果是在最后一個section 。這個section 叫 ‘Logical Processor to Group Map’. 

有80 邏輯cpu的機器的結果通常是這樣:

 

 

 

The result of a server with 80 LOGICAL PROCESSOR threads might look like:

Group 0:

************************************************************ 
--------------------

Group 1:

------------------------------------------------------------ 
********************

這個‘*’星字符符號的數量代表當前處理器編組中有多少個邏輯cpu。

符號“-”代表著一個邏輯處理器線程不是處理器組的一部分。

因此,上面的內容告訴我們處理器編組0里有60個邏輯cpu,而處理器編組1只有20個邏輯cpu。

 

 

160個邏輯cpu的硬件的結果會是這樣

Logical Processor to Group Map:

Group 0:

************************************************************ 
------------------------------------------------------------ 
----------------------------------------

Group 1:

------------------------------------------------------------ 
************************************************************ 
----------------------------------------

Group 2:

------------------------------------------------------------ 
------------------------------------------------------------ 
****************************************

可以看到三個處理器編組中,有兩個處理器編組有60個邏輯cpu,而第三個處理器編組只有40個邏輯cpu

 

 我的臺式機,雙核AMDcpu,處理器編組只有一個,處理器編組中只有2個邏輯cpu

Logical Processor to Group Map:
** Group 0

 

 

不均勻的處理器編組帶來的問題

遇到處理器編組不均勻的情況,應用程序有可能會分到第一個處理器編組,也有可能被分到第二個處理器編組。

重啟應用程序有可能會被分配到跟剛才的處理器編組不一樣的處理器編組,有可能會被分到邏輯cpu比較多的處理器編組也有可能是比較少邏輯cpu的

那個處理器編組。分到不同的處理器編組會導致應用程序在不同的負載下有不同的行為。

 

對于SAP軟件和SQLSERVER為了獲得可預計的性能,我們建議配置Windows2008R2創建處理器編組的時候都有相同數量的邏輯cpu。

 為了配置,Windows開發人員改變了處理器編組的算法在QFE 里面。

 

獲得分配均勻的處理器編組

最容易獲得均勻分配的處理器編組的方法是獲取微軟在2011年三月份發布的QFE 

QFE 的信息和微軟相關知識庫文章可以在這里找到:http://support.microsoft.com/kb/2510206

當構建處理器編組的時候QFE 會改變策略。目的是構建相同size的處理器編組。例如:在由英特爾Xeon  E7 家族(10核心超線程)4核或8核的處理器硬件里

我們能夠檢測到在40個邏輯處理器里,處理器編組可能會有2個或4個。如果是兩個,那么每個處理器編組會有20個邏輯處理器,如果是四個,那么每個處理器編組

會有10個邏輯處理器。

 

在下一代Windows(可能是Windows2012)里會默認使用這個新的策略

 

更多信息請參考:OSS note #1635387 – Windows Processor Groups


SQLSERVER2005和SQLSERVER2008有可能不會檢測到可用的處理器在一個超過64個邏輯cpu的機器上

SQL Server 2005 and 2008 versions may not detect all available processors on a machine with more than 64 logical processors

 

http://blogs.msdn.com/b/pamitt/archive/2011/11/02/sql-server-2005-and-2008-versions-may-not-detect-all-available-processors-on-a-machine-with-more-than-64-logical-processors.aspx

 

場景:我最近遇到一個場景SQL2005實例安裝在Windows2008R2上面,在開啟了超線程之后不能檢測到所有可用的邏輯處理器。

機器有4socket接口,每個socket接口有一個NUMA節點,每個socket有10個核心,所以一共有40核心。沒有開啟超線程,SQLSERVER能檢測到40個邏輯cpu

然而,開啟了超線程之后,只能檢測到20個邏輯cpu,盡管一共有80個邏輯cpu可用。

下面是在開啟和關閉超線程的時候,SQLSERVER的錯誤日志

 

With Hyperthreading turned OFF

2011-10-27 12:37:32.74 Server      Detected 40 CPUs. This is an informational message; no user action is required.

2011-10-27 12:37:32.94 Server      Large Page Extensions enabled.

2011-10-27 12:37:32.94 Server      Large Page Granularity: 2097152

2011-10-27 12:37:32.98 Server      Large Page Allocated: 32MB

2011-10-27 12:37:33.03 Server      Large Page Allocated: 32MB

2011-10-27 12:37:33.42 Server      Using locked pages for buffer pool.

2011-10-27 12:37:33.79 Server      Large Page Allocated: 32MB

2011-10-27 12:37:33.90 Server      Large Page Allocated: 32MB

2011-10-27 12:37:34.17 Server      Using dynamic lock allocation.  Initial allocation of 2500 Lock blocks and 5000 Lock Owner blocks per node.  This is an informational message only.  No user action is required.

2011-10-27 12:37:34.19 Server      Lock partitioning is enabled.  This is an informational message only. No user action is required.

2011-10-27 12:37:34.53 Server      Multinode configuration: node 0: CPU mask: 0x00000000000ffc00 Active CPU mask: 0x00000000000ffc00. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required.

2011-10-27 12:37:34.60 Server      Multinode configuration: node 1: CPU mask: 0x00000000000003ff Active CPU mask: 0x00000000000003ff. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required.

2011-10-27 12:37:34.65 Server      Multinode configuration: node 2: CPU mask: 0x000000003ff00000 Active CPU mask: 0x000000003ff00000. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required.

2011-10-27 12:37:34.70 Server      Multinode configuration: node 3: CPU mask: 0x000000ffc0000000 Active CPU mask: 0x000000ffc0000000. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required

With Hyperthreading turned ON

2011-10-27 13:13:50.31 Server     Detected 20 CPUs. This is an informational message; no user action is required.

2011-10-27 13:13:50.48 Server      Large Page Extensions enabled.

2011-10-27 13:13:50.48 Server      Large Page Granularity: 2097152

2011-10-27 13:14:04.68 Server      Large Page Allocated: 32MB

2011-10-27 13:14:07.87 Server      Using locked pages for buffer pool.

2011-10-27 13:14:12.25 Server      Using dynamic lock allocation.  Initial allocation of 2500 Lock blocks and 5000 Lock Owner blocks per node.  This is an informational message only.  No user action is required.

2011-10-27 13:14:12.28 Server      Lock partitioning is enabled.  This is an informational message only. No user action is required.

 

原因和解釋:一個新的概念在Windows2008R2里叫做:“處理器編組”。

SQLSERVER2008,SQLSERVER2005因為這個處理器編組會引發一些問題。

 

什么是處理器編組:在Windows2008R2里面是支持超過64個邏輯cpu的根據處理器編組的概念,處理器編組是一組64邏輯cpu,處理器編組是一個靜態的編組

他將64個邏輯處理器視為同一個單獨的調度實體。處理器編組是從0開始的,如果系統的邏輯cpu個數小于64個,那么就只有一個處理器編組: Group 0。

操作系統會最小化處理器編組的數量。例如:在一個有128個邏輯處理器的cpu里會有兩個處理器編組,每個處理器編組會有64個邏輯處理器,而不是

每個處理器編組32個邏輯處理器。處理器編組是一個新概念在Windows2008R2里面它不支持Windows2008,Windows vista和Windows2003

 

為什么處理器編組影響了SQLSERVER2005和SQLSERVER2008實例了?跟著下面的3個因素你就會知道怎樣影響到SQLSERVER

SQL2005和SQL2008是先于Windows2008R2發布的,因此這些版本的SQLSERVER不會利用到Windows2008R2的新的API,

去獲得處理器編組的優勢。

在一個大于64個邏輯處理器的系統上,Windows2008R2會構建不均勻的處理器編組,這是因為在Windows2008R2最初的算法實現上,

會創建盡可能小的處理器編組并且保持獨立的處理器編組足夠大。如果機器只有<=64個邏輯cpu,那沒有什么問題,這時候只會有一個處理器編組.

然而,如果機器有超過64個邏輯cpu,Windows2008R2會創建超過一個的處理器編組,SQLSERVER2005/2008會束縛于某一個處理器編組,

當SQLSERVER重啟的時候。在我們的場景,在開啟超線程之后,機器會有80個邏輯cpu和4個NUMA節點,每一個處理器編組就有兩個NUMA節點

在Windows2008R2操作系統里。

 

第一個處理器編組有3個NUMA節點,因此第一個處理器編組會有60邏輯處理器,而第二個處理器編組只有一個NUMA節點,二十個邏輯處理器。

當SQLSERVER實例重啟的時候,SQLSERVER被束縛到第二個處理器編組,即20個邏輯處理器

Windows2008R2會隨機分配應用程序到某一個處理器編組

 

 

變通方案和解決辦法:

要想全部利用超過64個邏輯處理器,那么你必須將SQLSERVER升級到SQLSERVER2008R2

如何逼使SQLSERVER使用最大邏輯cpu數量的那個處理器編組?

例如:在一個有96cpus的機器上,你有兩個處理器編組,編組1有64個邏輯cpus,編組2有32個邏輯cpus。如果你有SQLSERVER2005/2008

企業版,你可以使用sc.exe工具根據這篇文章去做:this blog article

如何解決非均勻的處理器編組,可以應用Windows2008R2 補丁 KB 2510206

如何手動指定使用哪一個NUMA節點,可以參考這篇知識庫文章:SQL Server on Windows 7 / Windows 2008 R2 with more than 64 CPUs

 

更多的參考文章

Additional References:


總結

使用最新版的SQLSERVER,如果遇到CPU性能問題,你可以檢查一下SQLSERVER當前利用的邏輯CPU數量

當然,你的機器配置需要超過64個邏輯處理器

 

如有不對的地方,歡迎大家拍磚o(∩_∩)o 


文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()