Windows 7/Windows Server 2008 R2 が 256 プロセッサまでしか "対応" しない理由を予想する

最大CPU数が4096、最大ノード数が512まで拡大されました。

Windows7 の 256 プロセッサ対応は全然負けてるねw

x86の最大CPU数、最大ノード数が拡大

最大CPU数が4096、最大ノード数が512まで拡大されました。当面はSGIx86_64スパコンくらいでしか意味がなさそうですが、カーネルデベロッパーから見ると、事実上、cpumask_t変数をスタックに置くことが全面禁止になってしまったことを意味します(スタックが4Kbytesしかないのに、1変数あたり512bytesの変数を置くなんて……)

そういえば,昨晩の WinHEC 2008 2日目のキーノートで,Windows Server 2008 R2 を使った 256 CPUs デモが行われていた.

デモは 37 分辺りから始まる.HP の Itanium サーバで,64 物理CPU × 2 (Core/物理CPU) × 2 (論理CPU/Core) の 256 論理 CPU だそうだ.詳しくは以下の transcript を参照されたい.

BILL LAING: What about Itanium? This system here is an HP system. Itanium is supported in Windows Server 2008 R2, and we've really focused our support on Itanium for these large-scale database workloads. We also have other features, such as dynamic hardware partitioning, also available with this kind of system. Our great partnership with HP, as I mentioned before, has enabled us to scale up to 256 logical processors in the Itanium Edition.

So this system you see here, the two cabinets, is the 64 processors, each processor has two cores, and each core has two threads. So that gives us 64 times 2, times 2, which is 256. So 256 logical processors, it also supports up to two terabytes of main memory. So if you thought the task manager with 192 cores looked busy, let's have a look at the superdome console. So now we're seeing the 256 processors, but I think we need a bigger screen. Maybe we'll ask for this one next time, right.

QUENTIN CLARK: You'll have to make every IT administrative console abut 20-feet wide.

ちなみにタスクマネージャはこんな感じになっていた.

仮に 4096 プロセッサに "対応" するとしたら,タスクマネージャも抜本的に手を入れる必要がありそうだ.
さて,Windows 7/Windows Server 2008 R2 が 256 プロセッサより多くのプロセッサに "対応" しない理由は何だろうか?
これは推測するしかないが,そのひとつは検証可能性と考えられる.
Mark Russinovich は,64-bit Windows Server 2008 Datacenter が "サポート" する最大メモリ量が 2TB である理由として,それが Microsoft でテスト可能な最大値だったからと述べている.

The maximum 2TB limit of 64-bit Windows Server 2008 Datacenter doesn't come from any implementation or hardware limitation, but Microsoft will only support configurations they can test.

As of the release of Windows Server 2008, the largest system available anywhere was 2TB and so Windows caps its use of physical memory there.

どうやら Microsoft は自社でテストできていないサイズのメモリ構成を "サポート" する気がなく,恐らくこれは CPU についても当てはまるだろう.そして 256 プロセッサは上記デモのように既に実機動作が行われており,次期 OS 出荷までにそのテストが終了すれば,Microsoft はきっと Windows 7/Windows Server 2008 R2 で 256 プロセッサを "サポート" するだろう.
それでは 256 論理 CPU を超える構成のハードウェアがすぐに出荷される可能性はないのだろうか?
これに関しては,PDC 2008 のセッションにヒントがあった.

Interrupt Addressing

  • xAPIC has been meeting interrupt architecture needs since P4, for Intel Architecture
    • 8 bit APIC ID addresses
    • Physical addresses limited to 0 – 254 APIC IDs
    • Logical addresses limited to 60 processors
    • Flat addresses limited to 8 processors
  • Nehalem processors require 16 APIC IDs per socket for 8 processors
    • Interrupt addressing strained on Nehalem platforms
    • xAPIC can address only up to 8 socket Nehalem
    • Only 128 processors
  • Next Generation Interrupt Architecture allows scaling to 256 processors on Nehalem platforms

つまり,(Intel の) 論理 CPU 数はハードウェア的な制約に縛られており,Intel の次世代割り込み機構で到達可能なのが高々 256 プロセッサということらしい.
先ほどの検証可能性の仮定と合わせて考えると,Windows が 256 より多くのプロセッサに "対応" するのには,まだしばらく時間がかかると言えそうだ.
(以下,コメントでのご指摘を受けて修正)
上記 PPT によれば,サポート可能な論理 CPU 数は主に APIC によって制約を受けており,x2APIC と Nehalem プラットフォームの組み合わせでは 256 プロセッサ (論理スレッド?) までスケールするらしい (ここは Intel 発のソースを見つけられなかったので注意して欲しい).
一方 Itanium の方はラジカルであり,Intel のページ によれば Itanium 9000 番台で既にハードウェア的には 512 ソケット,メモリ 1 PB まで行けるらしい.実際,Linux を使った NUMA 構成では,SGI Altix 4700 というデュアルコア Itanium を 512 ソケット載せた製品が既にあるそうだ(メモリは 128TB までらしい).冒頭の Linux カーネルの話に出てきた 最大ノード数 512 というのは,この環境のことと考えれば辻褄が合う.また,Linux カーネルの最大 CPU 数 4096 というのは,この環境に Quad Core Itanium (Tukwila) を載せたときの数字になる.(Core が各 4 つの SMT で ×2)

余談: アフィニティマスクと互換性

従来,Windows では CPU アフィニティをビットフラグで管理してきた.

BOOL WINAPI SetProcessAffinityMask(
  __in  HANDLE hProcess,
  __in  DWORD_PTR dwProcessAffinityMask
);

しかし,DWORD_PTR では 64-bit 環境でも高々 64 プロセッサまでしかマスク値を設定することができない.一方で,64 プロセッサを超える環境でも,SetProcessAffinityMask を利用している過去のアプリケーションが問題なく実行できなければならない.このような条件を満たす新しい API が必要となった.
先ほどの『Developing Applications for More Than 64 Logical Processors in Windows Server 2008 R2』によれば,Windows 7/Windows Server 2008 R2 では 64 論理 CPU をひとつの "グループ" と定義し,プロセスは初期状態で "グループ" のどれかに束縛されている(どのグループに属するかはラウンドロビンで決定される).そして,新しく定義された API で明示的に許可を与えない限り,プロセス内のスレッドは所属 "グループ" の CPU でのみ実行される.
つまり,新しい CPU グループ制御 API を使用しない限り,ひとつのプロセスは高々 64 個のプロセッサしか活用しない.かくして,SetProcessAffinityMask を使用する過去のアプリケーションの互換性は維持されるとのことだ.