qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Francesco Romani <fromani@redhat.com>
Cc: kwolf@redhat.com, mdroth@linux.vnet.ibm.com,
	qemu-devel@nongnu.org, lcapitulino@redhat.com
Subject: Re: [Qemu-devel] [PATCH] block: add watermark event
Date: Fri, 1 Aug 2014 12:39:40 +0100	[thread overview]
Message-ID: <20140801113940.GC7258@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <1404830964-10733-2-git-send-email-fromani@redhat.com>

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

On Tue, Jul 08, 2014 at 04:49:24PM +0200, Francesco Romani wrote:
> @@ -5813,3 +5815,57 @@ void bdrv_flush_io_queue(BlockDriverState *bs)
>          bdrv_flush_io_queue(bs->file);
>      }
>  }
> +
> +static bool watermark_exceeded(BlockDriverState *bs,
> +                               int64_t sector_num,
> +                               int nb_sectors)
> +{
> +
> +    if (bs->wr_watermark_perc > 0) {
> +        int64_t watermark = (bs->total_sectors) / 100 * bs->wr_watermark_perc;

bs->total_sectors should not be used directly.

Have you considered making the watermark parameter take sector units
instead of a percentage?

I'm not sure whether a precentage makes sense because 25% of a 10GB
image is 2.5 GB so a 75% watermark might be reasonable.  25% of a 1 TB
image is 250 GB and that's probably not a reasonable watermark.

So let the block-set-watermark caller pass an absolute sector number
instead.  It keeps things simple for both QEMU and thin provisioning
manager.

> +        if (sector_num >= watermark) {
> +            return true;
> +        }
> +    }
> +    return false;
> +}
> +
> +static int coroutine_fn watermark_before_write_notify(NotifierWithReturn *notifier,
> +                                                      void *opaque)
> +{
> +    BdrvTrackedRequest *req = opaque;
> +    int64_t sector_num = req->offset >> BDRV_SECTOR_BITS;
> +    int nb_sectors = req->bytes >> BDRV_SECTOR_BITS;
> +
> +/*  FIXME: needed? */
> +    assert((req->offset & (BDRV_SECTOR_SIZE - 1)) == 0);
> +    assert((req->bytes & (BDRV_SECTOR_SIZE - 1)) == 0);

Not really needed here.  Emulated storage controllers either get
requests in block units (i.e. they are automatically aligned) or check
them (like virtio-blk).

I guess there's no harm in checking, but I would drop it.

> +
> +    if (watermark_exceeded(req->bs, sector_num, nb_sectors)) {
> +        BlockDriverState *bs = req->bs;
> +        qapi_event_send_block_watermark(
> +            bdrv_get_device_name(bs),
> +            sector_num,
> +            bs->wr_highest_sector,
> +            &error_abort);

How do you prevent flooding events if every write request exceeds the
watermark?

Perhaps the watermark should be disabled until block-set-watermark is
called again.

> +    }
> +
> +    return 0; /* should always let other notifiers run */
> +}
> +
> +void bdrv_set_watermark_perc(BlockDriverState *bs,
> +                             int watermark_perc)
> +{
> +    NotifierWithReturn before_write = {
> +        .notify = watermark_before_write_notify,
> +    };
> +
> +    if (watermark_perc <= 0) {
> +        return;
> +    }
> +
> +    if (bs->wr_watermark_perc == 0) {
> +        bdrv_add_before_write_notifier(bs, &before_write);

before_write must be a BlockDriverState field so it has the correct
lifetime.  In this patch before_write is allocated on the stack and will
cause invalid memory accesses once we leave this function.

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

  parent reply	other threads:[~2014-08-01 11:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-08 14:49 [Qemu-devel] [PATCH] add watermark reporting for block devices Francesco Romani
2014-07-08 14:49 ` [Qemu-devel] [PATCH] block: add watermark event Francesco Romani
2014-07-08 15:10   ` Eric Blake
2014-08-01 11:39   ` Stefan Hajnoczi [this message]
2014-08-05  8:47     ` Kevin Wolf
2014-08-05 13:08       ` Stefan Hajnoczi
2014-08-08  8:01         ` Francesco Romani
2014-08-08 12:51           ` Eric Blake
2014-07-08 14:51 ` [Qemu-devel] [RFC] add watermark reporting for block devices Francesco Romani

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=20140801113940.GC7258@stefanha-thinkpad.redhat.com \
    --to=stefanha@redhat.com \
    --cc=fromani@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /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).