Skip to content

Instantly share code, notes, and snippets.

@unchama
Last active December 31, 2024 04:51
Show Gist options
  • Save unchama/bc9f945f1e2ee8dce43c4c8a79a1706e to your computer and use it in GitHub Desktop.
Save unchama/bc9f945f1e2ee8dce43c4c8a79a1706e to your computer and use it in GitHub Desktop.
AMD/Intel CPU間での安全なライブマイグレーションの検証

AMD/Intel CPU間での安全なライブマイグレーションの検証

概要

  • ゲストOSのCPU modelをクラスタ内のホストCPUのラインナップに応じて適切に選定してやることよって特定のホストCPUにしかない命令セットをゲストVMから隠蔽すれば安全にマイグレーションできる説
  • なおデフォルトのkvm64でもある程度大丈夫っぽい記載があるが、ぼくの経験上うまくいった試しがあまりない
    • でもドキュメント上は Compatible with Intel CPU >= Pentium 4, AMD CPU >= Phenom とあるので、一番安全そうに見えるが。別原因でこけてただけなのかなあ。
  • だいたいダメな時はマイグレーション後数十分後にフリーズしてることがよくあるように思う。マイグレーション後のホストCPUにない命令セット触った時にオワるんだろうか

ABI compatibility levels for CPU models

The x86_64 architecture has a number of ABI compatibility levels defined. Traditionally most operating systems and toolchains would only target the original baseline ABI. It is expected that in future OS and toolchains are likely to target newer ABIs. The table that follows illustrates which ABI compatibility levels can be satisfied by the QEMU CPU models. Note that the table only lists the long term stable CPU model versions (eg Haswell-v4). In addition to what is listed, there are also many CPU model aliases which resolve to a different CPU model version, depending on the machine type is in use.

x86_64アーキテクチャには、いくつかのABI(アプリケーションバイナリインターフェース)互換性レベルが定義されています。従来、多くのオペレーティングシステムやツールチェインは、元々のベースラインABIのみをターゲットとしていましたが、将来的には新しいABIをターゲットとするオペレーティングシステムやツールチェインが増えると予想されています。以下の表は、QEMUのCPUモデルがどのABI互換性レベルに対応しているかを示しています。この表では、長期的に安定したCPUモデルバージョン(例:Haswell-v4)のみがリストされています。なお、記載されているものに加え、マシンタイプに応じて異なるCPUモデルバージョンに解決されるCPUモデルエイリアスも多数存在します。

https://www.qemu.org/docs/master/system/i386/cpu.html

ABIはオブジェクトコードレベルのインタフェースであり、互換ABIをサポートするシステム間では同じ実行ファイルを変更無しで動作させることができる。

https://ja.wikipedia.org/wiki/%E3%82%A2%E3%83%97%E3%83%AA%E3%82%B1%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%83%90%E3%82%A4%E3%83%8A%E3%83%AA%E3%82%A4%E3%83%B3%E3%82%BF%E3%83%95%E3%82%A7%E3%83%BC%E3%82%B9

Historically, Proxmox VE had the kvm64 CPU model, with CPU flags at the level of Pentium 4 enabled, so performance was not great for certain workloads.

In the summer of 2020, AMD, Intel, Red Hat, and SUSE collaborated to define three x86-64 microarchitecture levels on top of the x86-64 baseline, with modern flags enabled. For details, see the x86-64-ABI specification.

kvm64 (x86-64-v1): Compatible with Intel CPU >= Pentium 4, AMD CPU >= Phenom.

x86-64-v2: Compatible with Intel CPU >= Nehalem, AMD CPU >= Opteron_G3. Added CPU flags compared to x86-64-v1: +cx16, +lahf-lm, +popcnt, +pni, +sse4.1, +sse4.2, +ssse3.

x86-64-v2-AES: Compatible with Intel CPU >= Westmere, AMD CPU >= Opteron_G4. Added CPU flags compared to x86-64-v2: +aes.

x86-64-v3: Compatible with Intel CPU >= Broadwell, AMD CPU >= EPYC. Added CPU flags compared to x86-64-v2-AES: +avx, +avx2, +bmi1, +bmi2, +f16c, +fma, +movbe, +xsave.

x86-64-v4: Compatible with Intel CPU >= Skylake, AMD CPU >= EPYC v4 Genoa. Added CPU flags compared to x86-64-v3: +avx512f, +avx512bw, +avx512cd, +avx512dq, +avx512vl.

https://pve.proxmox.com/pve-docs/chapter-qm.html#_qemu_cpu_types

現在のseichi-networkクラスタに最適なABI Compatibility Levelは?

現在のクラスタ構成

  • 基本戦略は「ホストCPUに無い命令セットをあたかもゲストVMにあるように見せてしまい、ゲストVMがそれを触った瞬間に死ぬ」みたいなノリな気がするので、クラスタ内で一番低いABI Levelを推測したCPUにゲストOSのCPU Modelを合わせて、特定のCPUにしか存在しない命令セットをゲストOSから隠蔽する。
  • CPUモデルからABI Levelを雑に推測。
  • リンク先のリストはほとんどサーバに寄ったモデルラインナップであった。なのでクライアントCPUは同アーキテクチャのサーバCPUとして雑に推測。
  • とはいえサーバ向けCPUにしか搭載されていない命令セットがあったはず(AVX512とか)。IntelCPUはClient向けのモデルが表にあったので一律それと推定してみた。
  • よってもって今回の場合に最適なCPU Modelは x86-64-v3 説。
ホスト名 搭載CPU 世代 推測適合Model ABI Level
unchama-sv-prox01 20 x 13th Gen Intel(R) Core(TM) i5-13500 (1 Socket)(*1) Raptor Lake Skylake-Client-v{1..4} v3
unchama-sv-prox03 16 x AMD Ryzen 7 5700X 8-Core Processor (1 Socket)(*2) Zen3 EPYC-Milan-v{1..2} v3
unchama-sv-prox04 16 x AMD Ryzen 7 8700G w/ Radeon 780M Graphics (1 Socket)(*3) Zen4 EPYC-Genoa-v1 v4
unchama-sv-prox05 20 x 13th Gen Intel(R) Core(TM) i5-13500 (1 Socket)(*1) Raptor Lake Skylake-Client-v{1..4} v3
unchama-sv-prox06 20 x 13th Gen Intel(R) Core(TM) i9-13900H (1 Socket)(*4) Raptor Lake Skylake-Client-v{1..4} v3
unchama-sv-prox07 20 x 13th Gen Intel(R) Core(TM) i9-13900H (1 Socket)(*4) Raptor Lake Skylake-Client-v{1..4} v3
unchama-sv-prox08 20 x 12th Gen Intel(R) Core(TM) i9-12900H (1 Socket)(*5) Alder Lake Skylake-Client-v{1..4} v3

(*1)https://www.intel.co.jp/content/www/jp/ja/products/sku/230580/intel-core-i513500-processor-24m-cache-up-to-4-80-ghz/specifications.html

(*2)https://www.amd.com/en/support/downloads/drivers.html/processors/ryzen/ryzen-5000-series/amd-ryzen-7-5700x.html

(*3)https://www.amd.com/en/products/processors/desktops/ryzen/8000-series/amd-ryzen-7-8700g.html

(*4)https://www.intel.co.jp/content/www/jp/ja/products/sku/232135/intel-core-i913900h-processor-24m-cache-up-to-5-40-ghz/specifications.html

(*5)https://www.intel.co.jp/content/www/jp/ja/products/sku/132214/intel-core-i912900h-processor-24m-cache-up-to-5-00-ghz/specifications.html

検証方法

  • 2つのVMを作成(2vCPU,4GB)
  • CPU Modelを検証したいモデルに設定
  • 起動
  • stress-ngを仕掛けて負荷をかける ここらへんを参照
  • ホストOSのcronとかで定期的にライブマイグレーションをする
    • qm migrateは移行元VMが存在するホストでしか打てないので注意
  • 死活はzabbix-agentで監視
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment