From patchwork Wed Jun 27 12:45:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10491407 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 31393602B3 for ; Wed, 27 Jun 2018 12:48:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F3D328D80 for ; Wed, 27 Jun 2018 12:48:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 131AA28D84; Wed, 27 Jun 2018 12:48:38 +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=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 936FE28D80 for ; Wed, 27 Jun 2018 12:48:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA8FB6B0281; Wed, 27 Jun 2018 08:48:36 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A5ABD6B0283; Wed, 27 Jun 2018 08:48:36 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9494A6B0284; Wed, 27 Jun 2018 08:48:36 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f200.google.com (mail-qt0-f200.google.com [209.85.216.200]) by kanga.kvack.org (Postfix) with ESMTP id 665AC6B0281 for ; Wed, 27 Jun 2018 08:48:36 -0400 (EDT) Received: by mail-qt0-f200.google.com with SMTP id j11-v6so1863208qtf.15 for ; Wed, 27 Jun 2018 05:48:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=fpMKvsAS6Q/rXfZA1526g7rOEkf3VVqlC3lS7ZuugNM=; b=ed4rCbbZtG9f8+5SviD4TKeYZVCj1bNsfZmRWPdVU0CgUkFnhF96bFI+OhDasweGHz GwiyV0bt3nM2tk4wbch2Aas+LJ92X0eId1vuoXh+i3BjLltS81PZx+MzUy1CokGCBS5C 59ejUuAsC4q/wgympfPma194rRF+IolFdbAIW/A0f8eUr9htJPWn3tG5WL88JyBnjV6i 5I8fEcQr09AlRa/QCQcR0oFdowRVuwRk5DMHPj3u80MKFBBFYnEGf+iM+MMMQ98vqDMo qLr5jR5WnmmqXTbBaHDRm4hKWeXg4JXkreVjecazcQ00gSE9uLkDq+oojYScOp8UrAkv sV8w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APt69E0PekzExMpP+k4gGXf/b+McMquqbbebdJ/bpjaTj2pSSYL2D5bq YaQZuw9IrabgPeZOT048ruoyzu4VHH+ifcvziHj7cihis4qfmxyWL+dpZVZDIRCg79Lc4cTdmCk fKZCPz7FEZ6GeU053KqaznwFsMJpy+4+XYm9zwaCvRITpPiG2sA3Ya1DCQhIw4rNlmA== X-Received: by 2002:a37:6fc5:: with SMTP id k188-v6mr4963627qkc.204.1530103716193; Wed, 27 Jun 2018 05:48:36 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdtB1rstzBEJbbR3QdKoYuN+6Ae+4+3GHk4lMNgrPeb0k6JqSOnpLt7/AK2xftdTQQZP7JV X-Received: by 2002:a37:6fc5:: with SMTP id k188-v6mr4963587qkc.204.1530103715427; Wed, 27 Jun 2018 05:48:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530103715; cv=none; d=google.com; s=arc-20160816; b=UhjNeISSyqxb1qJKRTzNmDixpINTVnmnFd8UwU+cKJE5/jE2jaowZoOhLzRoRq9knk 3/iW0Whpmimz05jdQoAFCKoHp5G8mTdjkjbQkg53LGHe6Yi2qpNwyD351T7l0wywNWqp SCYWeVNbzMUxAOCR0uhOH8KWNhkdsgck0ZHDe5viUoaDO5X2f9qoFcu4EiKSKeiHKNVx fudQDCBU4VDSOnoJcB6e3gNQ9kGVuwx8/LvAACtgh78nxse7bdyxAv7CndS08BZzWgsL nmOeB0GwcjxafFZi23r01Yq5CNgd6lORqDMxBBTkh47cbXWDdZKNRRqv87G74nkhVAvS WGag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=fpMKvsAS6Q/rXfZA1526g7rOEkf3VVqlC3lS7ZuugNM=; b=zNRpNKLSYEVwppoQ/0NBmz+br3/OuuYVjMpk/UB4OB9mcAUhdgKpGiJn843Gb5xI7I +SLhh5CD1IDlPJsrNUCYCFLiBNAPB6jcB/hdD77W5YqdFVtJbPKC6eNuOGcDEPwdmv3s hJOFCgJQ5/eO39wQy4CIUWFb09T2Ta7pvr0X+vTbJ4AXj0yKapWScMPSfrjrIJh+baNx w2J8gJAGl509OM5VhimRXyLoi+dg3Dk1d4hBnoLbPeVy2nKd05iKcNbNrgkvINVPw2Yr F3algLDKQpLfUGyNaPkXJUfQIinEz4WbNdtC3wXJamxflANcrr9aNe2F6Y7bZqjfieuW Ot3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx3-rdu2.redhat.com. [66.187.233.73]) by mx.google.com with ESMTPS id 13-v6si1787222qts.384.2018.06.27.05.48.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jun 2018 05:48:35 -0700 (PDT) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) client-ip=66.187.233.73; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03A92401EF04; Wed, 27 Jun 2018 12:48:35 +0000 (UTC) Received: from localhost (ovpn-12-44.pek2.redhat.com [10.72.12.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE9EB1C674; Wed, 27 Jun 2018 12:48:22 +0000 (UTC) From: Ming Lei To: Jens Axboe , Christoph Hellwig , Kent Overstreet Cc: David Sterba , Huang Ying , Mike Snitzer , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , "Darrick J . Wong" , Coly Li , Filipe Manana , Randy Dunlap , Ming Lei Subject: [PATCH V7 13/24] block: use bio_for_each_bvec() to map sg Date: Wed, 27 Jun 2018 20:45:37 +0800 Message-Id: <20180627124548.3456-14-ming.lei@redhat.com> In-Reply-To: <20180627124548.3456-1-ming.lei@redhat.com> References: <20180627124548.3456-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 27 Jun 2018 12:48:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 27 Jun 2018 12:48:35 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'ming.lei@redhat.com' RCPT:'' X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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(). 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 bf1dceb9656a..0f7769c5feb5 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -424,6 +424,56 @@ static int blk_phys_contig_segment(struct request_queue *q, struct bio *bio, return 0; } +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, @@ -444,25 +494,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; } @@ -484,7 +516,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);