Received: from eggs.gnu.org ([2001:4830:134:3::10]:34382) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEaPg-00027N-Nj for qemu-devel@nongnu.org; Tue, 05 Aug 2014 04:48:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XEaPa-0003Ub-ES for qemu-devel@nongnu.org; Tue, 05 Aug 2014 04:48:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10003) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEaPa-0003UU-7B for qemu-devel@nongnu.org; Tue, 05 Aug 2014 04:48:02 -0400 Date: Tue, 5 Aug 2014 10:47:57 +0200 From: Kevin Wolf Message-ID: <20140805084757.GB4391@noname.str.redhat.com> References: <1404830964-10733-1-git-send-email-fromani@redhat.com> <1404830964-10733-2-git-send-email-fromani@redhat.com> <20140801113940.GC7258@stefanha-thinkpad.redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="LZvS9be/3tNcYl/X" Content-Disposition: inline In-Reply-To: <20140801113940.GC7258@stefanha-thinkpad.redhat.com> Subject: Re: [Qemu-devel] [PATCH] block: add watermark event List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: mdroth@linux.vnet.ibm.com, Francesco Romani , qemu-devel@nongnu.org, lcapitulino@redhat.com --LZvS9be/3tNcYl/X Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Am 01.08.2014 um 13:39 hat Stefan Hajnoczi geschrieben: > 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 =3D (bs->total_sectors) / 100 * bs->wr_water= mark_perc; >=20 > bs->total_sectors should not be used directly. >=20 > Have you considered making the watermark parameter take sector units > instead of a percentage? >=20 > 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. >=20 > So let the block-set-watermark caller pass an absolute sector number > instead. It keeps things simple for both QEMU and thin provisioning > manager. No sector numbers in external interfaces, please. These units of 512 bytes are completely arbitrary and don't make any sense. I hope to get rid of BDRV_SECTOR_* eventually even internally. So for external APIs, please use bytes instead. > > + if (sector_num >=3D watermark) { > > + return true; > > + } > > + } > > + return false; > > +} > > + > > +static int coroutine_fn watermark_before_write_notify(NotifierWithRetu= rn *notifier, > > + void *opaque) > > +{ > > + BdrvTrackedRequest *req =3D opaque; > > + int64_t sector_num =3D req->offset >> BDRV_SECTOR_BITS; > > + int nb_sectors =3D req->bytes >> BDRV_SECTOR_BITS; > > + > > +/* FIXME: needed? */ > > + assert((req->offset & (BDRV_SECTOR_SIZE - 1)) =3D=3D 0); > > + assert((req->bytes & (BDRV_SECTOR_SIZE - 1)) =3D=3D 0); >=20 > 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). But we don't only get requests from emulated storage controllers. You cannot reasonably assume anything here (the requests are aligned according to the requirements of the backend, but that may just be 1). Again, do your calculations in a byte granularity to be safe here. > I guess there's no harm in checking, but I would drop it. >=20 > > + > > + if (watermark_exceeded(req->bs, sector_num, nb_sectors)) { > > + BlockDriverState *bs =3D req->bs; > > + qapi_event_send_block_watermark( > > + bdrv_get_device_name(bs), > > + sector_num, > > + bs->wr_highest_sector, > > + &error_abort); >=20 > How do you prevent flooding events if every write request exceeds the > watermark? >=20 > Perhaps the watermark should be disabled until block-set-watermark is > called again. I agree. Kevin --LZvS9be/3tNcYl/X Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAEBAgAGBQJT4Jo8AAoJEH8JsnLIjy/WbSEP/jN+u/Hr8s1DPqUrSeSqTxBU uOs+ZN6UF3ZJYiAsX9QXPMDPLqlN4agE2OWhKwpQDWt1MuJvWSAP+czPjcIfPcLC 1GxbupHK7qHUWuujvRIP8eu/+9l/FQsG//y3J7eUmKWoSLW4UrjgIFNbr/HNkNjc QgFDOXJl80YygwtMFdLQ2c0h7Rgyh53dzrQkz5yJ40kQm7anffoim/WzK8Tlh1nJ X2z0+6OA2p4fcsxiccTQ+qBCOrvU6tDvcvRLUzZniFv7H4x2d8Cvu8L+BzhuSEsr FyosbEBKtPLR0TgqZBTl26vua4Wg4qCmK/QY4EJCKWXk5O6TLCPw8cpAKymsnbgc uhYH6FF+zohdZig0SFOBJT9pHqispNltCfFeJfD8PX3ASCXhwCXr1I0sexCtZ8tZ WsJTdethA57ZoLRA78GvLlCMkB3pautaqLbMYEnLQxdU1CjLEFh6LYkGyvU+QBKc O8l2FCs90SrGTym+0Ono4Zm6sraLZIFjPfthbpRSAIy3PHaoWPtxZyZyY7rkUbec 2pLbJYt7PvXngYP/mTPrRhawhuSH5dPl1V2pldfTo8amSVH7Vx1oTIJwJqIcpimo cGWBg+q8fYlhywkdNBFgY62BR8HUZl1C1j/aO56bOUIUhMnQONK0VmaztXPjLvY8 4kZXPMquSeCmXlaGfXbI =cBOw -----END PGP SIGNATURE----- --LZvS9be/3tNcYl/X--