QEMU-Devel Archive on lore.kernel.org
 help / color / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>, qemu-block@nongnu.org
Cc: jsnow@redhat.com, qemu-devel@nongnu.org
Subject: Re: [PATCH v2 2/2] mirror: Wait only for in-flight operations
Date: Thu, 26 Mar 2020 19:27:14 +0100
Message-ID: <09eee5b4-71aa-97a2-1ea9-c6bfc313e77f@redhat.com> (raw)
In-Reply-To: <20200326153628.4869-3-kwolf@redhat.com>

[-- Attachment #1.1: Type: text/plain, Size: 3101 bytes --]

On 26.03.20 16:36, Kevin Wolf wrote:
> mirror_wait_for_free_in_flight_slot() just picks a random operation to
> wait for. However, a MirrorOp is already in s->ops_in_flight when
> mirror_co_read() waits for free slots, so if not enough slots are
> immediately available, an operation can end up waiting for itself, or
> two or more operations can wait for each other to complete, which
> results in a hang.
> Fix this by adding a flag to MirrorOp that tells us if the request is
> already in flight (and therefore occupies slots that it will later
> free), and picking only such operations for waiting.
> Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1794692
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  block/mirror.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> diff --git a/block/mirror.c b/block/mirror.c
> index 393131b135..88414d1653 100644
> --- a/block/mirror.c
> +++ b/block/mirror.c


> @@ -1318,6 +1324,7 @@ static MirrorOp *coroutine_fn active_write_prepare(MirrorBlockJob *s,
>          .offset             = offset,
>          .bytes              = bytes,
>          .is_active_write    = true,
> +        .is_in_flight       = true,
>      };
>      qemu_co_queue_init(&op->waiting_requests);
>      QTAILQ_INSERT_TAIL(&s->ops_in_flight, op, next);

There is a mirror_wait_on_conflicts() call after this.  I was a bit
worried about dependencies there.  But I don’t think there’s any
problem, because mirror_wait_for_any_operation() is only called by:

(1) mirror_wait_for_free_in_flight_slot(), which makes it look for
non-active operations only, and

(2) mirror_run(), which specifically waits for all active operations to
settle, so it makes sense to wait for all of them, even when they are
still doing their own dependency-waiting.

But still, I’m not sure whether this is conceptually the best thing to
do.  I think what we actually want is for
mirror_wait_for_free_in_flight_slot() to only wait for in-flight
operations; but the call in mirror_run() that waits for active-mirror
operations wants to wait for all active-mirror operations, not just the
ones that are in flight.

So I think conceptually it would make more sense to set is_in_flight
only after mirror_wait_on_conflicts(), and ensure that the
mirror_wait_for_any_operation() call from mirror_run() ignores
is_in_flight.  E.g. by having another parameter “bool in_flight” for
mirror_wait_for_any_operation() that chooses whether to check
is_in_flight or whether to ignore it.

In practice, @in_flight would always be the same as @active, but they
are different things.  But that would mean we would always ignore
is_in_flight for active-mirror operations.

In practice, there’s no difference to what this patch does, i.e. to just
let active-mirror operations have is_in_flight to be always true and let
mirror_wait_for_any_operation() check is_in_flight unconditionally.

So I don’t know.  Maybe this is a start:

Functionally-reviewed-by: Max Reitz <mreitz@redhat.com>


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-26 15:36 [PATCH v2 0/2] mirror: Fix hang (operation waiting for itself/circular dependency) Kevin Wolf
2020-03-26 15:36 ` [PATCH v2 1/2] Revert "mirror: Don't let an operation wait for itself" Kevin Wolf
2020-03-26 15:36 ` [PATCH v2 2/2] mirror: Wait only for in-flight operations Kevin Wolf
2020-03-26 18:27   ` Max Reitz [this message]
2020-03-26 15:53 ` [PATCH v2 0/2] mirror: Fix hang (operation waiting for itself/circular dependency) Eric Blake

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=09eee5b4-71aa-97a2-1ea9-c6bfc313e77f@redhat.com \
    --to=mreitz@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

QEMU-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/qemu-devel/0 qemu-devel/git/0.git
	git clone --mirror https://lore.kernel.org/qemu-devel/1 qemu-devel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 qemu-devel qemu-devel/ https://lore.kernel.org/qemu-devel \
	public-inbox-index qemu-devel

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git