From patchwork Fri May 25 03:45:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10426035 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 AEA58602D6 for ; Fri, 25 May 2018 03:48:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D15E28D8F for ; Fri, 25 May 2018 03:48:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F03E28DB7; Fri, 25 May 2018 03:48:16 +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 0244028D8F for ; Fri, 25 May 2018 03:48:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 067076B0298; Thu, 24 May 2018 23:48:15 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0169E6B029A; Thu, 24 May 2018 23:48:14 -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 E490C6B029B; Thu, 24 May 2018 23:48:14 -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 BA4676B0298 for ; Thu, 24 May 2018 23:48:14 -0400 (EDT) Received: by mail-qt0-f200.google.com with SMTP id g12-v6so2786324qtj.22 for ; Thu, 24 May 2018 20:48:14 -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=6js4vyP6PDRQrmgMKN7eDjkqCBRPbcxRpB41F+KEUJI=; b=s9rVnEFYBB67Fclchqo6ErJhfKnbUDNgSlZemIzTwLXjcpqY9UWtbX7WCgQJw5BZK4 +u1bs7k6ULHTvRdR1W8k0lWZ4gXaV09Do1bXZ6QvDiJykrdOzJdZbnGshv147Pb24lTT XKvi5udn8HHQmDWYjgPm3g+x5Xi494N4ZHqq36qH0oJ+/SP6IAMDWVdhdZbnXiE72Biv ocuwjEY6yWeJKYlQnap98abfqjSOqcMuofG+3R9s8JvYIhx4zSntOCGmuOSUf8pSuhHI 5vCtJ0pD44AwiYH079HK30AhTpoSFzmZ6JKKoTM613mXrX/UJS4mP8ByZWJiemXjO2DQ we7A== 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: ALKqPwdWwkVEnsv55be/QkaOBQmofA3SYW7B4lpkQNC7uHELICF8dsZW ZFOurt5ZKzcXTHQurb1Vcm6aM9PXeWfVmMJB7c0odN9IpGZuoQyoRUm387Cdz1Lsntl+mMK69Dh 0Rbkmx0m0sQl9CpR6PIWogRVZCgpVYSbsmbmSgmO9F2ANPdR8cLgmDxuyZZQxWQZVVw== X-Received: by 2002:ac8:24d4:: with SMTP id t20-v6mr603444qtt.30.1527220094560; Thu, 24 May 2018 20:48:14 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKl5ad/5R2XE6Dt3si5Hu8nkcxltV0tbPd3IVh5omvNPgSYtxcJWCwrSw/4Z1S9RybTmnQ/ X-Received: by 2002:ac8:24d4:: with SMTP id t20-v6mr603421qtt.30.1527220093974; Thu, 24 May 2018 20:48:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527220093; cv=none; d=google.com; s=arc-20160816; b=iVWcoh0rzqP/VD/iXbkCA6fEtC443dH/H/142WGRiAduG6ceMc080q1yGlU54eVDxU Oe6YYwuVbX+Mn+kZSRwxgdzPN2UWAYiXqTEr6CjRLoiJq+1R63bo24DDquzL9WOl0OkR biYZFMFL81+JOhO2uGiqPIM02x9b+DTFLZZZqLx+ARHtmvLhjU9o1hb6VZliA8UMrZVB sq+a2C7GlTSxLvF5uDNmhYhs6bGZvUA/mUjlLAtTK3B0k9FXPA/zyVpYUTOcGiwOOeY2 Qvu+ppshvtGDuZu36tbK1l4+OBswYaEUGDYs6vTTJtd1sj1XRQd03Xqgv0SqBJ2z52pI LPBQ== 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=6js4vyP6PDRQrmgMKN7eDjkqCBRPbcxRpB41F+KEUJI=; b=Pca9gaO6bPLe1S5PE9yIpYfvrWffRlEIriI9X0TAzjJ3L5LECyNddlKrjhRT6gQwlV Q46c6UR8c0jbEgFuJewv+p/K1R+RhaczykZp9BcAJdrcGcSdRGGXZm8NE4WRf5vOun6d fsrt52xBtpmafbBMqiX95ajKMByqzdjGqdiNBx6Xq6StmVAMkO1wzUzJt6OZY0v3ajdy vPaGeA5CTCphLsnbL8eFcZmxkTwvdyUnsfQzVPJUZm8MuPvBdG8nnU58KDe8t4RLIdaw IVl9ySncB6aVuzDDCFDxtXrhPLpJJ4uPibseyfz7nEKbKGoTcN/G7Wpb3eMbGOlqwaBA Xa5g== 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 o22-v6si7781407qka.165.2018.05.24.20.48.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 May 2018 20:48:13 -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 7BE8A401EF03; Fri, 25 May 2018 03:48:13 +0000 (UTC) Received: from localhost (ovpn-12-30.pek2.redhat.com [10.72.12.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 372BF83B80; Fri, 25 May 2018 03:48:02 +0000 (UTC) From: Ming Lei To: Jens Axboe , Christoph Hellwig , Alexander Viro , Kent Overstreet Cc: David Sterba , Huang Ying , 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 , Ming Lei Subject: [RESEND PATCH V5 07/33] block: use bio_for_each_segment() to map sg Date: Fri, 25 May 2018 11:45:55 +0800 Message-Id: <20180525034621.31147-8-ming.lei@redhat.com> In-Reply-To: <20180525034621.31147-1-ming.lei@redhat.com> References: <20180525034621.31147-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]); Fri, 25 May 2018 03:48:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 25 May 2018 03:48:13 +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_segment() 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 d157b752d965..9fc96c9f6061 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -414,6 +414,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, @@ -434,25 +484,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; } @@ -474,7 +506,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_page(bvec, bio, iter) + bio_for_each_segment(bvec, bio, iter) __blk_segment_map_sg(q, &bvec, sglist, &bvprv, sg, &nsegs, &cluster);