1.cpu
1)CPU Allocation

<domain>
 
  ...
 
  <vcpu placement='static' cpuset="1-4,^3,6" current="1">2</vcpu>
 
  <vcpus>
 
    <vcpu id='0' enabled='yes' hotpluggable='no' order='1'/>
 
    <vcpu id='1' enabled='no' hotpluggable='yes'/>
 
  </vcpus>
 
  ...
<
</domain>

vcpu
cpuset:qemu进程的绑定范围,如果未指定默认绑定到所有可用的物理核心上,对emulator和vcpu都生效。如果指定了emulatorpin,该配置对qemu主进程失效。如果指定了vcpupin,该配置对指定了vcpupin的vcpu失效。对其它未配置vcpupin的vcpu仍然有效。
placement:cpuset的分布方式,可以是auto或者static。如果指定了cpuset,默认为static或者numatune的placement。如果指定auto,libvirt会与numad服务通信获取建议的分布方式,cpuset参数指定的配置失效。
cputune
vcpupin cpuset: 优先级最高,如果指定按照该值绑定vcpu,vcpu的cpuset失效。
emulatorpin cpuset: 优先级最高,如果指定按照该值绑定emulator。vcpu的cpuset失效。
2..内存
1)内存分配

<domain>
  ...
  <maxMemory slots='16' unit='KiB'>1524288</maxMemory>
  <memory unit='KiB'>524288</memory>
  <currentMemory unit='KiB'>524288</currentMemory>
  ...
</domain>

maxMemory:为虚机分配的最大可运行内存,unit为单位
memory:为虚机分配的启动时的最大内存
currentMemory:为虚机分配的实际内存大小,无此项,默认等于memory
区别:当guest需要使用RAM时,qemu-kvm就在自己的进程内存空间中划分一段给guest用。对于guest OS设置了MaxMemory和CurrentMemory之后,guest OS的RAM上限也就有了,就是MaxMemory,如果当前的guest实际使用不了那么多RAM,就可以将CurrentMemory调小,将多余的内存还给host,guest中看到的内存大小就是CurrentMemory,这就是Memory Balloon特性。
2)Memory Backing:包含主机如何提供虚拟内存页给虚机

<domain>
  ...
  <memoryBacking>
    <hugepages>
      <page size="1" unit="G" nodeset="0-3,5"/>
      <page size="2" unit="M" nodeset="4"/>
    </hugepages>
    <nosharepages/>
    <locked/>
    <source type="file|anonymous|memfd"/>
    <access mode="shared|private"/>
    <allocation mode="immediate|ondemand"/>
    <discard/>
  </memoryBacking>
  ...
</domain>

hugepages:虚机使用的内存是巨页而非普通页面。
nosharepages:禁止虚机共享页面(内存合并,KSM)
locked:禁止swap,在一些实时场合使用
source:使用的内存类型;可以使用file内存或保持默认的anonymous类型,4.10之后支持memfd(仅QEMU/KVM)
access:模式属性,指明内存是共享的还是私有的,可能会被每numa node的memAccess重写
allocation:模式属性,指明什么时候分配内存,通过immediate和ondemand选项
discard:指明关机前什么时候丢弃内存中的内容
3)NUMA Node Tuning:设置虚机的numa策略来优化numa主机性能,仅由QEMU驱动程序支持。

<domain>
  ...
  <numatune>
    <memory mode="strict" nodeset="1-4,^3"/>
    <memnode cellid="0" mode="strict" nodeset="1"/>
    <memnode cellid="2" mode="preferred" nodeset="2"/>
  </numatune>
  ...
</domain>

memory:可选项,指明如何从物理node上给虚机分配内存
   mode: interleave, strict和preferred, 默认为strict,根据mode决定虚机的内存是否严格遵守nodeset的规则。
        1)interleave:    
        2)strict:根据指定的nodeset设置qemu内存分布亲和性
        3)preferred:要求nodeset中只能有一个target node
    nodeset 指定内存分配的具体节点
   placement static/auto可选,默认为static,默认与vcpu placement一致,当指定了nodeset时默认为static。如果指定了auto,nodeset将被忽略,云主机将只从numad返回结果的node上申请内存。如果vcpu的placement指定了auto,会默认增加一个numatune的配置,placement的值为auto,mode为strict。