From: Paolo Bonzini <pbonzini@redhat.com>
To: Stefan Hajnoczi <stefanha@gmail.com>,
qemu-devel <qemu-devel@nongnu.org>,
qemu block <qemu-block@nongnu.org>
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <famz@redhat.com>
Subject: Re: [Qemu-devel] Multiqueue block layer
Date: Mon, 19 Feb 2018 19:03:19 +0100 [thread overview]
Message-ID: <95b23032-6a23-914f-2c79-3da8bbc79c22@redhat.com> (raw)
In-Reply-To: <CAJSP0QV=rntD8h4kLdDaydDHxf9ustrK0jnUfU-aQFJp2wPAWg@mail.gmail.com>
On 18/02/2018 19:20, Stefan Hajnoczi wrote:
> Paolo's patches have been getting us closer to multiqueue block layer
> support but there is a final set of changes required that has become
> clearer to me just recently. I'm curious if this matches Paolo's
> vision and whether anyone else has comments.
>
> We need to push the AioContext lock down into BlockDriverState so that
> thread-safety is not tied to a single AioContext but to the
> BlockDriverState itself. We also need to audit block layer code to
> identify places that assume everything is run from a single
> AioContext.
This is mostly done already. Within BlockDriverState
dirty_bitmap_mutex, reqs_lock and the BQL is good enough in many cases.
Drivers already have their mutex.
> After this is done the final piece is to eliminate
> bdrv_set_aio_context(). BlockDriverStates should not be associated
> with an AioContext. Instead they should use whichever AioContext they
> are invoked under. The current thread's AioContext can be fetched
> using qemu_get_current_aio_context(). This is either the main loop
> AioContext or an IOThread AioContext.
>
> The .bdrv_attach/detach_aio_context() callbacks will no longer be
> necessary in a world where block driver code is thread-safe and any
> AioContext can be used.
This is not entirely possible. In particular, network drivers still
have a "home context" which is where the file descriptor callbacks are
attached to. They could still dispatch I/O from any thread in a
multiqueue setup. This is the remaining intermediate step between "no
AioContext lock" and "multiqueue".
> bdrv_drain_all() and friends do not require extensive modifications
> because the bdrv_wakeup() mechanism already works properly when there
> are multiple IOThreads involved.
Yes, this is already done indeed.
> Block jobs no longer need to be in the same AioContext as the
> BlockDriverState. For simplicity we may choose to always run them in
> the main loop AioContext by default. This may have a performance
> impact on tight loops like bdrv_is_allocated() and the initial
> mirroring phase, but maybe not.
>
> The upshot of all this is that bdrv_set_aio_context() goes away while
> all block driver code needs to be more aware of thread-safety. It can
> no longer assume that everything is called from one AioContext.
Correct.
> We should optimize file-posix.c and qcow2.c for maximum parallelism
> using fine-grained locks and other techniques. The remaining block
> drivers can use one CoMutex per BlockDriverState.
Even better: there is one thread pool and linux-aio context per I/O
thread, file-posix.c should just submit I/O to the current thread with
no locking whatsoever. There is still reqs_lock, but that can be
optimized easily (see
http://lists.gnu.org/archive/html/qemu-devel/2017-04/msg03323.html; now
that we have QemuLockable, reqs_lock could also just become a QemuSpin).
qcow2.c could be adjusted to use rwlocks.
> I'm excited that we're relatively close to multiqueue now. I don't
> want to jinx it by saying 2018 is the year of the multiqueue block
> layer, but I'll say it anyway :).
Heh. I have stopped pushing my patches (and scratched a few itches with
patchew instead) because I'm still a bit burned out from recent KVM
stuff, but this may be the injection of enthusiasm that I needed. :)
Actually, I'd be content with removing the AioContext lock in the first
half of 2018. 1/3rd of that is gone already---doh! But we're actually
pretty close, thanks to you and all the others who have helped reviewing
the past 100 or so patches!
Paolo
next prev parent reply other threads:[~2018-02-19 18:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-18 18:20 [Qemu-devel] Multiqueue block layer Stefan Hajnoczi
2018-02-19 18:03 ` Paolo Bonzini [this message]
2018-02-19 18:38 ` Stefan Hajnoczi
2018-02-19 18:41 ` Stefan Hajnoczi
2018-02-19 18:59 ` Alexandre DERUMIER
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=95b23032-6a23-914f-2c79-3da8bbc79c22@redhat.com \
--to=pbonzini@redhat.com \
--cc=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.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).