mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-08 20:51:26 +00:00
qemu: Refactor qemuDomainAdjustMaxMemLock()
Store the current memory locking limit and the desired one separately, which will help with later changes. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
a6b2804513
commit
b4967d7498
@ -9343,27 +9343,29 @@ int
|
|||||||
qemuDomainAdjustMaxMemLock(virDomainObjPtr vm,
|
qemuDomainAdjustMaxMemLock(virDomainObjPtr vm,
|
||||||
bool forceVFIO)
|
bool forceVFIO)
|
||||||
{
|
{
|
||||||
unsigned long long bytes = 0;
|
unsigned long long currentMemLock = 0;
|
||||||
|
unsigned long long desiredMemLock = 0;
|
||||||
|
|
||||||
bytes = qemuDomainGetMemLockLimitBytes(vm->def, forceVFIO);
|
desiredMemLock = qemuDomainGetMemLockLimitBytes(vm->def, forceVFIO);
|
||||||
|
if (virProcessGetMaxMemLock(vm->pid, ¤tMemLock) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (bytes) {
|
if (desiredMemLock > 0) {
|
||||||
/* If this is the first time adjusting the limit, save the current
|
/* If this is the first time adjusting the limit, save the current
|
||||||
* value so that we can restore it once memory locking is no longer
|
* value so that we can restore it once memory locking is no longer
|
||||||
* required */
|
* required */
|
||||||
if (!vm->originalMemlock) {
|
if (vm->originalMemlock == 0) {
|
||||||
if (virProcessGetMaxMemLock(vm->pid, &(vm->originalMemlock)) < 0)
|
vm->originalMemlock = currentMemLock;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Once memory locking is no longer required, we can restore the
|
/* Once memory locking is no longer required, we can restore the
|
||||||
* original, usually very low, limit */
|
* original, usually very low, limit */
|
||||||
bytes = vm->originalMemlock;
|
desiredMemLock = vm->originalMemlock;
|
||||||
vm->originalMemlock = 0;
|
vm->originalMemlock = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes > 0 &&
|
if (desiredMemLock > 0 &&
|
||||||
virProcessSetMaxMemLock(vm->pid, bytes) < 0) {
|
virProcessSetMaxMemLock(vm->pid, desiredMemLock) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user