Libvirt支持的三种CPU模式与热迁移

问题

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

解决办法

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











































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  Haswell
openstack flavor set --property aggregate_instance_extra_specs:cpu=broadwell 
openstack flavor set --property aggregate_instance_extra_specs:cpu=haswell 
  • 如果CPU型号过多,且不便用aggregate hosts划分,建议使用custom mode

 

原文链接:https://zhhuabj.github.io/2018/03/09/Libvirt支持的三种CPU模式与热迁移-by-Joshua/

你可能感兴趣的:(OpenStack)