From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53053) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZvmVS-0000H4-US for qemu-devel@nongnu.org; Mon, 09 Nov 2015 08:29:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZvmVR-0003lM-Ua for qemu-devel@nongnu.org; Mon, 09 Nov 2015 08:29:10 -0500 References: <1447059810-11376-1-git-send-email-arei.gonglei@huawei.com> From: Paolo Bonzini Message-ID: <56409F9B.8060202@redhat.com> Date: Mon, 9 Nov 2015 14:28:59 +0100 MIME-Version: 1.0 In-Reply-To: <1447059810-11376-1-git-send-email-arei.gonglei@huawei.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3] virtio-blk: trivial code optimization List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: arei.gonglei@huawei.com, qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, stefanha@redhat.com On 09/11/2015 10:03, arei.gonglei@huawei.com wrote: > From: Gonglei > > 1. avoid possible superflous checking > 2. make code more robustness > > Signed-off-by: Gonglei > Reviewed-by: Fam Zheng > --- > v3: change the third condition too [Paolo] > add Fam's R-by > --- > hw/block/virtio-blk.c | 27 +++++++++------------------ > 1 file changed, 9 insertions(+), 18 deletions(-) > > diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c > index 093e475..9124358 100644 > --- a/hw/block/virtio-blk.c > +++ b/hw/block/virtio-blk.c > @@ -404,24 +404,15 @@ void virtio_blk_submit_multireq(BlockBackend *blk, MultiReqBuffer *mrb) > for (i = 0; i < mrb->num_reqs; i++) { > VirtIOBlockReq *req = mrb->reqs[i]; > if (num_reqs > 0) { > - bool merge = true; > - > - /* merge would exceed maximum number of IOVs */ > - if (niov + req->qiov.niov > IOV_MAX) { > - merge = false; > - } > - > - /* merge would exceed maximum transfer length of backend device */ > - if (req->qiov.size / BDRV_SECTOR_SIZE + nb_sectors > max_xfer_len) { > - merge = false; > - } > - > - /* requests are not sequential */ > - if (sector_num + nb_sectors != req->sector_num) { > - merge = false; > - } > - > - if (!merge) { > + /* > + * NOTE: We cannot merge the requests in below situations: > + * 1. requests are not sequential > + * 2. merge would exceed maximum number of IOVs > + * 3. merge would exceed maximum transfer length of backend device > + */ > + if (sector_num + nb_sectors != req->sector_num || > + niov > IOV_MAX - req->qiov.niov || > + nb_sectors > max_xfer_len - req->qiov.size / BDRV_SECTOR_SIZE) { > submit_requests(blk, mrb, start, num_reqs, niov); > num_reqs = 0; > } > Reviewed-by: Paolo Bonzini