Libvirt支持的三种CPU模式与热迁移(by Joshua)

https://blog.csdn.net/quqi99/article/details/79495428

问题

原始的nova配置(cpu_mode=“host-passthrough”)导致无法热迁移,改成(cpu_mode=“custom”, cpu_model=“kvm64”)之后解决了热迁移问题但是嵌套虚拟化又不好便了,接着又改成(cpu_mode=‘host-model’)但热迁移仍然失败。有两全其美的方法吗?

解决办法

1, working solution was to create a custom CPU definition in /usr/share/libvirt/cpu_map.xml called SandyBridge-vmx, which contained the full feature flags for that CPU, not just the subset that differs from Westmere/etc., and includes the needed 'vmx' feature for nested kvm
<model name='SandyBridge-vmx'>
<vendor name='Intel'/>
<feature name='aes'/>
<feature name='apic'/>
<feature name='avx'/>
<feature name='clflush'/>
<feature name='cmov'/>
<feature name='cx16'/>
<feature name='cx8'/>
<feature name='de'/>
<feature name='fpu'/>
<feature name='fxsr'/>
<feature name='lahf_lm'/>
<feature name='lm'/>
<feature name='mca'/>
<feature name='mce'/>
<feature name='mmx'/>
<feature name='msr'/>
<feature name='mtrr'/>
<feature name='nx'/>
<feature name='pae'/>
<feature name='pat'/>
<feature name='pclmuldq'/>
<feature name='pge'/>
<feature name='pni'/>
<feature name='popcnt'/>
<feature name='pse'/>
<feature name='pse36'/>
<feature name='rdtscp'/>
<feature name='sep'/>
<feature name='sse'/>
<feature name='sse2'/>
<feature name='sse4.1'/>
<feature name='sse4.2'/>
<feature name='ssse3'/>
<feature name='syscall'/>
<feature name='tsc'/>
<feature name='tsc-deadline'/>
<feature name='x2apic'/>
<feature name='xsave'/>
<feature name='vmx'/>
</model>

2, And in /etc/nova/nova.conf, we use: 
$ sudo grep ^cpu_m /etc/nova/nova.conf
cpu_mode = custom
cpu_model = SandyBridge-vmx

理论

Libvirt主要支持三种 CPU mode:

  1. host-passthrough: libvirt 令 KVM 把宿主机的 CPU 指令集全部透传给虚拟机。因此虚拟机能够最大限度的使用宿主机 CPU 指令集,故性能是最好的。但是在热迁移时,它要求目的节点的 CPU 和源节点的一致。
  2. host-model: libvirt 根据当前宿主机 CPU 指令集从配置文件 /usr/share/libvirt/cpu_map.xml 选择一种最相配的 CPU 型号。在这种 mode 下,虚拟机的指令集往往比宿主机少,性能相对 host-passthrough 要差一点,但是热迁移时,它允许目的节点 CPU 和源节点的存在一定的差异。
  3. custom: 这种模式下虚拟机 CPU 指令集数最少,故性能相对最差,但是它在热迁移时跨不同型号 CPU 的能力最强。此外,custom 模式下支持用户添加额外的指令集。
  4. 三种mode的性能排序是:host-passthrough > host-model > custom
  5. 三种mode的热迁移通用性是: custom > host-model > host-passthrough

实际环境中多采用Intel E5系列的CPU,但是该系列的CPU也有多种型号,常见的有Xeon,Haswell,IvyBridge,SandyBridge等等。即使是host-model,在这些不同型号的CPU之间热迁移虚拟机也可能失败。所以从热迁移的角度,在选择 host-mode时:

  • 需要充分考虑既有宿主机类型,以后采购扩容时,也需要考虑相同问题
  • 除非不存在热迁移的场景,否则不应用选择host-passthrough
  • host-model下不同型号的 CPU 最好能以aggregate hosts划分,在迁移时可以使用aggregate filter来匹配相同型号的物理机
openstack aggregate create Broadwell
openstack aggregate create Haswell
openstack aggregate set --property cpu=broadwell Broadwell
openstack aggregate set --property cpu=haswell Haswell
opentack aggregate add host <host1> Haswell
openstack flavor set --property aggregate_instance_extra_specs:cpu=broadwell <flavor1>
openstack flavor set --property aggregate_instance_extra_specs:cpu=haswell <flavor2>
  • 如果CPU型号过多,且不便用aggregate hosts划分,建议使用custom mode

Reference

  • http://lirenke.github.io/2014/12/14/Guest-CPU-model-configuration-in-libvirt-with-QEMU-KVM/

其他 - 虚机为什么慢

虚机使用"stress-ng -c 1 --cpu-ops 2500"测试时慢, 原因是Spectre v2导致, 禁用它, OK.

<cpu mode='host-model'> 
<model fallback='allow'/> 
<topology sockets='1' cores='1' threads='1'/> 
<feature policy='disable' name='spec-ctrl'/> 
</cpu> 

<cpu mode='custom' match='exact' check='partial'>
<model fallback='allow'>Broadwell-IBRS</model>
<feature policy='disable' name='spec-ctrl'/> 
</cpu>

代码支持情况

charm与nova均支持cpu_model_extra_flags
https://opendev.org/openstack/charm-nova-compute/commit/8b026f4bfd3dd24e567265068b3efd27386608d7
https://blueprints.launchpad.net/nova/+spec/libvirt-cpu-model-extra-flags
https://bugzilla.redhat.com/show_bug.cgi?id=1275596

备用链接

https://zhhuabj.github.io/2018/03/09/Libvirt%E6%94%AF%E6%8C%81%E7%9A%84%E4%B8%89%E7%A7%8DCPU%E6%A8%A1%E5%BC%8F%E4%B8%8E%E7%83%AD%E8%BF%81%E7%A7%BB-by-Joshua/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值