From patchwork Tue Mar 1 12:51:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 8464941 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 81327C0553 for ; Tue, 1 Mar 2016 12:52:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AD2462025A for ; Tue, 1 Mar 2016 12:52:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AA001201FE for ; Tue, 1 Mar 2016 12:52:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753602AbcCAMwV (ORCPT ); Tue, 1 Mar 2016 07:52:21 -0500 Received: from mail-pf0-f180.google.com ([209.85.192.180]:33095 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753553AbcCAMwU (ORCPT ); Tue, 1 Mar 2016 07:52:20 -0500 Received: by mail-pf0-f180.google.com with SMTP id 124so50799214pfg.0; Tue, 01 Mar 2016 04:52:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=vSIrkiq6Xz/nlVY3xIGGti3cOlw3tG6gzkaln3JXFT8=; b=D58/BDx80AacMNrFVi/b4ytChpS3jsigIGQ2LFXsn5oJ6X9OKwCF+oCEM/PvcbFNA0 02bAKEsDIHeh71qew+vEGwozJAPQ7UgeRcDC85v8qRr76pTA+XO+gR7u7lDvxRPLdOgC FKPWNfBt9JilC1eLcuQbQe/8EFZ+7CQv8uTzqFZa1q+aVmzRua7HHoMZMqR8s+rOvLYs gqEom3AwtLul+pGFIfxZcUhobAv+T0HC/iOBwUENw4igAa7qmGVeAJ21AtJxZDVngoR2 nu73l3try3gt5CcwSkxcFvNIoHbhuhVOnkKozJKJ/t5TrW0kzAgBy4L5niFGpjBx2nRh cg7Q== X-Gm-Message-State: AD7BkJJpRbelAulI4JXJAP5aGfWTwAePIHCF3bzjhoHmlk4yEc9l69v5eHFNgq9A1/VvXw== X-Received: by 10.98.71.79 with SMTP id u76mr4866373pfa.122.1456836739329; Tue, 01 Mar 2016 04:52:19 -0800 (PST) Received: from localhost ([45.35.47.131]) by smtp.gmail.com with ESMTPSA id 19sm45479928pfb.64.2016.03.01.04.52.17 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 01 Mar 2016 04:52:18 -0800 (PST) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Ming Lei Subject: [PATCH] blk-merge: compute bio->bi_seg_front_size efficiently Date: Tue, 1 Mar 2016 20:51:58 +0800 Message-Id: <1456836718-11509-1-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.9.1 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It is enough to check and compute bio->bi_seg_front_size just after the 1st segment is found, but current code checks that for each bvec, which is inefficient. This patch follows the way in __blk_recalc_rq_segments() for computing bio->bi_seg_front_size, and it is more efficient and code becomes more readable too. Signed-off-by: Ming Lei --- block/blk-merge.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 2613531..e4c74a0 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -131,22 +131,21 @@ static struct bio *blk_bio_segment_split(struct request_queue *q, bvprvp = &bvprv; sectors += bv.bv_len >> 9; - if (nsegs == 1 && seg_size > front_seg_size) - front_seg_size = seg_size; continue; } new_segment: if (nsegs == queue_max_segments(q)) goto split; + if (nsegs == 1 && seg_size > front_seg_size) + front_seg_size = seg_size; + nsegs++; bvprv = bv; bvprvp = &bvprv; seg_size = bv.bv_len; sectors += bv.bv_len >> 9; - if (nsegs == 1 && seg_size > front_seg_size) - front_seg_size = seg_size; } do_split = false; @@ -159,6 +158,8 @@ split: bio = new; } + if (nsegs == 1 && seg_size > front_seg_size) + front_seg_size = seg_size; bio->bi_seg_front_size = front_seg_size; if (seg_size > bio->bi_seg_back_size) bio->bi_seg_back_size = seg_size;