qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Dou Liyang <douly.fnst@cn.fujitsu.com>
Cc: stefanha@redhat.com, kwolf@redhat.com, armbru@redhat.com,
	mreitz@redhat.com, eblake@redhat.com, famz@redhat.com,
	danpb@redhat.com, izumi.taku@jp.fujitsu.com,
	caoj.fnst@cn.fujitsu.com, fanc.fnst@cn.fujitsu.com,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH RFC v2 3/4] block/qapi: acquire a reference instead of a lock during querying blockstats
Date: Mon, 19 Dec 2016 14:34:52 +0000	[thread overview]
Message-ID: <20161219143452.GG17374@stefanha-x1.localdomain> (raw)
In-Reply-To: <1482137486-9843-4-git-send-email-douly.fnst@cn.fujitsu.com>

[-- Attachment #1: Type: text/plain, Size: 2574 bytes --]

On Mon, Dec 19, 2016 at 04:51:25PM +0800, Dou Liyang wrote:
> This patch works to improve the performance of the query requests.
> 
> From the commit 13344f3a, it adds a lock to make query-blockstats
> safe by the aio_context_acquire(). the qmp_query_blockstats func
> requires/releases the AioContext lock, which takes some time and
> blocks the I/O processing. It affects the performance, especially
> in the multi-disks guests.
> 
> As the low-level details of block statistics inside QEMU, we can
> acquire a reference instead of the lock.
> 
> Signed-off-by: Dou Liyang <douly.fnst@cn.fujitsu.com>
> ---
>  block/qapi.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)

This patch changes the locking rules for blk_get_stats() (this covers a
lot of fields), bdrv_get_node_name(), and blk_name().

You must document the new locking rules for these fields in
block-backend.h, block_int.h, etc.

> diff --git a/block/qapi.c b/block/qapi.c
> index bc622cd..2262918 100644
> --- a/block/qapi.c
> +++ b/block/qapi.c
> @@ -457,17 +457,21 @@ static BlockStats *bdrv_query_bds_stats(const BlockDriverState *bs,
>  }
>  
>  static BlockStats *bdrv_query_stats(BlockBackend *blk,
> -                                    const BlockDriverState *bs,
> +                                    BlockDriverState *bs,
>                                      bool query_backing)
>  {
>      BlockStats *s;
>  
> +    bdrv_ref(bs);
>      s = bdrv_query_bds_stats(bs, query_backing);
> +    bdrv_unref(bs);
>  
>      if (blk) {
> +        blk_ref(blk);
>          s->has_device = true;
>          s->device = g_strdup(blk_name(blk));
>          bdrv_query_blk_stats(s->stats, blk);
> +        blk_unref(blk);

This does not look correct.  The caller passed in bs and blk so they
must already have a reference.  If not, then what protects bs and blk
from deletion before/after this function is called?

>      }
>  
>      return s;
> @@ -523,13 +527,8 @@ BlockStatsList *qmp_query_blockstats(bool has_query_nodes,
>  
>      while (next_query_bds(&blk, &bs, query_nodes)) {
>          BlockStatsList *info = g_malloc0(sizeof(*info));
> -        AioContext *ctx = blk ? blk_get_aio_context(blk)
> -                              : bdrv_get_aio_context(bs);
>  
> -        aio_context_acquire(ctx);
>          info->value = bdrv_query_stats(blk, bs, !query_nodes);
> -        aio_context_release(ctx);
> -
>          *p_next = info;
>          p_next = &info->next;
>      }
> -- 
> 2.5.5
> 
> 
> 
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

  reply	other threads:[~2016-12-19 14:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-19  8:51 [Qemu-devel] [PATCH RFC v2 0/4] block/qapi: refactor and optimize the qmp_query_blockstats() Dou Liyang
2016-12-19  8:51 ` [Qemu-devel] [PATCH RFC v2 1/4] block: refactor bdrv_next_node for readability Dou Liyang
2016-12-19 14:19   ` Stefan Hajnoczi
2016-12-19  8:51 ` [Qemu-devel] [PATCH RFC v2 2/4] block/qapi: reduce the coupling between the bdrv_query_stats and bdrv_query_bds_stats Dou Liyang
2016-12-19  8:51 ` [Qemu-devel] [PATCH RFC v2 3/4] block/qapi: acquire a reference instead of a lock during querying blockstats Dou Liyang
2016-12-19 14:34   ` Stefan Hajnoczi [this message]
2016-12-19  8:51 ` [Qemu-devel] [PATCH RFC v2 4/4] block/qapi: optimize the query function of the blockstats Dou Liyang
2016-12-19 15:02 ` [Qemu-devel] [PATCH RFC v2 0/4] block/qapi: refactor and optimize the qmp_query_blockstats() Stefan Hajnoczi
2016-12-19 16:32   ` Fam Zheng
2016-12-20  9:39     ` Stefan Hajnoczi
2016-12-20  9:54       ` Dou Liyang
2016-12-20 10:01         ` Stefan Hajnoczi
2016-12-20 10:26           ` Dou Liyang
2016-12-20 11:09             ` Stefan Hajnoczi
2016-12-21  9:13       ` Dou Liyang
2016-12-21 11:06         ` Stefan Hajnoczi
2016-12-22 10:20           ` Dou Liyang
2016-12-20  9:47     ` Dou Liyang

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=20161219143452.GG17374@stefanha-x1.localdomain \
    --to=stefanha@gmail.com \
    --cc=armbru@redhat.com \
    --cc=caoj.fnst@cn.fujitsu.com \
    --cc=danpb@redhat.com \
    --cc=douly.fnst@cn.fujitsu.com \
    --cc=eblake@redhat.com \
    --cc=famz@redhat.com \
    --cc=fanc.fnst@cn.fujitsu.com \
    --cc=izumi.taku@jp.fujitsu.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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).