All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-devel@nongnu.org, Anthony Liguori <aliguori@us.ibm.com>,
	Avi Kivity <avi@redhat.com>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [RFC][PATCH 11/12] qcow2: Convert qcow2 to use	coroutines for async I/O
Date: Wed, 26 Jan 2011 10:08:15 -0600	[thread overview]
Message-ID: <4D4046EF.3050108@codemonkey.ws> (raw)
In-Reply-To: <4D4042A8.2040903@redhat.com>

On 01/26/2011 09:50 AM, Kevin Wolf wrote:
> Am 26.01.2011 16:40, schrieb Avi Kivity:
>    
>> On 01/22/2011 11:29 AM, Stefan Hajnoczi wrote:
>>      
>>> Converting qcow2 to use coroutines is fairly simple since most of qcow2
>>> is synchronous.  The synchronous I/O functions likes bdrv_pread() now
>>> transparently work when called from a coroutine, so all the synchronous
>>> code just works.
>>>
>>> The explicitly asynchronous code is adjusted to repeatedly call
>>> qcow2_aio_read_cb() or qcow2_aio_write_cb() until the request completes.
>>> At that point the coroutine will return from its entry function and its
>>> resources are freed.
>>>
>>> The bdrv_aio_readv() and bdrv_aio_writev() user callback is now invoked
>>> from a BH.  This is necessary since the user callback code does not
>>> expect to be executed from a coroutine.
>>>
>>> This conversion is not completely correct because the safety the
>>> synchronous code does not carry over to the coroutine version.
>>> Previously, a synchronous code path could assume that it will never be
>>> interleaved with another request executing.  This is no longer true
>>> because bdrv_pread() and bdrv_pwrite() cause the coroutine to yield and
>>> other requests can be processed during that time.
>>>
>>> The solution is to carefully introduce checks so that pending requests
>>> do not step on each other's toes.  That is left for a future patch...
>>>        
>> The way I thought of doing this is:
>>
>> qcow_aio_write(...)
>> {
>>       execute_in_coroutine {
>>           co_mutex_lock(&bs->mutex);
>>           do_qcow_aio_write(...); // original qcow code
>>           co_mutex_release(&bs->mutex);
>>      

The release has to be executed in the call back.

I think it's a bit nicer to not do a mutex, but rather to have a notion 
of freezing/unfreezing the block queue and instead do:

completion() {
    bdrv_unfreeze(bs);
}

coroutine {
    bdrv_freeze(bs);
    do_qcow_aio_write(completion);
}

Freeze/unfreeze is useful in a number of other places too (like 
snapshotting).

Regards,

Anthony Liguori

>>       }
>> }
>>
>> (similar changes for the the other callbacks)
>>
>> if the code happens to be asynchronous (no metadata changes), we'll take
>> the mutex and release it immediately after submitting the I/O, so no
>> extra serialization happens.  If the code does issue a synchronous
>> metadata write, we'll lock out all other operations on the same block
>> device, but still allow the vcpu to execute, since all the locking
>> happens in a coroutine.
>>
>> Essentially, a mutex becomes the dependency tracking mechnism.  A global
>> mutex means all synchronous operations are dependent.  Later, we can
>> convert the metadata cache entry dependency lists to local mutexes
>> inside the cache entry structures.
>>      
> I thought a bit about it since you mentioned it in the call yesterday
> and I think this approach makes sense. Even immediately after the
> conversion we should be in a better state than with Stefan's approach
> because I/O without metadata disk access won't be serialized.
>
> In the other thread you mentioned that you have written some code
> independently. Do you have it in some public git repository?
>
> Kevin
>
>    

  reply	other threads:[~2011-01-26 16:08 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-22  9:29 [Qemu-devel] [RFC][PATCH 00/12] qcow2: Convert qcow2 to use coroutines for async I/O Stefan Hajnoczi
2011-01-22  9:29 ` [Qemu-devel] [RFC][PATCH 01/12] coroutine: Add gtk-vnc coroutines library Stefan Hajnoczi
2011-01-26 15:25   ` Avi Kivity
2011-01-26 16:00     ` Anthony Liguori
2011-01-26 16:13       ` Avi Kivity
2011-01-26 16:19         ` Anthony Liguori
2011-01-26 16:22           ` Avi Kivity
2011-01-26 16:29             ` Anthony Liguori
2011-01-26 16:21         ` Anthony Liguori
2011-01-22  9:29 ` [Qemu-devel] [RFC][PATCH 02/12] continuation: Fix container_of() redefinition Stefan Hajnoczi
2011-01-22  9:29 ` [Qemu-devel] [RFC][PATCH 03/12] Make sure to release allocated stack when coroutine is released Stefan Hajnoczi
2011-01-22  9:29 ` [Qemu-devel] [RFC][PATCH 04/12] coroutine: Use thread-local leader and current variables Stefan Hajnoczi
2011-01-22  9:29 ` [Qemu-devel] [RFC][PATCH 05/12] coroutine: Add coroutines Stefan Hajnoczi
2011-01-26 15:29   ` Avi Kivity
2011-01-26 16:00     ` Anthony Liguori
2011-01-27  9:40     ` Stefan Hajnoczi
2011-01-22  9:29 ` [Qemu-devel] [RFC][PATCH 06/12] coroutine: Add qemu_coroutine_self() Stefan Hajnoczi
2011-01-22  9:29 ` [Qemu-devel] [RFC][PATCH 07/12] coroutine: Add coroutine_is_leader() Stefan Hajnoczi
2011-01-22  9:29 ` [Qemu-devel] [RFC][PATCH 08/12] coroutine: Add qemu_in_coroutine() Stefan Hajnoczi
2011-01-22  9:29 ` [Qemu-devel] [RFC][PATCH 09/12] block: Add bdrv_co_readv() and bdrv_co_writev() Stefan Hajnoczi
2011-01-22  9:29 ` [Qemu-devel] [RFC][PATCH 10/12] block: Add coroutine support to synchronous I/O functions Stefan Hajnoczi
2011-01-22  9:29 ` [Qemu-devel] [RFC][PATCH 11/12] qcow2: Convert qcow2 to use coroutines for async I/O Stefan Hajnoczi
2011-01-23 23:40   ` Anthony Liguori
2011-01-24 11:09     ` Stefan Hajnoczi
2011-01-26 15:40   ` Avi Kivity
2011-01-26 15:50     ` Kevin Wolf
2011-01-26 16:08       ` Anthony Liguori [this message]
2011-01-26 16:13         ` Avi Kivity
2011-01-26 16:28           ` Anthony Liguori
2011-01-26 16:38             ` Avi Kivity
2011-01-26 17:12               ` Anthony Liguori
2011-01-27  9:25                 ` Avi Kivity
2011-01-27  9:27                 ` Kevin Wolf
2011-01-27  9:49                   ` Avi Kivity
2011-01-27 10:34                     ` Kevin Wolf
2011-01-27 10:41                       ` Avi Kivity
2011-01-27 11:27                         ` Kevin Wolf
2011-01-27 12:21                           ` Avi Kivity
2011-01-26 16:08       ` Avi Kivity
2011-01-27 10:09     ` Stefan Hajnoczi
2011-01-27 10:46       ` Avi Kivity
2011-01-22  9:29 ` [Qemu-devel] [RFC][PATCH 12/12] qcow2: Serialize all requests Stefan Hajnoczi
2011-01-23 23:31 ` [Qemu-devel] [RFC][PATCH 00/12] qcow2: Convert qcow2 to use coroutines for async I/O Anthony Liguori
2011-02-01 13:23   ` Kevin Wolf
2011-01-24 11:58 ` [Qemu-devel] " Kevin Wolf
2011-01-24 13:10   ` Stefan Hajnoczi

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=4D4046EF.3050108@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.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.