From: Gonglei <arei.gonglei@huawei.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org,
mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH] virtio-blk: trivial code optimization
Date: Mon, 9 Nov 2015 10:08:02 +0800 [thread overview]
Message-ID: <56400002.9010708@huawei.com> (raw)
In-Reply-To: <563CA317.6080906@redhat.com>
On 2015/11/6 20:54, Paolo Bonzini wrote:
>
>
> On 06/11/2015 11:35, Stefan Hajnoczi wrote:
>>>> if (niov + req->qiov.niov > IOV_MAX) {
>>>> merge = false;
>>>> + goto unmerge;
>>>> }
>>>>
>>>> /* merge would exceed maximum transfer length of backend device */
>>>> if (req->qiov.size / BDRV_SECTOR_SIZE + nb_sectors > max_xfer_len) {
>>>> merge = false;
>>>> + goto unmerge;
>>>> }
>>>>
>>>> /* requests are not sequential */
>>>> if (sector_num + nb_sectors != req->sector_num) {
>>>> merge = false;
>>>> }
>>>> -
>>>> +unmerge:
>> C has a way of expressing this without gotos. Please use else if:
>>
>> if (a) {
>> ...
>> } else if (b) {
>> ...
>> } else if (c) {
>> ...
>> }
>
> Another way is
>
> if (niov + req->qiov.niov > IOV_MAX ||
> req->qiov.size / BDRV_SECTOR_SIZE + nb_sectors > max_xfer_len ||
> sector_num + nb_sectors != req->sector_num) {
> submit_requests(...)
> ...
> }
>
> While at it, we could reorder the conditions so that the most common
> ("requests are not sequential") comes first.
>
> I'm not sure about handling of overflow. It's probably better to
> write conditions as "new > max - old" (e.g. "niov > IOV_MAX -
> req->qiov.niov") rather than "old + new > max". The former is always
> safe, because we know that old <= max and there can be no integer
> overflow.
>
Nice points. Thanks, both of you.
Regards,
-Gonglei
prev parent reply other threads:[~2015-11-09 2:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-06 1:04 [Qemu-devel] [PATCH] virtio-blk: trivial code optimization arei.gonglei
2015-11-06 10:35 ` Stefan Hajnoczi
2015-11-06 12:54 ` Paolo Bonzini
2015-11-09 2:08 ` Gonglei [this message]
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=56400002.9010708@huawei.com \
--to=arei.gonglei@huawei.com \
--cc=kwolf@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--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).