From: Kevin Wolf <kwolf@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Cc: qemu-block@nongnu.org, eesposit@redhat.com, stefanha@redhat.com,
hreitz@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org
Subject: Re: [PATCH 10/13] block: Call drain callbacks only once
Date: Mon, 14 Nov 2022 13:32:23 +0100 [thread overview]
Message-ID: <Y3I1Vy5MH5zMhFy6@redhat.com> (raw)
In-Reply-To: <9fc70d98-24de-0461-cb13-864c7d77e90c@yandex-team.ru>
Am 09.11.2022 um 19:05 hat Vladimir Sementsov-Ogievskiy geschrieben:
> On 11/8/22 15:37, Kevin Wolf wrote:
> > We only need to call both the BlockDriver's callback and the parent
> > callbacks when going from undrained to drained or vice versa. A second
> > drain section doesn't make a difference for the driver or the parent,
> > they weren't supposed to send new requests before and after the second
> > drain.
> >
> > One thing that gets in the way is the 'ignore_bds_parents' parameter in
> > bdrv_do_drained_begin_quiesce() and bdrv_do_drained_end(): If it is true
> > for the first drain, bs->quiesce_counter will be non-zero, but the
> > parent callbacks still haven't been called, so a second drain where it
> > is false would still have to call them.
> >
> > Instead of keeping track of this, let's just get rid of the parameter.
> > It was introduced in commit 6cd5c9d7b2d as an optimisation so that
> > during bdrv_drain_all(), we wouldn't recursively drain all parents up to
> > the root for each node, resulting in quadratic complexity. As it happens,
> > calling the callbacks only once solves the same problem, so as of this
> > patch, we'll still have O(n) complexity and ignore_bds_parents is not
> > needed any more.
> >
> > This patch only ignores the 'ignore_bds_parents' parameter. It will be
> > removed in a separate patch.
> >
> > Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> > ---
> > block.c | 13 ++++++-------
> > block/io.c | 24 +++++++++++++-----------
> > tests/unit/test-bdrv-drain.c | 16 ++++++++++------
> > 3 files changed, 29 insertions(+), 24 deletions(-)
> >
> > diff --git a/block.c b/block.c
> > index 9d082631d9..8878586f6e 100644
> > --- a/block.c
> > +++ b/block.c
> > @@ -2816,7 +2816,6 @@ static void bdrv_replace_child_noperm(BdrvChild *child,
> > {
> > BlockDriverState *old_bs = child->bs;
> > int new_bs_quiesce_counter;
> > - int drain_saldo;
> > assert(!child->frozen);
> > assert(old_bs != new_bs);
> > @@ -2827,15 +2826,13 @@ static void bdrv_replace_child_noperm(BdrvChild *child,
> > }
> > new_bs_quiesce_counter = (new_bs ? new_bs->quiesce_counter : 0);
> > - drain_saldo = new_bs_quiesce_counter - child->parent_quiesce_counter;
> > /*
> > * If the new child node is drained but the old one was not, flush
> > * all outstanding requests to the old child node.
> > */
> > - while (drain_saldo > 0 && child->klass->drained_begin) {
> > + if (new_bs_quiesce_counter && !child->parent_quiesce_counter) {
>
> Looks like checking for child->klass->drained_begin was a wrong thing
> even prepatch?
I'm not sure if it was strictly wrong in practice, but at least
unnecessary. It would have been wrong if a BdrvChildClass implemented
for example .drained_begin, but not .drain_end. But I think we always
implement all three of .drained_begin/poll/end or none of them.
> Also, parent_quiesce_counter actually becomes a boolean variable..
> Should we stress it by new type and name?
Ok, but I would do that in a separate patch. Maybe 'bool drains_parent'.
> > bdrv_parent_drained_begin_single(child, true);
> > - drain_saldo--;
> > }
> > if (old_bs) {
> > @@ -2859,7 +2856,6 @@ static void bdrv_replace_child_noperm(BdrvChild *child,
> > * more often.
> > */
>
> the comment above ^^^ should be updated, we are not going to call
> drained_end more than once anyway
>
> > assert(new_bs->quiesce_counter <= new_bs_quiesce_counter);
>
> do we still need this assertion and the comment at all?
Patch 12 removes both, but I can do it already here.
> > - drain_saldo += new_bs->quiesce_counter - new_bs_quiesce_counter;
> > if (child->klass->attach) {
> > child->klass->attach(child);
> > @@ -2869,10 +2865,13 @@ static void bdrv_replace_child_noperm(BdrvChild *child,
> > /*
> > * If the old child node was drained but the new one is not, allow
> > * requests to come in only after the new node has been attached.
> > + *
> > + * Update new_bs_quiesce_counter because bdrv_parent_drained_begin_single()
> > + * polls, which could have changed the value.
> > */
> > - while (drain_saldo < 0 && child->klass->drained_end) {
> > + new_bs_quiesce_counter = (new_bs ? new_bs->quiesce_counter : 0);
> > + if (!new_bs_quiesce_counter && child->parent_quiesce_counter) {
> > bdrv_parent_drained_end_single(child);
> > - drain_saldo++;
> > }
> > }
> > diff --git a/block/io.c b/block/io.c
> > index 870a25d7a5..87c7a92f15 100644
> > --- a/block/io.c
> > +++ b/block/io.c
> > @@ -62,7 +62,7 @@ void bdrv_parent_drained_end_single(BdrvChild *c)
> > {
> > IO_OR_GS_CODE();
> > - assert(c->parent_quiesce_counter > 0);
> > + assert(c->parent_quiesce_counter == 1);
> > c->parent_quiesce_counter--;
> > if (c->klass->drained_end) {
> > c->klass->drained_end(c);
> > @@ -109,6 +109,7 @@ static bool bdrv_parent_drained_poll(BlockDriverState *bs, BdrvChild *ignore,
> > void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll)
> > {
> > IO_OR_GS_CODE();
> > + assert(c->parent_quiesce_counter == 0);
> > c->parent_quiesce_counter++;
> > if (c->klass->drained_begin) {
> > c->klass->drained_begin(c);
> > @@ -352,16 +353,16 @@ void bdrv_do_drained_begin_quiesce(BlockDriverState *bs,
> > BdrvChild *parent, bool ignore_bds_parents)
> > {
> > IO_OR_GS_CODE();
> > - assert(!qemu_in_coroutine());
>
> why that is dropped? seems unrelated to the commit
I'm sure I added it because I actually got an assertion failure, but I
can't reproduce it on this commit now. At the end of the series tests do
fail without this removed. I'll double check which commit is right one
to remove it.
> > /* Stop things in parent-to-child order */
> > if (qatomic_fetch_inc(&bs->quiesce_counter) == 0) {
> > aio_disable_external(bdrv_get_aio_context(bs));
> > - }
> > - bdrv_parent_drained_begin(bs, parent, ignore_bds_parents);
> > - if (bs->drv && bs->drv->bdrv_drain_begin) {
> > - bs->drv->bdrv_drain_begin(bs);
> > + /* TODO Remove ignore_bds_parents, we don't consider it any more */
> > + bdrv_parent_drained_begin(bs, parent, false);
> > + if (bs->drv && bs->drv->bdrv_drain_begin) {
> > + bs->drv->bdrv_drain_begin(bs);
> > + }
> > }
> > }
> > @@ -412,13 +413,14 @@ static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent,
> > assert(bs->quiesce_counter > 0);
> > /* Re-enable things in child-to-parent order */
>
> the comment should be moved too, I think
It is the same place as in bdrv_do_drained_begin_quiesce().
> > - if (bs->drv && bs->drv->bdrv_drain_end) {
> > - bs->drv->bdrv_drain_end(bs);
> > - }
> > - bdrv_parent_drained_end(bs, parent, ignore_bds_parents);
> > -
> > old_quiesce_counter = qatomic_fetch_dec(&bs->quiesce_counter);
> > if (old_quiesce_counter == 1) {
> > + if (bs->drv && bs->drv->bdrv_drain_end) {
> > + bs->drv->bdrv_drain_end(bs);
> > + }
> > + /* TODO Remove ignore_bds_parents, we don't consider it any more */
> > + bdrv_parent_drained_end(bs, parent, false);
> > +
> > aio_enable_external(bdrv_get_aio_context(bs));
> > }
> > }
Kevin
next prev parent reply other threads:[~2022-11-15 0:58 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-08 12:37 [PATCH 00/13] block: Simplify drain Kevin Wolf
2022-11-08 12:37 ` [PATCH 01/13] qed: Don't yield in bdrv_qed_co_drain_begin() Kevin Wolf
2022-11-09 9:21 ` Vladimir Sementsov-Ogievskiy
2022-11-09 9:27 ` Vladimir Sementsov-Ogievskiy
2022-11-09 12:22 ` Kevin Wolf
2022-11-09 21:49 ` Stefan Hajnoczi
2022-11-10 11:07 ` Kevin Wolf
2022-11-11 11:14 ` Emanuele Giuseppe Esposito
2022-11-14 18:16 ` Hanna Reitz
2022-11-08 12:37 ` [PATCH 02/13] test-bdrv-drain: Don't yield in .bdrv_co_drained_begin/end() Kevin Wolf
2022-11-09 10:50 ` Vladimir Sementsov-Ogievskiy
2022-11-09 12:28 ` Kevin Wolf
2022-11-09 13:45 ` Vladimir Sementsov-Ogievskiy
2022-11-11 11:14 ` Emanuele Giuseppe Esposito
2022-11-14 18:16 ` Hanna Reitz
2022-11-08 12:37 ` [PATCH 03/13] block: Revert .bdrv_drained_begin/end to non-coroutine_fn Kevin Wolf
2022-11-09 14:29 ` Vladimir Sementsov-Ogievskiy
2022-11-09 22:13 ` Stefan Hajnoczi
2022-11-11 11:14 ` Emanuele Giuseppe Esposito
2022-11-14 18:17 ` Hanna Reitz
2022-11-08 12:37 ` [PATCH 04/13] block: Remove drained_end_counter Kevin Wolf
2022-11-09 14:44 ` Vladimir Sementsov-Ogievskiy
2022-11-11 16:37 ` Kevin Wolf
2022-11-11 11:15 ` Emanuele Giuseppe Esposito
2022-11-14 18:19 ` Hanna Reitz
2022-11-08 12:37 ` [PATCH 05/13] block: Inline bdrv_drain_invoke() Kevin Wolf
2022-11-09 15:34 ` Vladimir Sementsov-Ogievskiy
2022-11-10 19:48 ` Stefan Hajnoczi
2022-11-11 11:15 ` Emanuele Giuseppe Esposito
2022-11-14 18:19 ` Hanna Reitz
2022-11-08 12:37 ` [PATCH 06/13] block: Drain invidual nodes during reopen Kevin Wolf
2022-11-09 16:00 ` Vladimir Sementsov-Ogievskiy
2022-11-11 16:54 ` Kevin Wolf
2022-11-08 12:37 ` [PATCH 07/13] block: Don't use subtree drains in bdrv_drop_intermediate() Kevin Wolf
2022-11-09 16:18 ` Vladimir Sementsov-Ogievskiy
2022-11-14 18:20 ` Hanna Reitz
2022-11-08 12:37 ` [PATCH 08/13] stream: Replace subtree drain with a single node drain Kevin Wolf
2022-11-09 16:52 ` Vladimir Sementsov-Ogievskiy
2022-11-10 10:16 ` Kevin Wolf
2022-11-10 11:25 ` Vladimir Sementsov-Ogievskiy
2022-11-10 17:27 ` Kevin Wolf
2022-11-14 18:21 ` Hanna Reitz
2022-11-08 12:37 ` [PATCH 09/13] block: Remove subtree drains Kevin Wolf
2022-11-09 17:22 ` Vladimir Sementsov-Ogievskiy
2022-11-14 18:22 ` Hanna Reitz
2022-11-08 12:37 ` [PATCH 10/13] block: Call drain callbacks only once Kevin Wolf
2022-11-09 18:05 ` Vladimir Sementsov-Ogievskiy
2022-11-14 12:32 ` Kevin Wolf [this message]
2022-11-09 18:54 ` Vladimir Sementsov-Ogievskiy
2022-11-14 18:23 ` Hanna Reitz
2022-11-08 12:37 ` [PATCH 11/13] block: Remove ignore_bds_parents parameter from drain functions Kevin Wolf
2022-11-09 18:57 ` Vladimir Sementsov-Ogievskiy
2022-11-14 18:23 ` Hanna Reitz
2022-11-08 12:37 ` [PATCH 12/13] block: Don't poll in bdrv_replace_child_noperm() Kevin Wolf
2022-11-11 11:21 ` Emanuele Giuseppe Esposito
2022-11-14 20:22 ` Hanna Reitz
2022-11-17 13:27 ` Kevin Wolf
2022-11-08 12:37 ` [PATCH 13/13] block: Remove poll parameter from bdrv_parent_drained_begin_single() Kevin Wolf
2022-11-14 20:24 ` Hanna Reitz
2022-11-10 20:13 ` [PATCH 00/13] block: Simplify drain Stefan Hajnoczi
2022-11-11 11:23 ` Emanuele Giuseppe Esposito
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=Y3I1Vy5MH5zMhFy6@redhat.com \
--to=kwolf@redhat.com \
--cc=eesposit@redhat.com \
--cc=hreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=vsementsov@yandex-team.ru \
/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).