[libvirt] [PATCH v1 19/31] qemu: Take NVMe disks into account when calculating memlock limit

Peter Krempa pkrempa at redhat.com
Tue Jul 16 14:18:27 UTC 2019


On Thu, Jul 11, 2019 at 17:54:06 +0200, Michal Privoznik wrote:
> We have this beautiful function that does crystal ball
> divination. The function is named
> qemuDomainGetMemLockLimitBytes() and it calculates the upper
> limit of how much locked memory is given guest going to need. The
> function bases its guess on devices defined for a domain. For
> instance, if there is a VFIO hostdev defined then it adds 1GiB to
> the guessed maximum. Since NVMe disks are pretty much VFIO
> hostdevs (but not quite), we have to do the same sorcery.
> 
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
>  src/qemu/qemu_domain.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index f09abc8a73..09e5ee37f4 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c


preceeding hunk


    for (i = 0; i < def->nhostdevs; i++) {
        virDomainHostdevSubsysPtr subsys = &def->hostdevs[i]->source.subsys;

        if (def->hostdevs[i]->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
            (subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV ||
             (subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
              subsys->u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO))) {
            memKB = virDomainDefGetMemoryTotal(def) + 1024 * 1024;
            goto done;
        }
    }


> @@ -10950,6 +10950,21 @@ qemuDomainGetMemLockLimitBytes(virDomainDefPtr def)
>          }
>      }
>  
> +    for (i = 0; i < def->ndisks; i++) {
> +        virDomainDiskDefPtr disk = def->disks[i];
> +        virStorageSourcePtr n;
> +
> +        if (!disk->src)
> +            continue;
> +
> +        for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
> +            if (n->type == VIR_STORAGE_TYPE_NVME) {
> +                memKB = virDomainDefGetMemoryTotal(def) + 1024 * 1024;
> +                goto done;
> +            }
> +        }
> +    }

Please set a booleand such as 'needVFIO' in the above hunk and here and
do the calculation once based on that boolean.

This implementation creates two instancess needing fixing in case when
we'd need to ever change the number.

ACK with that change
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190716/4f128c3f/attachment-0001.sig>


More information about the libvir-list mailing list