Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp943924imu; Fri, 9 Nov 2018 08:28:42 -0800 (PST) X-Google-Smtp-Source: AJdET5e9uTuW4nZNJgnmNF0PoicOfWoVTj2b+7w/Mtcm3Re5TPzhMrbUt70zKfEQ2kkV31aYL4cu X-Received: by 2002:a62:4896:: with SMTP id q22-v6mr9747153pfi.248.1541780922680; Fri, 09 Nov 2018 08:28:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541780922; cv=none; d=google.com; s=arc-20160816; b=vnhCDfN/XCLx9RPuxgNtr1shu0Lni+WHtjrQUzIaKEFdte7y8xQaIlz1EsyOZLC/2D ah4D6mcbLtwYoal5enhHskD6Krj/yUSufphiZVlyzmDSE1pPqHC1KBmqoAfpBybysPAM BCtdCSI1MgIdWhlPMNFvQRRSuyHlLkzufVUOp7m65g3TVI+H+W6Frh9Gx/7L/lqzf5ql 3RXClDZGxs0F9ccgf36VdmIP9KJG28ic8wfb87k95Vd6GchOvqZGw6MYcshLzQMSJco3 DbWw8596yN/DAIT+/sJrOB1JFm5kctOTmuhX+mP5aMmG7A38w8JSqa+o3hwdXguN4pff +wug== 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=fBQ6zKe3K4kLKIHDmvC9FUZcL8PvbUcd6zU2gtWOHck=; b=BnNZEqwGyzYEB2VLz6y2K0TM7oExJ7a6SztoZvQXHeGMxjEpoWz/gwPBKikdMK8x3u gqeqvWZmBGz1NSANYWcapKS8GQNtst4M3+4ASpb/9yb7PiNC7uCaZSoNz5/wso8lGLKK Kv57ecWFy0HYGfkyLsgbzSgPW9t1g48DdqQ1EQhsOMJmb/Fyn7ynRbVUVIEHwxYBQJMK fe+pT/ZeAllnQQ9KS1lGnBC1iemAtyMCGQMz+r9QzxfHCh+4qxGhXLE8EkYpx2Qynl4r diQIgWIaRuLF+avIcQVqRVQkY/vCE6oRHU3RA1lYZy8JqEgSAL/TF18L34xQnt3GDJF6 6Xaw== 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 l137-v6si9468219pfd.260.2018.11.09.08.28.22; Fri, 09 Nov 2018 08:28:42 -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 S1728733AbeKJCIh (ORCPT + 99 others); Fri, 9 Nov 2018 21:08:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49688 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728311AbeKJCIh (ORCPT ); Fri, 9 Nov 2018 21:08:37 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E8AA81F11; Fri, 9 Nov 2018 16:27:20 +0000 (UTC) Received: from localhost (ovpn-8-16.pek2.redhat.com [10.72.8.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F3306B8C0; Fri, 9 Nov 2018 16:27:19 +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 V8 10/18] block: loop: pass multi-page bvec to iov_iter Date: Sat, 10 Nov 2018 00:26:02 +0800 Message-Id: <20181109162610.18981-11-ming.lei@redhat.com> In-Reply-To: <20181109162610.18981-1-ming.lei@redhat.com> References: <20181109162610.18981-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 09 Nov 2018 16:27:20 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org iov_iter is implemented with bvec itererator, so it is safe to pass multipage bvec to it, and this way is much more efficient than passing one page in each bvec. Cc: Christoph Hellwig Signed-off-by: Ming Lei --- drivers/block/loop.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index bf6bc35aaf88..a3fd418ec637 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -515,16 +515,16 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, struct bio *bio = rq->bio; struct file *file = lo->lo_backing_file; unsigned int offset; - int segments = 0; + int nr_bvec = 0; int ret; if (rq->bio != rq->biotail) { - struct req_iterator iter; + struct bvec_iter iter; struct bio_vec tmp; __rq_for_each_bio(bio, rq) - segments += bio_segments(bio); - bvec = kmalloc_array(segments, sizeof(struct bio_vec), + nr_bvec += bio_bvecs(bio); + bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec), GFP_NOIO); if (!bvec) return -EIO; @@ -533,13 +533,14 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, /* * The bios of the request may be started from the middle of * the 'bvec' because of bio splitting, so we can't directly - * copy bio->bi_iov_vec to new bvec. The rq_for_each_segment + * copy bio->bi_iov_vec to new bvec. The bio_for_each_bvec * API will take care of all details for us. */ - rq_for_each_segment(tmp, rq, iter) { - *bvec = tmp; - bvec++; - } + __rq_for_each_bio(bio, rq) + bio_for_each_bvec(tmp, bio, iter) { + *bvec = tmp; + bvec++; + } bvec = cmd->bvec; offset = 0; } else { @@ -550,11 +551,11 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, */ offset = bio->bi_iter.bi_bvec_done; bvec = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter); - segments = bio_segments(bio); + nr_bvec = bio_bvecs(bio); } atomic_set(&cmd->ref, 2); - iov_iter_bvec(&iter, rw, bvec, segments, blk_rq_bytes(rq)); + iov_iter_bvec(&iter, rw, bvec, nr_bvec, blk_rq_bytes(rq)); iter.iov_offset = offset; cmd->iocb.ki_pos = pos; -- 2.9.5