passthroughLimit is being calculated even if usesVFIO is false.
After that, a if/else conditional is used to check if we're going
to sum it up with baseLimit.
This patch initializes passthroughLimit to zero and always
return memKB = baseLimit + passthroughLimit. The conditional
is then used to calculate passthroughLimit if usesVFIO is true.
This results in some cycles spared for the usesVFIO=false
scenario, but the real motivation is to make the code simpler
to add an alternative passthroughLimit formula for NVLink2
passthrough.
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/qemu/qemu_domain.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 59fe1eb401..55578f3d19 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -10366,7 +10366,7 @@ qemuDomainGetMemLockLimitBytes(virDomainDefPtr def)
unsigned long long maxMemory;
unsigned long long memory;
unsigned long long baseLimit;
- unsigned long long passthroughLimit;
+ unsigned long long passthroughLimit = 0;
size_t nPCIHostBridges = 0;
bool usesVFIO = false;
@@ -10432,15 +10432,12 @@ qemuDomainGetMemLockLimitBytes(virDomainDefPtr def)
* kiB pages, less still if the guest is mapped with hugepages (unlike
* the default 32-bit DMA window, DDW windows can use large IOMMU
* pages). 8 MiB is for second and further level overheads, like (b) */
- passthroughLimit = MAX(2 * 1024 * 1024 * nPCIHostBridges,
- memory +
- memory / 512 * nPCIHostBridges + 8192);
-
if (usesVFIO)
- memKB = baseLimit + passthroughLimit;
- else
- memKB = baseLimit;
+ passthroughLimit = MAX(2 * 1024 * 1024 * nPCIHostBridges,
+ memory +
+ memory / 512 * nPCIHostBridges + 8192);
+ memKB = baseLimit + passthroughLimit;
goto done;
}
--
2.20.1