mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 22:25:25 +00:00
qemu: Use qemuDomainMemoryLimit when computing memory for VFIO
This commit is contained in:
parent
e0e438af00
commit
6d8ebc7538
@ -6683,6 +6683,7 @@ qemuBuildCommandLine(virConnectPtr conn,
|
||||
int spice = 0;
|
||||
int usbcontroller = 0;
|
||||
bool usblegacy = false;
|
||||
bool mlock = false;
|
||||
int contOrder[] = {
|
||||
/* We don't add an explicit IDE or FD controller because the
|
||||
* provided PIIX4 device already includes one. It isn't possible to
|
||||
@ -8337,22 +8338,15 @@ qemuBuildCommandLine(virConnectPtr conn,
|
||||
|
||||
if (hostdev->source.subsys.u.pci.backend
|
||||
== VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
|
||||
unsigned long long memKB;
|
||||
|
||||
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("VFIO PCI device assignment is not "
|
||||
"supported by this version of qemu"));
|
||||
goto error;
|
||||
}
|
||||
/* VFIO requires all of the guest's memory to be
|
||||
* locked resident, plus some amount for IO
|
||||
* space. Alex Williamson suggested adding 1GiB for IO
|
||||
* space just to be safe (some finer tuning might be
|
||||
* nice, though).
|
||||
*/
|
||||
memKB = def->mem.max_balloon + (1024 * 1024);
|
||||
virCommandSetMaxMemLock(cmd, memKB * 1024);
|
||||
/* VFIO requires all of the guest's memory to be locked
|
||||
* resident */
|
||||
mlock = true;
|
||||
}
|
||||
|
||||
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) {
|
||||
@ -8572,6 +8566,9 @@ qemuBuildCommandLine(virConnectPtr conn,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (mlock)
|
||||
virCommandSetMaxMemLock(cmd, qemuDomainMemoryLimit(def) * 1024);
|
||||
|
||||
virObjectUnref(cfg);
|
||||
return cmd;
|
||||
|
||||
|
@ -2199,6 +2199,9 @@ qemuDomainMemoryLimit(virDomainDefPtr def)
|
||||
* cache per each disk) + F
|
||||
* where k = 0.5 and F = 200MB. The cache for disks is important as
|
||||
* kernel cache on the host side counts into the RSS limit.
|
||||
* Moreover, VFIO requires some amount for IO space. Alex Williamson
|
||||
* suggested adding 1GiB for IO space just to be safe (some finer
|
||||
* tuning might be nice, though).
|
||||
*
|
||||
* Technically, the disk cache does not have to be included in
|
||||
* RLIMIT_MEMLOCK but it doesn't hurt as it's just an upper limit and
|
||||
@ -2210,6 +2213,18 @@ qemuDomainMemoryLimit(virDomainDefPtr def)
|
||||
mem *= 1.5;
|
||||
mem += def->ndisks * 32768;
|
||||
mem += 204800;
|
||||
|
||||
for (i = 0; i < def->nhostdevs; i++) {
|
||||
virDomainHostdevDefPtr hostdev = def->hostdevs[i];
|
||||
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
|
||||
hostdev->source.subsys.type ==
|
||||
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
|
||||
hostdev->source.subsys.u.pci.backend ==
|
||||
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
|
||||
mem += 1024 * 1024;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mem;
|
||||
|
@ -1054,23 +1054,21 @@ int qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver,
|
||||
|
||||
if (hostdev->source.subsys.u.pci.backend
|
||||
== VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
|
||||
unsigned long long memKB;
|
||||
|
||||
if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("VFIO PCI device assignment is not "
|
||||
"supported by this version of qemu"));
|
||||
goto error;
|
||||
}
|
||||
/* VFIO requires all of the guest's memory to be locked
|
||||
* resident, plus some amount for IO space. Alex Williamson
|
||||
* suggested adding 1GiB for IO space just to be safe (some
|
||||
* finer tuning might be nice, though).
|
||||
* In this case, the guest's memory may already be locked, but
|
||||
* it doesn't hurt to "change" the limit to the same value.
|
||||
|
||||
/* VFIO requires all of the guest's memory to be locked resident.
|
||||
* In this case, the guest's memory may already be locked, but it
|
||||
* doesn't hurt to "change" the limit to the same value.
|
||||
*/
|
||||
memKB = vm->def->mem.max_balloon + (1024 * 1024);
|
||||
virProcessSetMaxMemLock(vm->pid, memKB * 1024);
|
||||
vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
|
||||
virProcessSetMaxMemLock(vm->pid,
|
||||
qemuDomainMemoryLimit(vm->def) * 1024);
|
||||
vm->def->hostdevs[vm->def->nhostdevs--] = NULL;
|
||||
}
|
||||
|
||||
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
|
||||
|
Loading…
Reference in New Issue
Block a user