From: Stefan Hajnoczi <stefanha@redhat.com>
To: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
qemu-block@nongnu.org, qemu-devel@nongnu.org,
Max Reitz <mreitz@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>, John Snow <jsnow@redhat.com>
Subject: Re: [PATCH v2 0/7] block-copy: protect block-copy internal structures
Date: Thu, 27 May 2021 11:31:22 +0100 [thread overview]
Message-ID: <YK90+mIIjmgFJ8So@stefanha-x1.localdomain> (raw)
In-Reply-To: <20210518100757.31243-1-eesposit@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 3382 bytes --]
On Tue, May 18, 2021 at 12:07:50PM +0200, Emanuele Giuseppe Esposito wrote:
> This serie of patches aims to reduce the usage of the global
> AioContexlock in block-copy, by introducing smaller granularity
> locks thus on making the block layer thread safe.
>
> This serie depends on Paolo's coroutine_sleep API and my previous
> serie that brings thread safety to the smaller API used by block-copy,
> like ratelimit, progressmeter abd co-shared-resource.
>
> What's missing for block-copy to be fully thread-safe is fixing
> the CoSleep API to allow cross-thread sleep and wakeup.
> Paolo is working on it and will post the patches once his new
> CoSleep API is accepted.
>
> Patch 1 introduces the .method field instead of .use_copy_range
> and .copy_size, so that it can be later used as atomic.
> Patch 2-3 provide comments and refactoring in preparation to
> the locks added in patch 4 on BlockCopyTask, patch 5-6 on
> BlockCopyCallState and 7 BlockCopyState.
>
> Based-on: <20210517100548.28806-1-pbonzini@redhat.com>
> Based-on: <20210518094058.25952-1-eesposit@redhat.com>
> Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Here is my understanding of thread-safety in your
https://gitlab.com/eesposit/qemu.git dataplane_new branch:
Reading the code was much more satisfying than trying to review the
patches. That's probably because I'm not familiar with the block-copy.c
implementation and needed the context. I noticed you already addressed
some of Vladimir's comments in your git branch, so that may have helped
too.
The backup block job and the backup-top filter driver have a
BlockCopyState. QEMU threads that call bdrv_co_preadv/pwritev() invoke
the block_copy() coroutine function, so BlockCopyState needs to be
protected between threads. Additionally, the backup block job invokes
block_copy_async() to perform a background copy operation.
The relationships are as follows:
BlockCopyState - shared state that any thread can access
BlockCopyCallState - per-block_copy()/block_copy_async() state, not
accessed by other coroutines/threads
BlockCopyTask - per-aiotask state, find_conflicting_task_locked()
accesses this for a given BlockCopyState
What is the purpose of the BlockCopyState->calls list?
Existing issue: the various
block_copy_call_finished/succeeded/failed/cancelled/status() APIs are a
bit extreme. They all end up being called by block/backup.c in
succession when it seems like a single call should be enough to report
the status.
It's not immediately obvious to me that BlockCopyCallState needs to be
thread-safe. So I wondered why finished needs to be atomic. Then I
realized the set_speed/cancel code runs in the monitor, so at least
block_copy_call_cancel() and block_copy_kick() need to be thread-safe. I
guess the BlockCopyCallState status APIs were made thread-safe for
consistency even though it's not needed at the moment?
Please add doc comments to block-copy.h explaining the thread-safety of
the APIs (it might be as simple as "all APIs are thread-safe" at the top
of the file).
Summarizing everything, this series adds BlockCopyState->lock to protect
shared state and makes BlockCopyCallState's status atomic so it can be
queried from threads other than the one performing the copy operation.
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
prev parent reply other threads:[~2021-05-27 13:02 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-18 10:07 [PATCH v2 0/7] block-copy: protect block-copy internal structures Emanuele Giuseppe Esposito
2021-05-18 10:07 ` [PATCH v2 1/7] block-copy: streamline choice of copy_range vs. read/write Emanuele Giuseppe Esposito
2021-05-20 14:42 ` Vladimir Sementsov-Ogievskiy
2021-05-20 15:06 ` Emanuele Giuseppe Esposito
2021-05-20 15:24 ` Vladimir Sementsov-Ogievskiy
2021-05-21 15:10 ` Paolo Bonzini
2021-05-21 15:48 ` Vladimir Sementsov-Ogievskiy
2021-05-21 16:43 ` Paolo Bonzini
2021-05-21 17:51 ` Vladimir Sementsov-Ogievskiy
2021-05-27 8:20 ` Stefan Hajnoczi
2021-05-27 19:04 ` Paolo Bonzini
2021-05-18 10:07 ` [PATCH v2 2/7] block-copy: improve documentation of BlockCopyTask and BlockCopyState types and functions Emanuele Giuseppe Esposito
2021-05-20 15:00 ` Vladimir Sementsov-Ogievskiy
2021-05-20 15:15 ` Emanuele Giuseppe Esposito
2021-05-18 10:07 ` [PATCH v2 3/7] block-copy: move progress_set_remaining in block_copy_task_end Emanuele Giuseppe Esposito
2021-05-20 15:03 ` Vladimir Sementsov-Ogievskiy
2021-05-18 10:07 ` [PATCH v2 4/7] block-copy: add a CoMutex to the BlockCopyTask list Emanuele Giuseppe Esposito
2021-05-20 15:19 ` Vladimir Sementsov-Ogievskiy
2021-05-25 10:07 ` Emanuele Giuseppe Esposito
2021-05-25 10:25 ` Vladimir Sementsov-Ogievskiy
2021-05-26 14:58 ` Paolo Bonzini
2021-05-26 16:13 ` Vladimir Sementsov-Ogievskiy
2021-05-27 9:07 ` Stefan Hajnoczi
2021-05-18 10:07 ` [PATCH v2 5/7] block-copy: add QemuMutex lock for BlockCopyCallState list Emanuele Giuseppe Esposito
2021-05-20 15:30 ` Vladimir Sementsov-Ogievskiy
2021-05-21 15:01 ` Paolo Bonzini
2021-05-25 10:58 ` Emanuele Giuseppe Esposito
2021-05-26 14:49 ` Paolo Bonzini
2021-05-28 10:53 ` Paolo Bonzini
2021-05-18 10:07 ` [PATCH v2 6/7] block-copy: atomic .cancelled and .finished fields in BlockCopyCallState Emanuele Giuseppe Esposito
2021-05-20 15:34 ` Vladimir Sementsov-Ogievskiy
2021-05-21 15:02 ` Paolo Bonzini
2021-05-21 15:53 ` Vladimir Sementsov-Ogievskiy
2021-05-21 15:56 ` Vladimir Sementsov-Ogievskiy
2021-05-21 16:47 ` Paolo Bonzini
2021-05-18 10:07 ` [PATCH v2 7/7] block-copy: protect BlockCopyState .method fields Emanuele Giuseppe Esposito
2021-05-21 17:10 ` Vladimir Sementsov-Ogievskiy
2021-05-25 10:18 ` Emanuele Giuseppe Esposito
2021-05-25 11:00 ` Vladimir Sementsov-Ogievskiy
2021-05-26 14:48 ` Paolo Bonzini
2021-05-26 17:18 ` Vladimir Sementsov-Ogievskiy
2021-05-28 10:24 ` Paolo Bonzini
2021-05-28 11:01 ` Paolo Bonzini
2021-05-28 11:52 ` Vladimir Sementsov-Ogievskiy
2021-05-28 12:44 ` Vladimir Sementsov-Ogievskiy
2021-05-20 13:47 ` [PATCH v2 0/7] block-copy: protect block-copy internal structures Vladimir Sementsov-Ogievskiy
2021-05-20 14:33 ` Emanuele Giuseppe Esposito
2021-05-27 10:31 ` Stefan Hajnoczi [this message]
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=YK90+mIIjmgFJ8So@stefanha-x1.localdomain \
--to=stefanha@redhat.com \
--cc=eesposit@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@virtuozzo.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).