From patchwork Tue Dec 27 15:56:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9489443 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DEE5362AAD for ; Tue, 27 Dec 2016 16:03:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF977201BC for ; Tue, 27 Dec 2016 16:03:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C38542094F; Tue, 27 Dec 2016 16:03:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9CC0223B2 for ; Tue, 27 Dec 2016 16:03:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755998AbcL0QCg (ORCPT ); Tue, 27 Dec 2016 11:02:36 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:36698 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755703AbcL0QB3 (ORCPT ); Tue, 27 Dec 2016 11:01:29 -0500 Received: by mail-pg0-f68.google.com with SMTP id n5so12798110pgh.3; Tue, 27 Dec 2016 08:01:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xrkjwlMKjpnbHme4iylSQ8QY2X8G/RhsLMMjFxRzPsA=; b=QvMJiIhFxhd4U1qjn8TKhqzlFtzbfZiaok7zxyqHPPo27dwSXCiUrCN0AW8Z7Wpppg Qu1v9XF277A5GSXpWqI0EvkqvBVoxFlMtyNFEgKU60s9KFH6RHgz85AbF4XFHohUBIA8 7YgRKoHfLNnFOyqG0aBPP3kYGAgq1ZzvCmBWGgVsf6oK1Oah5u9SddMc55Bj9eFo930C zknCZDeJqBjJALyxgH+kMExwOz5KfB+SR+MF/0if74D7h/wrPvHmOCYjugbY/iGzUMKG S7Yk5NsiSTrtqWFJ5wnfuOW3luFr/kXXaNpt1g7vXbdE5R2hQNi3K5EjA8sgCH0Zr7yV AMrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xrkjwlMKjpnbHme4iylSQ8QY2X8G/RhsLMMjFxRzPsA=; b=GldoLgmTJsE40XNhpzXfeSLNVR7N1PSLm6e6A++d34C29Lkp0E7hQxNOPSAToigEvP 1QmvyvDxkLSs3Yp9Jr+EwAujWrQpJSSbJHJ5spuz2opeRNJoAUxzp9anplbhjZwBxrff uxBqKWKzBw+5ApNBLmmP5z/0VQc66FmRFirDWsni+MKQtW5wkqQ4kkmoWkXBAS8irRyY lfy01+Al5Hgx06eZl3Z0PcUMvjiVPEMcI2TvuVp7Ki/TZGBFaXTcmGegztBTmW+ekr2r DybcOoNpDYFL8ORqZ6tWPQSdqoRJWpSFw83MFD+4df1Ibo4xJeE9yac1aBDwz55AzUKp Z3Ew== X-Gm-Message-State: AIkVDXK9/Jdp0g/Naqy5sv70N1PjAxCWIOvS0bGOhRWE8HZdlSV03XbrjJyxOqIL4oDOhw== X-Received: by 10.99.94.194 with SMTP id s185mr59096137pgb.35.1482854470730; Tue, 27 Dec 2016 08:01:10 -0800 (PST) Received: from localhost ([45.35.47.137]) by smtp.gmail.com with ESMTPSA id e6sm72120822pgf.4.2016.12.27.08.01.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Dec 2016 08:01:09 -0800 (PST) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Ming Lei , Jens Axboe Subject: [PATCH v1 24/54] blk-merge: compute bio->bi_seg_front_size efficiently Date: Tue, 27 Dec 2016 23:56:13 +0800 Message-Id: <1482854250-13481-25-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482854250-13481-1-git-send-email-tom.leiming@gmail.com> References: <1482854250-13481-1-git-send-email-tom.leiming@gmail.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.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 182398cb1524..e3abc835e4b7 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -153,22 +153,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; @@ -181,6 +180,8 @@ static struct bio *blk_bio_segment_split(struct request_queue *q, 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;