使用 virt-manager 模拟 NUMA 机器

使用 virt-manager 模拟 NUMA 机器

我需要开发一个使用库函数库。但我家里没有 NUMA 机器,函数numa_avaiable()返回 0。

我想模拟一台 NUMA 机器。因此,我安装了 qemu 和 virt-manager。但是在创建虚拟机的向导中,我没有找到创建 NUMA 机器的选项。

可以这样做吗?还有其他选择吗?

提前致谢,

答案1

来自QEMU 3.0.0 文档

qemu-system-XXXyour_machineXXX [options] [disk_image]

Option:
-numa node[,mem=size][,cpus=firstcpu[-lastcpu]][,nodeid=node]
-numa node[,memdev=id][,cpus=firstcpu[-lastcpu]][,nodeid=node]
-numa dist,src=source,dst=destination,val=distance
-numa cpu,node-id=node[,socket-id=x][,core-id=y][,thread-id=z] 

Define a NUMA node and assign RAM and VCPUs to it. Set the NUMA distance from 
a source node to a destination node.

Legacy VCPU assignment uses ‘cpus’ option where firstcpu and lastcpu are CPU
indexes. Each ‘cpus’ option represent a contiguous range of CPU indexes (or a
single VCPU if lastcpu is omitted). A non-contiguous set of VCPUs can be
represented by providing multiple ‘cpus’ options. If ‘cpus’ is omitted on all 
nodes, VCPUs are automatically split between them.

For example, the following option assigns VCPUs 0, 1, 2 and 5 to a NUMA node:

    -numa node,cpus=0-2,cpus=5 

‘cpu’ option is a new alternative to ‘cpus’ option which uses ‘socket-
id|core-id|thread-id’ properties to assign CPU objects to a node using 
topology layout properties of CPU. The set of properties is machine specific,
and depends on used machine type/‘smp’ options. It could be queried with 
‘hotpluggable-cpus’ monitor command. ‘node-id’ property specifies node to which
CPU object will be assigned, it’s required for node to be declared with
‘node’ option before it’s used with ‘cpu’ option.

For example:

-M pc \
-smp 1,sockets=2,maxcpus=2 \
-numa node,nodeid=0 -numa node,nodeid=1 \
-numa cpu,node-id=0,socket-id=0 -numa cpu,node-id=1,socket-id=1 

‘mem’ assigns a given RAM amount to a node. ‘memdev’ assigns RAM from a given 
memory backend device to a node. If ‘mem’ and ‘memdev’ are omitted in all 
nodes, RAM is split equally between them.

‘mem’ and ‘memdev’ are mutually exclusive. Furthermore, if one node uses
‘memdev’, all of them have to use it.

source and destination are NUMA node IDs. distance is the NUMA distance from
source to destination. The distance from a node to itself is always 10. If 
any pair of nodes is given a distance, then all pairs must be given 
distances. Although, when distances are only given in one direction for each 
pair of nodes, then the distances in the opposite directions are assumed to
be the same. If, however, an asymmetrical pair of distances is given for even 
one node pair, then all node pairs must be provided distance values for both
directions, even when they are symmetrical. When a node is unreachable from 
another node, set the pair’s distance to 255.

Note that the -numa option doesn’t allocate any of the specified resources, 
it just assigns existing resources to NUMA nodes. This means that one still
has to use the -m, -smp options to allocate RAM and VCPUs respectively.

你可以看看这个教程如何设置虚拟机。

相关内容