All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ryan Harper <ryanh@us.ibm.com>
To: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Cc: qemu-devel@nongnu.org, kwolf@redhat.com, aliguori@us.ibm.com,
	stefanha@linux.vnet.ibm.com, kvm@vger.kernel.org,
	mtosatti@redhat.com, zwu.kernel@gmail.com, luowenj@cn.ibm.com,
	raharper@us.ibm.com
Subject: Re: [Qemu-devel] [PATCH v4 2/3] The support for block queue
Date: Mon, 1 Aug 2011 15:21:26 -0500	[thread overview]
Message-ID: <20110801202126.GM7358@us.ibm.com> (raw)
In-Reply-To: <1312179955-23536-3-git-send-email-wuzhy@linux.vnet.ibm.com>

* Zhi Yong Wu <wuzhy@linux.vnet.ibm.com> [2011-08-01 01:30]:

> +static AIOPool block_queue_pool = {
> +    .aiocb_size         = sizeof(struct BlockDriverAIOCB),
> +    .cancel             = qemu_block_queue_cancel,
> +};
> +
> +static void qemu_block_queue_callback(void *opaque, int ret)
> +{
> +    BlockDriverAIOCB *acb = opaque;
> +
> +    qemu_aio_release(acb);
> +}
> +

So, here we really want to invoke the original commands callback, and
then free the request here (via qemu_aio_release()).  see below.


> +BlockDriverAIOCB *qemu_block_queue_enqueue(BlockQueue *queue,
> +                        BlockDriverState *bs,
> +                        BlockRequestHandler *handler,
> +                        int64_t sector_num,
> +                        QEMUIOVector *qiov,
> +                        int nb_sectors,
> +                        BlockDriverCompletionFunc *cb,
> +                        void *opaque)
> +{
> +    BlockIORequest *request;
> +    BlockDriverAIOCB *acb;
> +
> +    request = qemu_malloc(sizeof(BlockIORequest));
> +    request->bs = bs;
> +    request->handler = handler;
> +    request->sector_num = sector_num;
> +    request->qiov = qiov;
> +    request->nb_sectors = nb_sectors;
> +    request->cb = cb;
> +    request->opaque = opaque;
> +
> +    QTAILQ_INSERT_TAIL(&queue->requests, request, entry);
> +
> +    acb = qemu_aio_get(&block_queue_pool, bs,
> +                       qemu_block_queue_callback, opaque);
> +    request->acb = acb;
> +
> +    return acb;
> +}
> +
> +int qemu_block_queue_handler(BlockIORequest *request)
> +{
> +    int ret;
> +    BlockDriverAIOCB *res;
> +
> +    /* indicate this req is from block queue */
> +    request->bs->req_from_queue = true;
> +
> +    res = request->handler(request->bs, request->sector_num,
> +                           request->qiov, request->nb_sectors,
> +                           request->cb, request->opaque);
> +
> +    if (request->acb) {
> +        qemu_block_queue_callback(request->acb, 0);
> +    }
> +
> +    ret = (res == NULL) ? 0 : 1;
> +
> +    return ret;
> +}


You don't want to malloc the BlockIORequest directly in _enqueue(), rather
you want to allocate that from your AIOPool via qemu_aio_get().  As it
is now, we're allocating two BlockIORequests (malloc and then a
aio_get()).  You'll need a BlockDriverAIOCB in the BlockIORequest
structure.  Then in your queue_handler, instead of passing the original
read or write callback (request->cb), you want to hook the block_queue callback
(qemu_block_queue_callback()), in that callback you can then invoke the
request callback and then release the request.

The request should be, only one malloc (via the pool which will re-use
the memory instead of incuring a malloc on every request), and then you 
release the memory back to the pool once your request is complete, which
you'll know after wiring up the block_queue callback to the completion
of the request's handler.  And then since we don't double allocate, you
won't need to do the qemu_free(request) in block.c in block_timer...


-- 
Ryan Harper
Software Engineer; Linux Technology Center
IBM Corp., Austin, Tx
ryanh@us.ibm.com

WARNING: multiple messages have this Message-ID (diff)
From: Ryan Harper <ryanh@us.ibm.com>
To: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Cc: kwolf@redhat.com, aliguori@us.ibm.com,
	stefanha@linux.vnet.ibm.com, kvm@vger.kernel.org,
	mtosatti@redhat.com, qemu-devel@nongnu.org, zwu.kernel@gmail.com,
	luowenj@cn.ibm.com, raharper@us.ibm.com
Subject: Re: [Qemu-devel] [PATCH v4 2/3] The support for block queue
Date: Mon, 1 Aug 2011 15:21:26 -0500	[thread overview]
Message-ID: <20110801202126.GM7358@us.ibm.com> (raw)
In-Reply-To: <1312179955-23536-3-git-send-email-wuzhy@linux.vnet.ibm.com>

* Zhi Yong Wu <wuzhy@linux.vnet.ibm.com> [2011-08-01 01:30]:

> +static AIOPool block_queue_pool = {
> +    .aiocb_size         = sizeof(struct BlockDriverAIOCB),
> +    .cancel             = qemu_block_queue_cancel,
> +};
> +
> +static void qemu_block_queue_callback(void *opaque, int ret)
> +{
> +    BlockDriverAIOCB *acb = opaque;
> +
> +    qemu_aio_release(acb);
> +}
> +

So, here we really want to invoke the original commands callback, and
then free the request here (via qemu_aio_release()).  see below.


> +BlockDriverAIOCB *qemu_block_queue_enqueue(BlockQueue *queue,
> +                        BlockDriverState *bs,
> +                        BlockRequestHandler *handler,
> +                        int64_t sector_num,
> +                        QEMUIOVector *qiov,
> +                        int nb_sectors,
> +                        BlockDriverCompletionFunc *cb,
> +                        void *opaque)
> +{
> +    BlockIORequest *request;
> +    BlockDriverAIOCB *acb;
> +
> +    request = qemu_malloc(sizeof(BlockIORequest));
> +    request->bs = bs;
> +    request->handler = handler;
> +    request->sector_num = sector_num;
> +    request->qiov = qiov;
> +    request->nb_sectors = nb_sectors;
> +    request->cb = cb;
> +    request->opaque = opaque;
> +
> +    QTAILQ_INSERT_TAIL(&queue->requests, request, entry);
> +
> +    acb = qemu_aio_get(&block_queue_pool, bs,
> +                       qemu_block_queue_callback, opaque);
> +    request->acb = acb;
> +
> +    return acb;
> +}
> +
> +int qemu_block_queue_handler(BlockIORequest *request)
> +{
> +    int ret;
> +    BlockDriverAIOCB *res;
> +
> +    /* indicate this req is from block queue */
> +    request->bs->req_from_queue = true;
> +
> +    res = request->handler(request->bs, request->sector_num,
> +                           request->qiov, request->nb_sectors,
> +                           request->cb, request->opaque);
> +
> +    if (request->acb) {
> +        qemu_block_queue_callback(request->acb, 0);
> +    }
> +
> +    ret = (res == NULL) ? 0 : 1;
> +
> +    return ret;
> +}


You don't want to malloc the BlockIORequest directly in _enqueue(), rather
you want to allocate that from your AIOPool via qemu_aio_get().  As it
is now, we're allocating two BlockIORequests (malloc and then a
aio_get()).  You'll need a BlockDriverAIOCB in the BlockIORequest
structure.  Then in your queue_handler, instead of passing the original
read or write callback (request->cb), you want to hook the block_queue callback
(qemu_block_queue_callback()), in that callback you can then invoke the
request callback and then release the request.

The request should be, only one malloc (via the pool which will re-use
the memory instead of incuring a malloc on every request), and then you 
release the memory back to the pool once your request is complete, which
you'll know after wiring up the block_queue callback to the completion
of the request's handler.  And then since we don't double allocate, you
won't need to do the qemu_free(request) in block.c in block_timer...


-- 
Ryan Harper
Software Engineer; Linux Technology Center
IBM Corp., Austin, Tx
ryanh@us.ibm.com

  reply	other threads:[~2011-08-01 20:21 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-01  6:25 [PATCH v4 0/3] The intro for QEMU disk I/O limits Zhi Yong Wu
2011-08-01  6:25 ` [Qemu-devel] " Zhi Yong Wu
2011-08-01  6:25 ` [PATCH v4 1/3] The cmd support for QEMU block I/O throttling Zhi Yong Wu
2011-08-01  6:25   ` [Qemu-devel] " Zhi Yong Wu
2011-08-01  6:25 ` [PATCH v4 2/3] The support for block queue Zhi Yong Wu
2011-08-01  6:25   ` [Qemu-devel] " Zhi Yong Wu
2011-08-01 20:21   ` Ryan Harper [this message]
2011-08-01 20:21     ` Ryan Harper
2011-08-05  2:57     ` Zhi Yong Wu
2011-08-05  2:57       ` Zhi Yong Wu
2011-08-01  6:25 ` [PATCH v4 3/3] The support for queue timer and throttling algorithm Zhi Yong Wu
2011-08-01  6:25   ` [Qemu-devel] " Zhi Yong Wu
2011-08-01 20:39   ` Ryan Harper
2011-08-01 20:39     ` Ryan Harper
2011-08-05  2:48     ` Zhi Yong Wu
2011-08-05  2:48       ` Zhi Yong Wu
2011-08-01 20:06 ` [PATCH v4 0/3] The intro for QEMU disk I/O limits Ryan Harper
2011-08-01 20:06   ` [Qemu-devel] " Ryan Harper
2011-08-05  2:20   ` Zhi Yong Wu
2011-08-05  2:20     ` Zhi Yong Wu

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=20110801202126.GM7358@us.ibm.com \
    --to=ryanh@us.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwolf@redhat.com \
    --cc=luowenj@cn.ibm.com \
    --cc=mtosatti@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=raharper@us.ibm.com \
    --cc=stefanha@linux.vnet.ibm.com \
    --cc=wuzhy@linux.vnet.ibm.com \
    --cc=zwu.kernel@gmail.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.