67 lines
2.5 KiB
Diff
67 lines
2.5 KiB
Diff
|
|
From f97100914ff9e00c78e41012b695afe864df6c54 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Adttil <2429917001@qq.com>
|
||
|
|
Date: Thu, 12 Dec 2024 19:39:52 +0800
|
||
|
|
Subject: [PATCH] Bugfix: Enhance the capability to trace the shutdown status
|
||
|
|
of large VMS
|
||
|
|
|
||
|
|
Since the passthrough device needs to be unpinned when shutting down,
|
||
|
|
this greatly extends the VM shutdown time. Previously, libvirt's
|
||
|
|
tracking time for the qemu process was only related to the number of
|
||
|
|
devices, which led to the tracking time exceeding the limit in scenarios
|
||
|
|
with large-size passthrough devices. Now fix him by adjusting the delay
|
||
|
|
to vary with memory size.
|
||
|
|
|
||
|
|
Signed-off-by: wwwumr <1127858301@qq.com>
|
||
|
|
Signed-off-by: Adttil <2429917001@qq.com>
|
||
|
|
---
|
||
|
|
src/qemu/qemu_process.c | 17 +++++++++++++++--
|
||
|
|
1 file changed, 15 insertions(+), 2 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
|
||
|
|
index 63ce075812..89dfd23c84 100644
|
||
|
|
--- a/src/qemu/qemu_process.c
|
||
|
|
+++ b/src/qemu/qemu_process.c
|
||
|
|
@@ -103,6 +103,7 @@
|
||
|
|
#include "logging/log_protocol.h"
|
||
|
|
|
||
|
|
#define VIR_FROM_THIS VIR_FROM_QEMU
|
||
|
|
+#define MEMORY_LATENCY_FACTOR (1 << 20)
|
||
|
|
|
||
|
|
VIR_LOG_INIT("qemu.qemu_process");
|
||
|
|
|
||
|
|
@@ -8610,6 +8611,9 @@ qemuProcessCreatePretendCmdBuild(virDomainObj *vm,
|
||
|
|
int
|
||
|
|
qemuProcessKill(virDomainObj *vm, unsigned int flags)
|
||
|
|
{
|
||
|
|
+ unsigned long long memoryPotentialDelay;
|
||
|
|
+ size_t extraWaitingTime;
|
||
|
|
+
|
||
|
|
VIR_DEBUG("vm=%p name=%s pid=%lld flags=0x%x",
|
||
|
|
vm, vm->def->name,
|
||
|
|
(long long)vm->pid, flags);
|
||
|
|
@@ -8629,10 +8633,19 @@ qemuProcessKill(virDomainObj *vm, unsigned int flags)
|
||
|
|
}
|
||
|
|
|
||
|
|
/* Request an extra delay of two seconds per current nhostdevs
|
||
|
|
- * to be safe against stalls by the kernel freeing up the resources */
|
||
|
|
+ * to be safe against stalls by the kernel freeing up the resources
|
||
|
|
+ * At the same time, Calculate the extra waiting delay required by the
|
||
|
|
+ * VM specifications. The unpin time during device passthrough is
|
||
|
|
+ * related to the momory */
|
||
|
|
+ extraWaitingTime = vm->def->nhostdevs * 2;
|
||
|
|
+ if (vm->def->nhostdevs > 0) {
|
||
|
|
+ memoryPotentialDelay = vm->def->mem.total_memory / MEMORY_LATENCY_FACTOR;
|
||
|
|
+ extraWaitingTime += (size_t)memoryPotentialDelay;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
return virProcessKillPainfullyDelay(vm->pid,
|
||
|
|
!!(flags & VIR_QEMU_PROCESS_KILL_FORCE),
|
||
|
|
- vm->def->nhostdevs * 2,
|
||
|
|
+ extraWaitingTime,
|
||
|
|
false);
|
||
|
|
}
|
||
|
|
|
||
|
|
--
|
||
|
|
2.41.0.windows.1
|
||
|
|
|