Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp872844imj; Fri, 15 Feb 2019 08:11:25 -0800 (PST) X-Google-Smtp-Source: AHgI3IYoRlFiuDQ03X+iEp20VwoALmkBQN3Tm97pwcH1cvEUs+GjE1XMYt0mqAu4aVSP8+Aib7i7 X-Received: by 2002:a17:902:bc81:: with SMTP id bb1mr10775466plb.223.1550247085898; Fri, 15 Feb 2019 08:11:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550247085; cv=none; d=google.com; s=arc-20160816; b=aDCGZYTHUbBPtoJ/wGE7ELUHmTp7GqWTe3MT1bl6/uaktOIi8BAguhGXpK+Fhs9L04 Zxl5nP7YWV16cas5LMip24EZE07jPdHfhCL41SyiSx0SfsnFjr44KSt8qU26OT+YDvs6 1nFN7Y62ovWfHWKXztJCO5vtPSWUNxIzs98bdhzqW435gHCyeqYA8HdiifIkTaPD8lAq DlF7t5zgwWezQUoKGx5zFh9HV7bJqttma8KV7nhbmbrB+qSLXPNbN54UbuI6tmiAc1dZ 91GSUb8p/GwQuMGUBdKzSxhWXobcRI4CMNuDGcZD3w7DrO3qs6lmegawc3uFF/xOD9WT fXRQ== 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=QDJuYdB/v5IBDbMNukxwyLgaj2zPEtaGeI+9DGb7M44=; b=G/tZYje5OxEOeCFyZ9r8Oq3u/Ojb8xUw9xx6Jxw92rsz0NbbGj4o06o+L5uB0PnPfh 0QIZxVwcyzC0Nr2SfY7awSKw3ct5kk6kAejq7QvOtVamF5rDWsPhYC/r33MYoAG/7v85 iHPbWBQvqpp7hC1aTE/wodCcSWXG+DOz/CtqolyvMZGnlRKLe/71S4QOhMBTF/RkDdzA qRPlAg69xjWqUwXouQ0STLN4CFRFfCJ7nJr1hOpT7j0ccQbfwpS0QT73w9U5H4O6Pn/D hglu2r7UXiKrNLielu7GOLsR6u0CyyaWi9cOJV9VP+NeNCe7ocHlmT7fqwfw8QHwKe9n LvqQ== 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 72si3120037plb.224.2019.02.15.08.11.10; Fri, 15 Feb 2019 08:11:25 -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 S2394378AbfBOLQY (ORCPT + 99 others); Fri, 15 Feb 2019 06:16:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51182 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394341AbfBOLQT (ORCPT ); Fri, 15 Feb 2019 06:16:19 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B6648C01DE19; Fri, 15 Feb 2019 11:16:18 +0000 (UTC) Received: from localhost (ovpn-8-22.pek2.redhat.com [10.72.8.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id B69A026E59; Fri, 15 Feb 2019 11:16:17 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V15 11/18] block: loop: pass multi-page bvec to iov_iter Date: Fri, 15 Feb 2019 19:13:17 +0800 Message-Id: <20190215111324.30129-12-ming.lei@redhat.com> In-Reply-To: <20190215111324.30129-1-ming.lei@redhat.com> References: <20190215111324.30129-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 15 Feb 2019 11:16:19 +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 on bvec itererator helpers, so it is safe to pass multi-page bvec to it, and this way is much more efficient than passing one page in each bvec. Reviewed-by: Christoph Hellwig Reviewed-by: Omar Sandoval Signed-off-by: Ming Lei --- drivers/block/loop.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index cf5538942834..8ef583197414 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -511,21 +511,22 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, loff_t pos, bool rw) { struct iov_iter iter; + struct req_iterator rq_iter; struct bio_vec *bvec; struct request *rq = blk_mq_rq_from_pdu(cmd); struct bio *bio = rq->bio; struct file *file = lo->lo_backing_file; + struct bio_vec tmp; unsigned int offset; - int segments = 0; + int nr_bvec = 0; int ret; + rq_for_each_bvec(tmp, rq, rq_iter) + nr_bvec++; + if (rq->bio != rq->biotail) { - struct req_iterator iter; - struct bio_vec tmp; - __rq_for_each_bio(bio, rq) - segments += bio_segments(bio); - bvec = kmalloc_array(segments, sizeof(struct bio_vec), + bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec), GFP_NOIO); if (!bvec) return -EIO; @@ -534,10 +535,10 @@ 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 rq_for_each_bvec * API will take care of all details for us. */ - rq_for_each_segment(tmp, rq, iter) { + rq_for_each_bvec(tmp, rq, rq_iter) { *bvec = tmp; bvec++; } @@ -551,11 +552,10 @@ 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); } 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