From: Peter Xu <peterx@redhat.com>
To: Fam Zheng <famz@redhat.com>
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Laurent Vivier <lvivier@redhat.com>,
Juan Quintela <quintela@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [RFC 0/6] monitor: allow per-monitor thread
Date: Tue, 22 Aug 2017 14:56:04 +0800 [thread overview]
Message-ID: <20170822065604.GH30356@pxdev.xzpeter.org> (raw)
In-Reply-To: <20170822063348.GE2146@lemon>
On Tue, Aug 22, 2017 at 02:33:48PM +0800, Fam Zheng wrote:
> On Tue, 08/22 13:59, Peter Xu wrote:
> > On Tue, Aug 22, 2017 at 12:15:19PM +0800, Fam Zheng wrote:
> > > On Tue, 08/22 10:56, Peter Xu wrote:
> > > > I haven't really encountered (c), but I think it's the migrate_cancel
> > > > command that matters, which should not need BQL as well.
> > >
> > > There is bdrv_invalidate_cache_all() in migrate_cancel which clearly isn't safe.
> > > Is that if block unreachable in this case? If so we should assert, otherwise
> > > this command is not okay to run without BQL.
> >
> > Ah. I see. Even if so, if that is the only usage of BQL, IMHO we can
> > still mark migrate_cancel as "without-bql=true", instead we take the
> > BQL before calling bdrv_invalidate_cache_all(). Then migrate_cancel
> > can be BQL-free at least when block migration is not active.
> >
> > >
> > > Generically, what guarantee the thread-safety of a qmp command when you decide
> > > BQL is not needed? In other words, how do you prove commands are safe without
> > > BQL? I think almost every command accesses global state, but lock-free data
> > > structures are rare AFAICT.
> >
> > I would suggest we split the problem into at least three parts. IMHO
> > we need to answer below questions one by one to know what we should do
> > next:
> >
> > 1. whether we can handle monitor commands outside iothread, or say, in
> > an isolated thread?
> >
> > This is basically what patch 2 does, the "per-monitor threads".
> >
> > IMHO this is the very first question to ask. So now I know that at
> > least current code cannot do it. We need to at least do something
> > to remove/replace the assertion to make this happen. Can we? I
> > don't really know the answer yet. If this is undoable, we can skip
> > question 2/3 below and may need to rethink on how to solve the
> > problem that postcopy recovery encounters.
> >
> > 2. whether there is any monitor commands can run without BQL?
> >
> > This is basically what patch 3/5 does, one for QMP, one for HMP.
> >
> > If we can settle question 1, then we can possibly start consider
> > this question. This step does not really allow any command to run
> > without BQL, but we need to know whether it's possible in general,
> > and if possible, we provide a framework to allow QMP/HMP developers
> > to specify that. If you see patch 3/5, the default behavior is
> > still taking the BQL for all commands.
> >
> > IMHO doing this whole thing is generally good in the sense that
> > this is actually forcing ourselves to break the BQL into smaller
> > locks. Take the migration commands for example: migrate_incoming
> > do not need BQL, and when we write codes around it we know that we
> > don't need to think about thread-safety. That's not good IMHO. I
> > think it's time we should start consider thread-safety always.
> > Again, for migrate_incoming to do this, actually we'll possibly at
> > least need a migration management lock (the smaller lock) to make
> > sure e.g. the user is not running two migrate_incoming commands in
> > parallel (after per-monitor threads, it can happen). But it's
> > better than BQL, because BQL is for sure too big, so even a guest
> > page access (as long as it held the BQL) can block migration
> > commands.
>
> Yes, this is my point. You cannot just declare a command "BQL-free" without
> adding small locks first, and I think this is actually missing in this series.
> As you said, two per-monitor threads can race if they do migrate_incoming in
> parallel. This is also the answer to 3.
Ah, I see. The small lock will be there if there is another post. :)
--
Peter Xu
next prev parent reply other threads:[~2017-08-22 6:56 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-21 7:44 [Qemu-devel] [RFC 0/6] monitor: allow per-monitor thread Peter Xu
2017-08-21 7:44 ` [Qemu-devel] [RFC 1/6] monitor: move skip_flush into monitor_data_init Peter Xu
2017-08-21 7:44 ` [Qemu-devel] [RFC 2/6] monitor: allow monitor to create thread to poll Peter Xu
2017-08-21 7:44 ` [Qemu-devel] [RFC 3/6] QAPI: new QMP command option "without-bql" Peter Xu
2017-08-21 7:44 ` [Qemu-devel] [RFC 4/6] migration: qmp: migrate_incoming don't need BQL Peter Xu
2017-08-21 7:44 ` [Qemu-devel] [RFC 5/6] hmp: support "without_bql" Peter Xu
2017-08-21 7:44 ` [Qemu-devel] [RFC 6/6] migration: hmp: migrate_incoming don't need BQL Peter Xu
2017-08-21 8:58 ` [Qemu-devel] [RFC 0/6] monitor: allow per-monitor thread Fam Zheng
2017-08-21 10:05 ` Peter Xu
2017-08-21 10:17 ` Dr. David Alan Gilbert
2017-08-21 14:04 ` Fam Zheng
2017-08-21 14:06 ` Dr. David Alan Gilbert
2017-08-21 13:57 ` Fam Zheng
2017-08-21 15:36 ` Dr. David Alan Gilbert
2017-08-21 16:54 ` Fam Zheng
2017-08-21 17:28 ` Dr. David Alan Gilbert
2017-08-22 2:15 ` Fam Zheng
2017-08-22 2:56 ` Peter Xu
2017-08-22 4:15 ` Fam Zheng
2017-08-22 5:59 ` Peter Xu
2017-08-22 6:33 ` Fam Zheng
2017-08-22 6:56 ` Peter Xu [this message]
2017-08-22 8:29 ` Dr. David Alan Gilbert
2017-08-22 8:48 ` Fam Zheng
2017-08-22 8:48 ` Dr. David Alan Gilbert
2017-08-22 4:51 ` no-reply
2017-08-22 6:21 ` Peter Xu
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=20170822065604.GH30356@pxdev.xzpeter.org \
--to=peterx@redhat.com \
--cc=armbru@redhat.com \
--cc=dgilbert@redhat.com \
--cc=famz@redhat.com \
--cc=lvivier@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.