From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>,
qemu-devel@nongnu.org, david@redhat.com, cohuck@redhat.com,
thuth@redhat.com, borntraeger@de.ibm.com, frankja@linux.ibm.com,
fiuczy@linux.ibm.com, pasic@linux.ibm.com,
alex.bennee@linaro.org, armbru@redhat.com,
Murilo Opsfelder Araujo <muriloo@linux.ibm.com>
Subject: Re: [PATCH v4 1/1] os-posix: asynchronous teardown for shutdown on Linux
Date: Tue, 25 Oct 2022 13:52:04 +0100 [thread overview]
Message-ID: <Y1fb9OAKTgUXC/w6@redhat.com> (raw)
In-Reply-To: <c60fa9e2-b5c4-6765-da23-e6cc31746f53@redhat.com>
On Tue, Oct 25, 2022 at 02:42:11PM +0200, Paolo Bonzini wrote:
> On 8/12/22 15:34, Claudio Imbrenda wrote:
> > 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>
> > ---
>
> Nice trick indeed!
>
> The only question I have is whether it would make sense to do this in
> Libvirt instead.
Hmm, interesting idea, that hadn't occurred to me.
Current flow is
libvirtd -> fork -> fork -> execve(qemu)
\-> clone(async handler)
Due to CLONE_VM, both main QEMU PID and async handler PID are sharing
the memory mappings of code being executed. Everything is fine.
If doing it in libvirt the flow would be
libvirtd -> fork -> fork -> execve(qemu)
\-> clone(async handler)
In the latter case the async handler would be running code from
the libvirt binary. When the parent calls execve that will load
the code from QEMU, and because of CLONE_VM, this affect the
memory mappings in the async handler proces too. I think that
will end up quite explody, no ?
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2022-10-25 12:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-12 13:34 [PATCH v4 1/1] os-posix: asynchronous teardown for shutdown on Linux Claudio Imbrenda
2022-08-23 17:14 ` Daniel P. Berrangé
2022-10-25 12:42 ` Paolo Bonzini
2022-10-25 12:52 ` Daniel P. Berrangé [this message]
2022-10-25 13:12 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y1fb9OAKTgUXC/w6@redhat.com \
--to=berrange@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=armbru@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=fiuczy@linux.ibm.com \
--cc=frankja@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=muriloo@linux.ibm.com \
--cc=pasic@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).