Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5484442imu; Tue, 13 Nov 2018 07:17:14 -0800 (PST) X-Google-Smtp-Source: AJdET5fESgpWLIvEaGAaM8pL8lx3QtIpbfhRpgqrUOzevF7yZoNuWxgEYUYDORjuvZ6pu3q7rVKP X-Received: by 2002:a62:6bc8:: with SMTP id g191-v6mr5811794pfc.134.1542122233914; Tue, 13 Nov 2018 07:17:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542122233; cv=none; d=google.com; s=arc-20160816; b=npVhzA394gUTS4mezIbJJm5WNLqw+UcACD4Ix983KlRcH1QSSED4zk7OFOBfSiB/E+ DuxxXyURfc1R9gVauOThrXUTBdniYgQzf0OOO5UrLL1fgm+xcAd2XLgxbRdrrsSeK/5N CrBBCKNF0VVB+IWtDbybu6T7AcptKlfdokgZdaAsAwHmLQ/TC22Y+uIQ7HYnQANW5mLz JAJjzUws4NGFXMfFcSFMTzRDmQ6YIjcIdNaGHLeSW9TSPNNfUEBMd/WNfZjYnnxgXJg8 auhgotjduxmEbPiGTaB3+6jrbR05hrRAnvd6/mbKcUi29CBW5GQZ8tMW74t2Q9JdVyK7 RlrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=JnooYSOi+petECpZEkaXYdo2t9s7xFSbcP7nWWOwWaI=; b=d2i7jXy/5eJQdb/4otOBsl02LSjDiTQbOPpPzRNdxvIKgnugBGL7MlGbfwGMtbTLxG cA64EsQFw4d5eBnMWQNulXi91i1TRB6s16dYo2kHkRTKygS8VSwkxQRnt3YAOPhjx55H Pwin3R7X7hs6gD4hXAm5Zw93jNeUM2h4TFRzoDx7cbu1NlQrx6O/tObWzETiP+qQPII/ yCttk1SOCY6PK+rL5vtZNplKwkM/Hhd1/htCmZ6LqrRfb7GikMdmRGFqUZ6cG4cn2QZW 2yRBJ1uHQw/1eIHvwO22Fm3+gr1UbLmcULw2dqYvTPnv1HitoHTr5kspGI0EpL0GlUTv lziQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v6si5356556pfj.167.2018.11.13.07.16.37; Tue, 13 Nov 2018 07:17:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387908AbeKNBO1 (ORCPT + 99 others); Tue, 13 Nov 2018 20:14:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43114 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387822AbeKNBO1 (ORCPT ); Tue, 13 Nov 2018 20:14:27 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EDAF763144; Tue, 13 Nov 2018 15:15:52 +0000 (UTC) Received: from localhost (ovpn-8-23.pek2.redhat.com [10.72.8.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id C42145D961; Tue, 13 Nov 2018 15:15:48 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Ming Lei , Christoph Hellwig Subject: [PATCH V9 04/19] block: use bio_for_each_bvec() to map sg Date: Tue, 13 Nov 2018 23:14:50 +0800 Message-Id: <20181113151505.15498-5-ming.lei@redhat.com> In-Reply-To: <20181113151505.15498-1-ming.lei@redhat.com> References: <20181113151505.15498-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 13 Nov 2018 15:15:53 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is more efficient to use bio_for_each_bvec() to map sg, meantime we have to consider splitting multipage bvec as done in blk_bio_segment_split(). Cc: Christoph Hellwig Signed-off-by: Ming Lei --- block/blk-merge.c | 72 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 20 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 6f7deb94a23f..cb9f49bcfd36 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -473,6 +473,56 @@ static int blk_phys_contig_segment(struct request_queue *q, struct bio *bio, return biovec_phys_mergeable(q, &end_bv, &nxt_bv); } +static struct scatterlist *blk_next_sg(struct scatterlist **sg, + struct scatterlist *sglist) +{ + if (!*sg) + return sglist; + else { + /* + * If the driver previously mapped a shorter + * list, we could see a termination bit + * prematurely unless it fully inits the sg + * table on each mapping. We KNOW that there + * must be more entries here or the driver + * would be buggy, so force clear the + * termination bit to avoid doing a full + * sg_init_table() in drivers for each command. + */ + sg_unmark_end(*sg); + return sg_next(*sg); + } +} + +static unsigned blk_bvec_map_sg(struct request_queue *q, + struct bio_vec *bvec, struct scatterlist *sglist, + struct scatterlist **sg) +{ + unsigned nbytes = bvec->bv_len; + unsigned nsegs = 0, total = 0; + + while (nbytes > 0) { + unsigned seg_size; + struct page *pg; + unsigned offset, idx; + + *sg = blk_next_sg(sg, sglist); + + seg_size = min(nbytes, queue_max_segment_size(q)); + offset = (total + bvec->bv_offset) % PAGE_SIZE; + idx = (total + bvec->bv_offset) / PAGE_SIZE; + pg = nth_page(bvec->bv_page, idx); + + sg_set_page(*sg, pg, seg_size, offset); + + total += seg_size; + nbytes -= seg_size; + nsegs++; + } + + return nsegs; +} + static inline void __blk_segment_map_sg(struct request_queue *q, struct bio_vec *bvec, struct scatterlist *sglist, struct bio_vec *bvprv, @@ -490,25 +540,7 @@ __blk_segment_map_sg(struct request_queue *q, struct bio_vec *bvec, (*sg)->length += nbytes; } else { new_segment: - if (!*sg) - *sg = sglist; - else { - /* - * If the driver previously mapped a shorter - * list, we could see a termination bit - * prematurely unless it fully inits the sg - * table on each mapping. We KNOW that there - * must be more entries here or the driver - * would be buggy, so force clear the - * termination bit to avoid doing a full - * sg_init_table() in drivers for each command. - */ - sg_unmark_end(*sg); - *sg = sg_next(*sg); - } - - sg_set_page(*sg, bvec->bv_page, nbytes, bvec->bv_offset); - (*nsegs)++; + (*nsegs) += blk_bvec_map_sg(q, bvec, sglist, sg); } *bvprv = *bvec; } @@ -530,7 +562,7 @@ static int __blk_bios_map_sg(struct request_queue *q, struct bio *bio, int cluster = blk_queue_cluster(q), nsegs = 0; for_each_bio(bio) - bio_for_each_segment(bvec, bio, iter) + bio_for_each_bvec(bvec, bio, iter) __blk_segment_map_sg(q, &bvec, sglist, &bvprv, sg, &nsegs, &cluster); -- 2.9.5