aboutsummaryrefslogtreecommitdiff
path: root/qemu-options.hx
diff options
context:
space:
mode:
authorClaudio Imbrenda <imbrenda@linux.ibm.com>2022-08-12 15:34:53 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2022-10-31 09:46:34 +0100
commitc891c24b1a4f5496cdb5f6afff9dae146334c7d3 (patch)
tree53fbbaa0593195ccec3154787df3834f1282c5b6 /qemu-options.hx
parent121531751087ad3f8d87ad17068835bbcd14fb02 (diff)
os-posix: asynchronous teardown for shutdown on Linux
This patch adds support for asynchronously tearing down a VM on Linux. When qemu terminates, either naturally or because of a fatal signal, the VM is torn down. If the VM is huge, it can take a considerable amount of time for it to be cleaned up. In case of a protected VM, it might take even longer than a non-protected VM (this is the case on s390x, for example). Some users might want to shut down a VM and restart it immediately, without having to wait. This is especially true if management infrastructure like libvirt is used. This patch implements a simple trick on Linux to allow qemu to return immediately, with the teardown of the VM being performed asynchronously. If the new commandline option -async-teardown is used, a new process is spawned from qemu at startup, using the clone syscall, in such way that it will share its address space with qemu.The new process will have the name "cleanup/<QEMU_PID>". It will wait until qemu terminates completely, and then it will exit itself. This allows qemu to terminate quickly, without having to wait for the whole address space to be torn down. The cleanup process will exit after qemu, so it will be the last user of the address space, and therefore it will take care of the actual teardown. The cleanup process will share the same cgroups as qemu, so both memory usage and cpu time will be accounted properly. If possible, close_range will be used in the cleanup process to close all open file descriptors. If it is not available or if it fails, /proc will be used to determine which file descriptors to close. If the cleanup process is forcefully killed with SIGKILL before the main qemu process has terminated completely, the mechanism is defeated and the teardown will not be asynchronous. This feature can already be used with libvirt by adding the following to the XML domain definition to pass the parameter to qemu directly: <commandline xmlns="http://libvirt.org/schemas/domain/qemu/1.0"> <arg value='-async-teardown'/> </commandline> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Reviewed-by: Murilo Opsfelder Araujo <muriloo@linux.ibm.com> Tested-by: Murilo Opsfelder Araujo <muriloo@linux.ibm.com> Message-Id: <20220812133453.82671-1-imbrenda@linux.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'qemu-options.hx')
-rw-r--r--qemu-options.hx19
1 files changed, 19 insertions, 0 deletions
diff --git a/qemu-options.hx b/qemu-options.hx
index eb38e5dc40..e26d1dad39 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -4774,6 +4774,25 @@ HXCOMM Internal use
DEF("qtest", HAS_ARG, QEMU_OPTION_qtest, "", QEMU_ARCH_ALL)
DEF("qtest-log", HAS_ARG, QEMU_OPTION_qtest_log, "", QEMU_ARCH_ALL)
+#ifdef __linux__
+DEF("async-teardown", 0, QEMU_OPTION_asyncteardown,
+ "-async-teardown enable asynchronous teardown\n",
+ QEMU_ARCH_ALL)
+#endif
+SRST
+``-async-teardown``
+ Enable asynchronous teardown. A new process called "cleanup/<QEMU_PID>"
+ will be created at startup sharing the address space with the main qemu
+ process, using clone. It will wait for the main qemu process to
+ terminate completely, and then exit.
+ This allows qemu to terminate very quickly even if the guest was
+ huge, leaving the teardown of the address space to the cleanup
+ process. Since the cleanup process shares the same cgroups as the
+ main qemu process, accounting is performed correctly. This only
+ works if the cleanup process is not forcefully killed with SIGKILL
+ before the main qemu process has terminated completely.
+ERST
+
DEF("msg", HAS_ARG, QEMU_OPTION_msg,
"-msg [timestamp[=on|off]][,guest-name=[on|off]]\n"
" control error message format\n"