通过virt-install 命令创建虚拟机的时候会调用到qemu/hw/arm/virt.c 中的machvirt_machine_init
static const TypeInfo virt_machine_info = {
.name = TYPE_VIRT_MACHINE,
.parent = TYPE_MACHINE,
.abstract = true,
.instance_size = sizeof(VirtMachineState),
.class_size = sizeof(VirtMachineClass),
.class_init = virt_machine_class_init,
};
static void machvirt_machine_init(void)
{
type_register_static(&virt_machine_info);
}
这里我们重点看virt_machine_class_init->machvirt_init
static void machvirt_init(MachineState *machine)
{
//下面这段code中会对要创建虚拟机的vcpu的个数和ram的size检查
if (gic_version == 3) {
virt_max_cpus = vbi->memmap[VIRT_GIC_REDIST].size / 0x20000;
clustersz = GICV3_TARGETLIST_BITS;
} else {
virt_max_cpus = GIC_NCPU;
clustersz = GIC_TARGETLIST_BITS;
}
if (max_cpus > virt_max_cpus) {
error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
"supported by machine 'mach-virt' (%d)",
max_cpus, virt_max_cpus);
exit(1);
}
vbi->smp_cpus = smp_cpus;
if (machine->ram_size > vbi->memmap[VIRT_MEM].size) {
error_report("mach-virt: cannot model more than %dGB RAM", RAMLIMIT_GB);
exit(1);
}
}
这里加入gic_version 不等于3的话,则vcpu的个数不能超过virt_max_cpus = GIC_NCPU;。这里的#define GIC_NCPU 8
从下面这个秒钟可以看到memory最大不能超过RAMLIMIT_BYTES,也就是256GB
#define RAMLIMIT_GB 255
#define RAMLIMIT_BYTES (RAMLIMIT_GB * 1024ULL * 1024 * 1024)
static const MemMapEntry a15memmap[] = {
[VIRT_MEM] = { 0x40000000, RAMLIMIT_BYTES },
/* Second PCIe window, 512GB wide at the 512GB boundary */
[VIRT_PCIE_MMIO_HIGH] = { 0x8000000000ULL, 0x8000000000ULL },
};
通过virt-install 创建虚拟机时qemu对vcpu和ram的限制
最新推荐文章于 2023-10-13 16:07:43 发布