mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
qemu_domain: add a PPC64 memLockLimit helper
There is a lot of documentation in the comments about how PPC64 handles passthrough VFIO devices to calculate the @memLockLimit. And more will be added with the PPC64 NVLink2 support code. Let's remove the PPC64 code from qemuDomainGetMemLockLimitBytes() body and put it into a helper function. This will simplify the flow of qemuDomainGetMemLockLimitBytes() that handles all the other platforms and improves readability of the PPC64 specifics. Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
cf7c521287
commit
7a686fd2ea
@ -10344,42 +10344,21 @@ qemuDomainUpdateCurrentMemorySize(virDomainObjPtr vm)
|
||||
|
||||
|
||||
/**
|
||||
* qemuDomainGetMemLockLimitBytes:
|
||||
* getPPC64MemLockLimitBytes:
|
||||
* @def: domain definition
|
||||
*
|
||||
* Calculate the memory locking limit that needs to be set in order for
|
||||
* the guest to operate properly. The limit depends on a number of factors,
|
||||
* including certain configuration options and less immediately apparent ones
|
||||
* such as the guest architecture or the use of certain devices.
|
||||
*
|
||||
* Returns: the memory locking limit, or 0 if setting the limit is not needed
|
||||
* A PPC64 helper that calculates the memory locking limit in order for
|
||||
* the guest to operate properly.
|
||||
*/
|
||||
unsigned long long
|
||||
qemuDomainGetMemLockLimitBytes(virDomainDefPtr def)
|
||||
static unsigned long long
|
||||
getPPC64MemLockLimitBytes(virDomainDefPtr def)
|
||||
{
|
||||
unsigned long long memKB = 0;
|
||||
size_t i;
|
||||
|
||||
/* prefer the hard limit */
|
||||
if (virMemoryLimitIsSet(def->mem.hard_limit)) {
|
||||
memKB = def->mem.hard_limit;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* If the guest wants its memory to be locked, we need to raise the memory
|
||||
* locking limit so that the OS will not refuse allocation requests;
|
||||
* however, there is no reliable way for us to figure out how much memory
|
||||
* the QEMU process will allocate for its own use, so our only way out is
|
||||
* to remove the limit altogether. Use with extreme care */
|
||||
if (def->mem.locked)
|
||||
return VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
||||
|
||||
if (ARCH_IS_PPC64(def->os.arch) && def->virtType == VIR_DOMAIN_VIRT_KVM) {
|
||||
unsigned long long maxMemory;
|
||||
unsigned long long memory;
|
||||
unsigned long long baseLimit;
|
||||
unsigned long long baseLimit = 0;
|
||||
unsigned long long memory = 0;
|
||||
unsigned long long maxMemory = 0;
|
||||
unsigned long long passthroughLimit = 0;
|
||||
size_t nPCIHostBridges = 0;
|
||||
size_t i, nPCIHostBridges = 0;
|
||||
bool usesVFIO = false;
|
||||
|
||||
for (i = 0; i < def->ncontrollers; i++) {
|
||||
@ -10450,9 +10429,45 @@ qemuDomainGetMemLockLimitBytes(virDomainDefPtr def)
|
||||
memory / 512 * nPCIHostBridges + 8192);
|
||||
|
||||
memKB = baseLimit + passthroughLimit;
|
||||
|
||||
return memKB << 10;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* qemuDomainGetMemLockLimitBytes:
|
||||
* @def: domain definition
|
||||
*
|
||||
* Calculate the memory locking limit that needs to be set in order for
|
||||
* the guest to operate properly. The limit depends on a number of factors,
|
||||
* including certain configuration options and less immediately apparent ones
|
||||
* such as the guest architecture or the use of certain devices.
|
||||
*
|
||||
* Returns: the memory locking limit, or 0 if setting the limit is not needed
|
||||
*/
|
||||
unsigned long long
|
||||
qemuDomainGetMemLockLimitBytes(virDomainDefPtr def)
|
||||
{
|
||||
unsigned long long memKB = 0;
|
||||
size_t i;
|
||||
|
||||
/* prefer the hard limit */
|
||||
if (virMemoryLimitIsSet(def->mem.hard_limit)) {
|
||||
memKB = def->mem.hard_limit;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* If the guest wants its memory to be locked, we need to raise the memory
|
||||
* locking limit so that the OS will not refuse allocation requests;
|
||||
* however, there is no reliable way for us to figure out how much memory
|
||||
* the QEMU process will allocate for its own use, so our only way out is
|
||||
* to remove the limit altogether. Use with extreme care */
|
||||
if (def->mem.locked)
|
||||
return VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
||||
|
||||
if (ARCH_IS_PPC64(def->os.arch) && def->virtType == VIR_DOMAIN_VIRT_KVM)
|
||||
return getPPC64MemLockLimitBytes(def);
|
||||
|
||||
/* For device passthrough using VFIO the guest memory and MMIO memory
|
||||
* regions need to be locked persistent in order to allow DMA.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user