From patchwork Sat Jun 9 12:29:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10455543 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 F2599601F7 for ; Sat, 9 Jun 2018 12:32:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4D50223A4 for ; Sat, 9 Jun 2018 12:32:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D94AD223A6; Sat, 9 Jun 2018 12:32:04 +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 548DF223A4 for ; Sat, 9 Jun 2018 12:32:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63DFF6B026E; Sat, 9 Jun 2018 08:32:03 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5C44B6B026F; Sat, 9 Jun 2018 08:32:03 -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 48F0C6B0270; Sat, 9 Jun 2018 08:32:03 -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 1B9D36B026E for ; Sat, 9 Jun 2018 08:32:03 -0400 (EDT) Received: by mail-qt0-f200.google.com with SMTP id c1-v6so375529qtj.6 for ; Sat, 09 Jun 2018 05:32:03 -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=hqyHF8YWYn9EL8eWgmQyDZYkOkVAVCxCrsvIKnf1IzY=; b=KcSywwmCiTTphEo8W5BDzWUb73Hsl7ZBFRNDieeGCcEM3gM4DRZUhvYWhyDfWTvbT5 G+KvmH0FlF2UO0XWTorY57B7MoNc9q5ChPqnfU9gnJ1ze68LcxPTPAd3tFDTIomWagyw joXcyPB0/68+s2DG8syd2loN/FW7E7qefdhk0ODBATiCUhQa1WG5GqRZjL/0OfLJSoJU cR5IlGCH6YKZbtBq5DBOorrzvVbJ9DTNMB5GC1w1WPZSTXEWGZpHNx/D1fWFr4XWm6nJ FkG5M6Sq7hvexJBg1TboeRZNRLLnFBAZHk7NPxHDwpdFPRSjaojnr1+i74y/LGKIrkNX DLXA== 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: APt69E3ktIJ+utbIL2E1me2zycZylKrvHZoTkPgrOs7xq7dFdTGAzmAR UN8gqS2RL2bj5ZubNRofIY7wwFcmIlGUpDjHuB9vXrdkXGWpRPTmKfTOZAPrzXJ5bAXLMxzKMSC p62qZpScqWr922r/ARXOku0NJQgm6jab0GMJ2mmrI0XPpNAY9At2HBdR2c6VUquwm8w== X-Received: by 2002:ac8:f2a:: with SMTP id e39-v6mr9501635qtk.88.1528547522923; Sat, 09 Jun 2018 05:32:02 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJEAUiPbcGK870pcLoZxQJo6s+P3FaUR6vcFzjbCFqd+7qz2/VUq6+99CbjImKqN3Qw8QZr X-Received: by 2002:ac8:f2a:: with SMTP id e39-v6mr9501601qtk.88.1528547522318; Sat, 09 Jun 2018 05:32:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528547522; cv=none; d=google.com; s=arc-20160816; b=ls3/zshHkOD50TPvmf9j1BxtEczKU1XcJ4VB6g8/cxS3RliEmoFwGjZzaO1EiH1dsT aXae1q2Pr/bnLojiKM6MsvssOZQrenGNN+wr+hxiYwSaRaUMaOSUwdA9uXZxgYR1oM3c bg/ydTuDWN9hNhQCFRZEIErtaIFFgbxab/JVxWOu1pgW3GA2KXwcM+FujiCInviTSCyp aab3iDoBe8vysKFcLZl0xwjcTUcUlvHzdiQe6YMPrSsffT9uuFYJirYMe7khI8/EwcBi YkAPE70TyojuxRJmYkthsv5CgPdfuw4Y+5nm3wIqwgxsJe6PKNcA5ri3hOx81QM6UGr4 Nt+A== 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=hqyHF8YWYn9EL8eWgmQyDZYkOkVAVCxCrsvIKnf1IzY=; b=v2U6lW6kz5AJUq4Tpx3Vpa1Myc/ycKhKpV2MLHDOZKREwhsEYXu2Dlc2TBVeG0ye0l ENi3KrjffstUZf2JNlFQnFJo/n3JzimTFhVwm51gzAVmAouUX8h+0nQRmxlJ2PeMrLGT JcGuBjHZwjCTEHIqPwDZ6+e6NAEgPBOTKbwYXlEdiiRtDsoYjRWzPuq/rmslXZ7JQho2 U2m6+tPAszB7+ICbZ3XC8E3JMgyYKXBtM0ht8BgIi38A/0yWL0qBH0gR+43InoMy8blf crYzVtlP6DF9R3tzN26x/BWTtFbwlO+4O6nEULUCIfLkOPLV3OFwQyXLyg6MuFc9EOqU Io6A== 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 f190-v6si4168112qka.21.2018.06.09.05.32.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 Jun 2018 05:32:02 -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-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DBBCBBB42D; Sat, 9 Jun 2018 12:32:01 +0000 (UTC) Received: from localhost (ovpn-12-40.pek2.redhat.com [10.72.12.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 338E72166BB2; Sat, 9 Jun 2018 12:31:52 +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 , Randy Dunlap , Ming Lei Subject: [PATCH V6 07/30] block: use bio_for_each_chunk() to map sg Date: Sat, 9 Jun 2018 20:29:51 +0800 Message-Id: <20180609123014.8861-8-ming.lei@redhat.com> In-Reply-To: <20180609123014.8861-1-ming.lei@redhat.com> References: <20180609123014.8861-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sat, 09 Jun 2018 12:32:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sat, 09 Jun 2018 12:32:01 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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_chunk() 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 2493fe027953..044db0fa2f89 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_chunk(bvec, bio, iter) __blk_segment_map_sg(q, &bvec, sglist, &bvprv, sg, &nsegs, &cluster);